Updated the examples

This commit is contained in:
Sasha Koshka 2023-04-18 16:18:30 -04:00
parent 14080b1f88
commit 7cdc5868e5
20 changed files with 271 additions and 169 deletions

View File

@ -54,9 +54,16 @@ func NewHBox (space Space, children ...tomo.Element) (element *Box) {
}
// NewHBox creates a new vertical box.
func NewVBox (space Space) (element *Box) {
element = NewHBox(space)
element.vertical = true
func NewVBox (space Space, children ...tomo.Element) (element *Box) {
element = &Box {
padding: space.Includes(SpacePadding),
margin: space.Includes(SpaceMargin),
vertical: true,
}
element.scratch = make(map[tomo.Element] scratchEntry)
element.theme.Case = tomo.C("tomo", "box")
element.entity = tomo.NewEntity(element).(tomo.ContainerEntity)
element.Adopt(children...)
return
}

View File

@ -0,0 +1,104 @@
package containers
import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
type childManager struct {
onChange func ()
children []tomo.LayoutEntry
parent tomo.Parent
theme theme.Wrapped
config config.Wrapped
}
// Adopt adds a new child element to the container. If expand is set to true,
// the element will expand (instead of contract to its minimum size), in
// whatever way is defined by the container's layout.
func (manager *childManager) Adopt (child tomo.Element, expand bool) {
if child0, ok := child.(tomo.Themeable); ok {
child0.SetTheme(manager.theme.Theme)
}
if child0, ok := child.(tomo.Configurable); ok {
child0.SetConfig(manager.config.Config)
}
child.SetParent(manager.parent)
manager.children = append (manager.children, tomo.LayoutEntry {
Element: child,
Expand: expand,
})
manager.onChange()
}
// Disown removes the given child from the container if it is contained within
// it.
func (manager *childManager) Disown (child tomo.Element) {
for index, entry := range manager.children {
if entry.Element == child {
manager.clearChildEventHandlers(entry.Element)
manager.children = append (
manager.children[:index],
manager.children[index + 1:]...)
break
}
}
manager.onChange()
}
// DisownAll removes all child elements from the container at once.
func (manager *childManager) DisownAll () {
for _, entry := range manager.children {
manager.clearChildEventHandlers(entry.Element)
}
manager.children = nil
manager.onChange()
}
// Children returns a slice containing this element's children.
func (manager *childManager) Children () (children []tomo.Element) {
children = make([]tomo.Element, len(manager.children))
for index, entry := range manager.children {
children[index] = entry.Element
}
return
}
// CountChildren returns the amount of children contained within this element.
func (manager *childManager) CountChildren () (count int) {
return len(manager.children)
}
// Child returns the child at the specified index. If the index is out of
// bounds, this method will return nil.
func (manager *childManager) Child (index int) (child tomo.Element) {
if index < 0 || index > len(manager.children) { return }
return manager.children[index].Element
}
// ChildAt returns the child that contains the specified x and y coordinates. If
// there are no children at the coordinates, this method will return nil.
func (manager *childManager) ChildAt (point image.Point) (child tomo.Element) {
for _, entry := range manager.children {
if point.In(entry.Bounds) {
child = entry.Element
}
}
return
}
func (manager *childManager) clearChildEventHandlers (child tomo.Element) {
child.DrawTo(nil, image.Rectangle { }, nil)
child.SetParent(nil)
if child, ok := child.(tomo.Focusable); ok {
if child.Focused() {
child.HandleUnfocus()
}
}
}

View File

@ -129,5 +129,7 @@ func imageWindow (parent tomo.Window, image image.Image) {
container.AdoptExpand(elements.NewImage(image))
container.Adopt(closeButton)
window.Adopt(container)
closeButton.Focus()
window.Show()
}

View File

@ -22,44 +22,40 @@ func run () {
if err != nil { panic(err.Error()); return }
document := elements.NewDocument()
document.Adopt (elements.NewLabel (
"A document container is a vertically stacked container " +
"capable of properly laying out flexible elements such as " +
"text-wrapped labels. You can also include normal elements " +
"like:", true), true)
document.Adopt (elements.NewButton (
"Buttons,"), true)
document.Adopt (elements.NewCheckbox (
"Checkboxes,", true), true)
document.Adopt(elements.NewTextBox("", "And text boxes."), true)
document.Adopt (elements.NewSpacer(true), true)
document.Adopt (elements.NewLabel (
"Document containers are meant to be placed inside of a " +
"ScrollContainer, like this one.", true), true)
document.Adopt (elements.NewLabel (
"You could use document containers to do things like display various " +
"forms of hypertext (like HTML, gemtext, markdown, etc.), " +
"lay out a settings menu with descriptive label text between " +
"control groups like in iOS, or list comment or chat histories.",
true), true)
document.Adopt(elements.NewImage(logo), true)
document.Adopt (elements.NewLabel (
"You can also choose whether each element is on its own line " +
"(sort of like an HTML/CSS block element) or on a line with " +
"other adjacent elements (like an HTML/CSS inline element).",
true), true)
document.Adopt(elements.NewButton("Just"), false)
document.Adopt(elements.NewButton("like"), false)
document.Adopt(elements.NewButton("this."), false)
document.Adopt (elements.NewLabel (
"Oh, you're a switch? Then name all of these switches:",
true), true)
document.Adopt (
elements.NewLabelWrapped (
"A document container is a vertically stacked container " +
"capable of properly laying out flexible elements such as " +
"text-wrapped labels. You can also include normal elements " +
"like:"),
elements.NewButton("Buttons,"),
elements.NewCheckbox("Checkboxes,", true),
elements.NewTextBox("", "And text boxes."),
elements.NewLine(),
elements.NewLabelWrapped (
"Document containers are meant to be placed inside of a " +
"ScrollContainer, like this one."),
elements.NewLabelWrapped (
"You could use document containers to do things like display various " +
"forms of hypertext (like HTML, gemtext, markdown, etc.), " +
"lay out a settings menu with descriptive label text between " +
"control groups like in iOS, or list comment or chat histories."),
elements.NewImage(logo),
elements.NewLabelWrapped (
"You can also choose whether each element is on its own line " +
"(sort of like an HTML/CSS block element) or on a line with " +
"other adjacent elements (like an HTML/CSS inline element)."))
document.AdoptInline (
elements.NewButton("Just"),
elements.NewButton("like"),
elements.NewButton("this."))
document.Adopt (elements.NewLabelWrapped (
"Oh, you're a switch? Then name all of these switches:"))
for i := 0; i < 30; i ++ {
document.Adopt(elements.NewSwitch("", false), false)
document.AdoptInline(elements.NewSwitch("", false))
}
window.Adopt(elements.NewScroll(document, false, true))
window.Adopt(elements.NewScroll(elements.ScrollVertical, document))
window.OnClose(tomo.Stop)
window.Show()
}

View File

@ -12,15 +12,15 @@ func main () {
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 192, 192))
window.SetTitle("adventure")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
var world flow.Flow
world.Transition = container.DisownAll
world.Stages = map [string] func () {
"start": func () {
label := elements.NewLabel (
"you are standing next to a river.", true)
label := elements.NewLabelWrapped (
"you are standing next to a river.")
button0 := elements.NewButton("go in the river")
button0.OnClick(world.SwitchFunc("wet"))
@ -29,70 +29,65 @@ func run () {
button2 := elements.NewButton("turn around")
button2.OnClick(world.SwitchFunc("bear"))
container.Adopt(label, true)
container.Adopt(button0, false)
container.Adopt(button1, false)
container.Adopt(button2, false)
container.AdoptExpand(label)
container.Adopt(button0, button1, button2)
button0.Focus()
},
"wet": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you get completely soaked.\n" +
"you die of hypothermia.", true)
"you die of hypothermia.")
button0 := elements.NewButton("try again")
button0.OnClick(world.SwitchFunc("start"))
button1 := elements.NewButton("exit")
button1.OnClick(tomo.Stop)
container.Adopt(label, true)
container.Adopt(button0, false)
container.Adopt(button1, false)
container.AdoptExpand(label)
container.Adopt(button0, button1)
button0.Focus()
},
"house": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you are standing in front of a delapidated " +
"house.", true)
"house.")
button1 := elements.NewButton("go inside")
button1.OnClick(world.SwitchFunc("inside"))
button0 := elements.NewButton("turn back")
button0.OnClick(world.SwitchFunc("start"))
container.Adopt(label, true)
container.Adopt(button1, false)
container.Adopt(button0, false)
container.AdoptExpand(label)
container.Adopt(button0, button1)
button1.Focus()
},
"inside": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you are standing inside of the house.\n" +
"it is dark, but rays of light stream " +
"through the window.\n" +
"there is nothing particularly interesting " +
"here.", true)
"here.")
button0 := elements.NewButton("go back outside")
button0.OnClick(world.SwitchFunc("house"))
container.Adopt(label, true)
container.Adopt(button0, false)
container.AdoptExpand(label)
container.Adopt(button0)
button0.Focus()
},
"bear": func () {
label := elements.NewLabel (
label := elements.NewLabelWrapped (
"you come face to face with a bear.\n" +
"it eats you (it was hungry).", true)
"it eats you (it was hungry).")
button0 := elements.NewButton("try again")
button0.OnClick(world.SwitchFunc("start"))
button1 := elements.NewButton("exit")
button1.OnClick(tomo.Stop)
container.Adopt(label, true)
container.Adopt(button0, false)
container.Adopt(button1, false)
container.AdoptExpand(label)
container.Adopt(button0, button1)
button0.Focus()
},
}

