2023-01-19 18:07:27 +00:00
package main
2023-03-10 03:23:09 +00:00
import "image"
2023-01-19 18:07:27 +00:00
import "git.tebibyte.media/sashakoshka/tomo"
2023-03-31 03:19:04 +00:00
import "git.tebibyte.media/sashakoshka/tomo/layouts"
import "git.tebibyte.media/sashakoshka/tomo/elements"
2023-03-16 05:14:39 +00:00
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
2023-03-16 18:22:56 +00:00
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
2023-01-19 18:07:27 +00:00
func main ( ) {
tomo . Run ( run )
}
func run ( ) {
2023-03-17 05:58:42 +00:00
window , _ := tomo . NewWindow ( 360 , 240 )
2023-01-19 18:07:27 +00:00
window . SetTitle ( "Scroll" )
2023-03-31 03:19:04 +00:00
container := containers . NewContainer ( layouts . Vertical { true , true } )
2023-01-19 18:07:27 +00:00
window . Adopt ( container )
2023-03-31 03:19:04 +00:00
textBox := elements . NewTextBox ( "" , copypasta )
2023-03-16 18:22:56 +00:00
scrollContainer := containers . NewScrollContainer ( true , false )
2023-03-10 03:23:09 +00:00
2023-03-31 03:19:04 +00:00
disconnectedContainer := containers . NewContainer ( layouts . Horizontal {
2023-03-10 03:23:09 +00:00
Gap : true ,
} )
2023-03-31 03:19:04 +00:00
list := elements . NewList (
elements . NewListEntry ( "This is list item 0" , nil ) ,
elements . NewListEntry ( "This is list item 1" , nil ) ,
elements . NewListEntry ( "This is list item 2" , nil ) ,
elements . NewListEntry ( "This is list item 3" , nil ) ,
elements . NewListEntry ( "This is list item 4" , nil ) ,
elements . NewListEntry ( "This is list item 5" , nil ) ,
elements . NewListEntry ( "This is list item 6" , nil ) ,
elements . NewListEntry ( "This is list item 7" , nil ) ,
elements . NewListEntry ( "This is list item 8" , nil ) ,
elements . NewListEntry ( "This is list item 9" , nil ) ,
elements . NewListEntry ( "This is list item 10" , nil ) ,
elements . NewListEntry ( "This is list item 11" , nil ) ,
elements . NewListEntry ( "This is list item 12" , nil ) ,
elements . NewListEntry ( "This is list item 13" , nil ) ,
elements . NewListEntry ( "This is list item 14" , nil ) ,
elements . NewListEntry ( "This is list item 15" , nil ) ,
elements . NewListEntry ( "This is list item 16" , nil ) ,
elements . NewListEntry ( "This is list item 17" , nil ) ,
elements . NewListEntry ( "This is list item 18" , nil ) ,
elements . NewListEntry ( "This is list item 19" , nil ) ,
elements . NewListEntry ( "This is list item 20" , nil ) )
2023-03-10 03:23:09 +00:00
list . Collapse ( 0 , 32 )
2023-03-31 03:19:04 +00:00
scrollBar := elements . NewScrollBar ( true )
2023-03-10 03:23:09 +00:00
list . OnScrollBoundsChange ( func ( ) {
scrollBar . SetBounds (
list . ScrollContentBounds ( ) ,
list . ScrollViewportBounds ( ) )
} )
scrollBar . OnScroll ( func ( viewport image . Point ) {
list . ScrollTo ( viewport )
} )
2023-01-19 18:07:27 +00:00
scrollContainer . Adopt ( textBox )
2023-03-31 03:19:04 +00:00
container . Adopt ( elements . NewLabel ( "A ScrollContainer:" , false ) , false )
2023-03-10 03:23:09 +00:00
container . Adopt ( scrollContainer , false )
disconnectedContainer . Adopt ( list , false )
2023-03-31 03:19:04 +00:00
disconnectedContainer . Adopt ( elements . NewLabel (
2023-03-10 04:27:08 +00:00
"Notice how the scroll bar to the right can be used to " +
"control the list, despite not even touching it. It is " +
"indeed a thing you can do. It is also terrible UI design so " +
"don't do it." , true ) , true )
2023-03-10 03:23:09 +00:00
disconnectedContainer . Adopt ( scrollBar , false )
container . Adopt ( disconnectedContainer , true )
2023-01-19 18:07:27 +00:00
window . OnClose ( tomo . Stop )
window . Show ( )
}
2023-03-10 03:23:09 +00:00
const copypasta = ` "I use Linux as my operating system," I state proudly to the unkempt, bearded man. He swivels around in his desk chair with a devilish gleam in his eyes, ready to mansplain with extreme precision. "Actually", he says with a grin, "Linux is just the kernel. You use GNU+Linux!' I don't miss a beat and reply with a smirk, "I use Alpine, a distro that doesn't include the GNU Coreutils, or any other GNU code. It's Linux, but it's not GNU+Linux." The smile quickly drops from the man's face. His body begins convulsing and he foams at the mouth and drops to the floor with a sickly thud. As he writhes around he screams "I-IT WAS COMPILED WITH GCC! THAT MEANS IT'S STILL GNU!" Coolly, I reply "If windows were compiled with GCC, would that make it GNU?" I interrupt his response with "-and work is being made on the kernel to make it more compiler-agnostic. Even if you were correct, you won't be for long." With a sickly wheeze, the last of the man's life is ejected from his body. He lies on the floor, cold and limp. I've womansplained him to death. `