View File

@ -15,13 +15,13 @@ func main () {
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 200, 216))
window.SetTitle("Clock")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
clock := fun.NewAnalogClock(time.Now())
container.Adopt(clock, true)
label := elements.NewLabel(formatTime(), false)
container.Adopt(label, false)
label := elements.NewLabel(formatTime())
container.AdoptExpand(clock)
container.Adopt(label)
window.OnClose(tomo.Stop)
window.Show()

View File

@ -12,12 +12,12 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
window.SetTitle("horizontal stack")
container := elements.NewHBox(true, true)
container := elements.NewHBox(elements.SpaceBoth)
window.Adopt(container)
container.Adopt(elements.NewLabel("this is sample text", true), true)
container.Adopt(elements.NewLabel("this is sample text", true), true)
container.Adopt(elements.NewLabel("this is sample text", true), true)
container.AdoptExpand(elements.NewLabelWrapped("this is sample text"))
container.AdoptExpand(elements.NewLabelWrapped("this is sample text"))
container.AdoptExpand(elements.NewLabelWrapped("this is sample text"))
window.OnClose(tomo.Stop)
window.Show()

View File

@ -12,29 +12,31 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
window.SetTitle("Icons")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
container.Adopt(elements.NewLabel("Just some of the wonderful icons we have:", false), false)
container.Adopt(elements.NewSpacer(true), false)
container.Adopt(icons(tomo.IconHome, tomo.IconHistory), true)
container.Adopt(icons(tomo.IconFile, tomo.IconNetwork), true)
container.Adopt(icons(tomo.IconOpen, tomo.IconRemoveFavorite), true)
container.Adopt(icons(tomo.IconCursor, tomo.IconDistort), true)
container.Adopt (
elements.NewLabel("Just some of the wonderful icons we have:"),
elements.NewLine())
container.AdoptExpand (
icons(tomo.IconHome, tomo.IconHistory),
icons(tomo.IconFile, tomo.IconNetwork),
icons(tomo.IconOpen, tomo.IconRemoveFavorite),
icons(tomo.IconCursor, tomo.IconDistort))
closeButton := elements.NewButton("Yes verynice")
closeButton.SetIcon(tomo.IconYes)
closeButton.OnClick(tomo.Stop)
container.Adopt(closeButton, false)
container.Adopt(closeButton)
window.OnClose(tomo.Stop)
window.Show()
}
func icons (min, max tomo.Icon) (container *containers.Box) {
container = containers.NewHBox(false, true)
func icons (min, max tomo.Icon) (container *elements.Box) {
container = elements.NewHBox(elements.SpaceMargin)
for index := min; index <= max; index ++ {
container.Adopt(elements.NewIcon(index, tomo.IconSizeSmall), true)
container.AdoptExpand(elements.NewIcon(index, tomo.IconSizeSmall))
}
return
}

View File

@ -9,7 +9,6 @@ import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/popups"
import "git.tebibyte.media/sashakoshka/tomo/elements"
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
func main () {
tomo.Run(run)
@ -25,7 +24,7 @@ func run () {
file.Close()
if err != nil { fatalError(window, err); return }
container := containers.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
logoImage := elements.NewImage(logo)
button := elements.NewButton("Show me a gopher instead")
button.OnClick (func () {
@ -34,11 +33,11 @@ func run () {
gopher, _, err :=
image.Decode(bytes.NewReader(gopher.GopherPng()))
if err != nil { fatalError(window, err); return }
container.Adopt(elements.NewImage(gopher),true)
container.AdoptExpand(elements.NewImage(gopher))
})
container.Adopt(logoImage, true)
container.Adopt(button, false)
container.AdoptExpand(logoImage)
container.Adopt(button)
window.Adopt(container)
button.Focus()

View File

@ -12,7 +12,7 @@ func main () {
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Enter Details")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
// create inputs
@ -45,13 +45,8 @@ func run () {
fingerLength.OnChange(check)
// add elements to container
container.Adopt(elements.NewLabel("Choose your words carefully.", false), true)
container.Adopt(firstName, false)
container.Adopt(lastName, false)
container.Adopt(fingerLength, false)
container.Adopt(elements.NewSpacer(true), false)
container.Adopt(button, false)
container.AdoptExpand(elements.NewLabel("Choose your words carefully."))
container.Adopt(firstName, lastName, fingerLength, elements.NewLine(), button)
window.OnClose(tomo.Stop)
window.Show()
}

View File

@ -11,7 +11,7 @@ func main () {
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 480, 360))
window.SetTitle("example label")
window.Adopt(elements.NewLabel(text, true))
window.Adopt(elements.NewLabelWrapped(text))
window.OnClose(tomo.Stop)
window.Show()
}

View File

@ -14,7 +14,7 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 300, 0))
window.SetTitle("List Sidebar")
container := elements.NewHBox(true, true)
container := elements.NewHBox(elements.SpaceBoth)
window.Adopt(container)
var currentPage tomo.Element
@ -22,29 +22,30 @@ func run () {
if currentPage != nil {
container.Disown(currentPage)
}
container.Adopt(newPage, true)
container.AdoptExpand(newPage)
currentPage = newPage
}
intro := elements.NewLabel (
intro := elements.NewLabelWrapped (
"The List element can be easily used as a sidebar. " +
"Click on entries to flip pages!", true)
"Click on entries to flip pages!")
button := elements.NewButton("I do nothing!")
button.OnClick (func () {
popups.NewDialog(popups.DialogKindInfo, window, "", "Sike!")
})
mouse := testing.NewMouse()
input := elements.NewTextBox("Write some text", "")
form := elements.NewVBox(false, true)
form.Adopt(elements.NewLabel("I have:", false), false)
form.Adopt(elements.NewSpacer(true), false)
form.Adopt(elements.NewCheckbox("Skin", true), false)
form.Adopt(elements.NewCheckbox("Blood", false), false)
form.Adopt(elements.NewCheckbox("Bone", false), false)
form := elements.NewVBox (
elements.SpaceMargin,
elements.NewLabel("I have:"),
elements.NewLine(),
elements.NewCheckbox("Skin", true),
elements.NewCheckbox("Blood", false),
elements.NewCheckbox("Bone", false))
art := testing.NewArtist()
makePage := func (name string, callback func ()) tomo.Selectable {
cell := elements.NewCell(elements.NewLabel(name, false))
cell := elements.NewCell(elements.NewLabel(name))
cell.OnSelectionChange (func () {
if cell.Selected() { callback() }
})
@ -60,7 +61,7 @@ func run () {
makePage("art", func () { turnPage(art) }))
list.Collapse(96, 0)
container.Adopt(list, false)
container.Adopt(list)
turnPage(intro)
window.OnClose(tomo.Stop)

View File

@ -14,8 +14,9 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(200, 200, 256, 256))
window.SetTitle("Main")
container := elements.NewVBox(true, true)
container.Adopt(elements.NewLabel("Main window", false), true)
container := elements.NewVBox (
elements.SpaceBoth,
elements.NewLabel("Main window"))
window.Adopt(container)
window.OnClose(tomo.Stop)
@ -31,8 +32,9 @@ func createPanel (parent tomo.MainWindow, id int, bounds image.Rectangle) {
window, _ := parent.NewPanel(bounds)
title := fmt.Sprint("Panel #", id)
window.SetTitle(title)
container := containers.NewVBox(true, true)
container.Adopt(elements.NewLabel(title, false), true)
container := elements.NewVBox (
elements.SpaceBoth,
elements.NewLabel(title))
window.Adopt(container)
window.Show()
}

View File

@ -14,10 +14,10 @@ func run () {
if err != nil { panic(err.Error()) }
window.SetTitle("Dialog Boxes")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
container.Adopt(elements.NewLabel("Try out different dialogs:", false), true)
container.AdoptExpand(elements.NewLabel("Try out different dialogs:"))
infoButton := elements.NewButton("popups.DialogKindInfo")
infoButton.OnClick (func () {
@ -27,7 +27,7 @@ func run () {
"Information",
"You are wacky")
})
container.Adopt(infoButton, false)
container.Adopt(infoButton)
infoButton.Focus()
questionButton := elements.NewButton("popups.DialogKindQuestion")
@ -41,7 +41,7 @@ func run () {
popups.Button { "No", func () { } },
popups.Button { "Not sure", func () { } })
})
container.Adopt(questionButton, false)
container.Adopt(questionButton)
warningButton := elements.NewButton("popups.DialogKindWarning")
warningButton.OnClick (func () {
@ -51,7 +51,7 @@ func run () {
"Warning",
"They are fast approaching.")
})
container.Adopt(warningButton, false)
container.Adopt(warningButton)
errorButton := elements.NewButton("popups.DialogKindError")
errorButton.OnClick (func () {
@ -61,7 +61,7 @@ func run () {
"Error",
"There is nowhere left to go.")
})
container.Adopt(errorButton, false)
container.Adopt(errorButton)
menuButton := elements.NewButton("menu")
menuButton.OnClick (func () {
@ -70,14 +70,14 @@ func run () {
tomo.Bounds(0, 0, 64, 64).
Add(menuButton.Entity().Bounds().Min))
if err != nil { println(err.Error()) }
menu.Adopt(elements.NewLabel("I'm a shy window...", true))
menu.Adopt(elements.NewLabelWrapped("I'm a shy window..."))
menu.Show()
})
container.Adopt(menuButton, false)
container.Adopt(menuButton)
cancelButton := elements.NewButton("No thank you.")
cancelButton.OnClick(tomo.Stop)
container.Adopt(cancelButton, false)
container.Adopt(cancelButton)
window.OnClose(tomo.Stop)
window.Show()

View File

@ -13,16 +13,15 @@ func main () {
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Approaching")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
container.Adopt (elements.NewLabel (
"Rapidly approaching your location...", false), false)
container.AdoptExpand(elements.NewLabel("Rapidly approaching your location..."))
bar := elements.NewProgressBar(0)
container.Adopt(bar, false)
container.Adopt(bar)
button := elements.NewButton("Stop")
button.SetEnabled(false)
container.Adopt(button, false)
container.Adopt(button)
window.OnClose(tomo.Stop)
window.Show()

View File

@ -21,7 +21,7 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 640, 480))
window.SetTitle("Raycaster")
container := elements.NewVBox(false, false)
container := elements.NewVBox(elements.SpaceNone)
window.Adopt(container)
wallTexture, _ := TextureFrom(bytes.NewReader(wallTextureBytes))
@ -48,16 +48,16 @@ func run () {
wallTexture,
})
topBar := containers.NewHBox(true, true)
topBar := elements.NewHBox(elements.SpaceBoth)
staminaBar := elements.NewProgressBar(game.Stamina())
healthBar := elements.NewProgressBar(game.Health())
topBar.Adopt(elements.NewLabel("Stamina:", false), false)
topBar.Adopt(staminaBar, true)
topBar.Adopt(elements.NewLabel("Health:", false), false)
topBar.Adopt(healthBar, true)
container.Adopt(topBar, false)
container.Adopt(game, true)
topBar.Adopt(elements.NewLabel("Stamina:"))
topBar.AdoptExpand(staminaBar)
topBar.Adopt(elements.NewLabel("Health:"))
topBar.AdoptExpand(healthBar)
container.Adopt(topBar)
container.AdoptExpand(game)
game.Focus()
game.OnStatUpdate (func () {

View File

@ -12,12 +12,12 @@ func main () {
func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 240))
window.SetTitle("Scroll")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
textBox := elements.NewTextBox("", copypasta)
disconnectedContainer := elements.NewHBox(false, true)
disconnectedContainer := elements.NewHBox(elements.SpaceMargin)
list := elements.NewList (
2,
elements.NewCell(elements.NewCheckbox("Item 0", true)),
@ -42,8 +42,9 @@ func run () {
elements.NewCell(elements.NewCheckbox("Item 19", false)),
elements.NewCell(elements.NewCheckbox("Item 20", true)),
elements.NewCell(elements.NewCheckbox("Item 21", false)),
elements.NewCell (elements.NewScroll (elements.NewTextBox (
"", "I bet you weren't expecting this!"), true, false)))
elements.NewCell(elements.NewScroll (
elements.ScrollHorizontal,
elements.NewTextBox("", "I bet you weren't expecting this!"))))
list.Collapse(0, 32)
scrollBar := elements.NewScrollBar(true)
list.OnScrollBoundsChange (func () {
@ -55,16 +56,16 @@ func run () {
list.ScrollTo(viewport)
})
container.Adopt(elements.NewLabel("A ScrollContainer:", false), false)
container.Adopt(elements.NewScroll(textBox, true, false), false)
disconnectedContainer.Adopt(list, false)
disconnectedContainer.Adopt (elements.NewLabel (
container.Adopt(elements.NewLabel("A ScrollContainer:"))
container.Adopt(elements.NewScroll(elements.ScrollHorizontal, textBox))
disconnectedContainer.Adopt(list)
disconnectedContainer.AdoptExpand(elements.NewLabelWrapped (
"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)
disconnectedContainer.Adopt(scrollBar, false)
container.Adopt(disconnectedContainer, true)
"don't do it."))
disconnectedContainer.Adopt(scrollBar)
container.AdoptExpand(disconnectedContainer)
window.OnClose(tomo.Stop)
window.Show()

View File

@ -12,15 +12,15 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Spaced Out")
container := elements.NewVBox(true, true)
window.Adopt(container)
container.Adopt (elements.NewLabel("This is at the top", false), false)
container.Adopt (elements.NewSpacer(true), false)
container.Adopt (elements.NewLabel("This is in the middle", false), false)
container.Adopt (elements.NewSpacer(false), true)
container.Adopt (elements.NewLabel("This is at the bottom", false), false)
container := elements.NewVBox (
elements.SpaceBoth,
elements.NewLabel("This is at the top"),
elements.NewLine(),
elements.NewLabel("This is in the middle"))
container.AdoptExpand(elements.NewSpacer())
container.Adopt(elements.NewLabel("This is at the bottom"))
window.Adopt(container)
window.OnClose(tomo.Stop)
window.Show()
}

View File

@ -12,12 +12,12 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
window.SetTitle("Switches")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
window.Adopt(container)
container.Adopt(elements.NewSwitch("hahahah", false), false)
container.Adopt(elements.NewSwitch("hehehehheheh", false), false)
container.Adopt(elements.NewSwitch("you can flick da swicth", false), false)
container.Adopt(elements.NewSwitch("hahahah", false))
container.Adopt(elements.NewSwitch("hehehehheheh", false))
container.Adopt(elements.NewSwitch("you can flick da swicth", false))
window.OnClose(tomo.Stop)
window.Show()

View File

@ -13,26 +13,25 @@ func run () {
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 128, 128))
window.SetTitle("vertical stack")
container := elements.NewVBox(true, true)
container := elements.NewVBox(elements.SpaceBoth)
label := elements.NewLabel("it is a label hehe", true)
label := elements.NewLabelWrapped("it is a label hehe")
button := elements.NewButton("drawing pad")
okButton := elements.NewButton("OK")
button.OnClick (func () {
container.DisownAll()
container.Adopt(elements.NewLabel("Draw here:", false), false)
container.Adopt(testing.NewMouse(), true)
container.Adopt(okButton, false)
container.Adopt(elements.NewLabel("Draw here (not really):"))
container.AdoptExpand(testing.NewMouse())
container.Adopt(okButton)
okButton.Focus()
})
okButton.OnClick(tomo.Stop)
container.Adopt(label, true)
container.Adopt(button, false)
container.Adopt(okButton, false)
okButton.Focus()
container.AdoptExpand(label)
container.Adopt(button, okButton)
window.Adopt(container)
okButton.Focus()
window.OnClose(tomo.Stop)
window.Show()
}