Updated the examples
This commit is contained in:
parent
14080b1f88
commit
7cdc5868e5
@ -54,9 +54,16 @@ func NewHBox (space Space, children ...tomo.Element) (element *Box) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewHBox creates a new vertical box.
|
// NewHBox creates a new vertical box.
|
||||||
func NewVBox (space Space) (element *Box) {
|
func NewVBox (space Space, children ...tomo.Element) (element *Box) {
|
||||||
element = NewHBox(space)
|
element = &Box {
|
||||||
element.vertical = true
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
104
elements/containers/common.go
Normal file
104
elements/containers/common.go
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -129,5 +129,7 @@ func imageWindow (parent tomo.Window, image image.Image) {
|
|||||||
container.AdoptExpand(elements.NewImage(image))
|
container.AdoptExpand(elements.NewImage(image))
|
||||||
container.Adopt(closeButton)
|
container.Adopt(closeButton)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
|
closeButton.Focus()
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
@ -22,44 +22,40 @@ func run () {
|
|||||||
if err != nil { panic(err.Error()); return }
|
if err != nil { panic(err.Error()); return }
|
||||||
|
|
||||||
document := elements.NewDocument()
|
document := elements.NewDocument()
|
||||||
|
document.Adopt (
|
||||||
document.Adopt (elements.NewLabel (
|
elements.NewLabelWrapped (
|
||||||
"A document container is a vertically stacked container " +
|
"A document container is a vertically stacked container " +
|
||||||
"capable of properly laying out flexible elements such as " +
|
"capable of properly laying out flexible elements such as " +
|
||||||
"text-wrapped labels. You can also include normal elements " +
|
"text-wrapped labels. You can also include normal elements " +
|
||||||
"like:", true), true)
|
"like:"),
|
||||||
document.Adopt (elements.NewButton (
|
elements.NewButton("Buttons,"),
|
||||||
"Buttons,"), true)
|
elements.NewCheckbox("Checkboxes,", true),
|
||||||
document.Adopt (elements.NewCheckbox (
|
elements.NewTextBox("", "And text boxes."),
|
||||||
"Checkboxes,", true), true)
|
elements.NewLine(),
|
||||||
document.Adopt(elements.NewTextBox("", "And text boxes."), true)
|
elements.NewLabelWrapped (
|
||||||
document.Adopt (elements.NewSpacer(true), true)
|
"Document containers are meant to be placed inside of a " +
|
||||||
document.Adopt (elements.NewLabel (
|
"ScrollContainer, like this one."),
|
||||||
"Document containers are meant to be placed inside of a " +
|
elements.NewLabelWrapped (
|
||||||
"ScrollContainer, like this one.", true), true)
|
"You could use document containers to do things like display various " +
|
||||||
document.Adopt (elements.NewLabel (
|
"forms of hypertext (like HTML, gemtext, markdown, etc.), " +
|
||||||
"You could use document containers to do things like display various " +
|
"lay out a settings menu with descriptive label text between " +
|
||||||
"forms of hypertext (like HTML, gemtext, markdown, etc.), " +
|
"control groups like in iOS, or list comment or chat histories."),
|
||||||
"lay out a settings menu with descriptive label text between " +
|
elements.NewImage(logo),
|
||||||
"control groups like in iOS, or list comment or chat histories.",
|
elements.NewLabelWrapped (
|
||||||
true), true)
|
"You can also choose whether each element is on its own line " +
|
||||||
document.Adopt(elements.NewImage(logo), true)
|
"(sort of like an HTML/CSS block element) or on a line with " +
|
||||||
document.Adopt (elements.NewLabel (
|
"other adjacent elements (like an HTML/CSS inline element)."))
|
||||||
"You can also choose whether each element is on its own line " +
|
document.AdoptInline (
|
||||||
"(sort of like an HTML/CSS block element) or on a line with " +
|
elements.NewButton("Just"),
|
||||||
"other adjacent elements (like an HTML/CSS inline element).",
|
elements.NewButton("like"),
|
||||||
true), true)
|
elements.NewButton("this."))
|
||||||
document.Adopt(elements.NewButton("Just"), false)
|
document.Adopt (elements.NewLabelWrapped (
|
||||||
document.Adopt(elements.NewButton("like"), false)
|
"Oh, you're a switch? Then name all of these switches:"))
|
||||||
document.Adopt(elements.NewButton("this."), false)
|
|
||||||
document.Adopt (elements.NewLabel (
|
|
||||||
"Oh, you're a switch? Then name all of these switches:",
|
|
||||||
true), true)
|
|
||||||
for i := 0; i < 30; i ++ {
|
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.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
@ -12,15 +12,15 @@ func main () {
|
|||||||
func run () {
|
func run () {
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 192, 192))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 192, 192))
|
||||||
window.SetTitle("adventure")
|
window.SetTitle("adventure")
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
var world flow.Flow
|
var world flow.Flow
|
||||||
world.Transition = container.DisownAll
|
world.Transition = container.DisownAll
|
||||||
world.Stages = map [string] func () {
|
world.Stages = map [string] func () {
|
||||||
"start": func () {
|
"start": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabelWrapped (
|
||||||
"you are standing next to a river.", true)
|
"you are standing next to a river.")
|
||||||
|
|
||||||
button0 := elements.NewButton("go in the river")
|
button0 := elements.NewButton("go in the river")
|
||||||
button0.OnClick(world.SwitchFunc("wet"))
|
button0.OnClick(world.SwitchFunc("wet"))
|
||||||
@ -29,70 +29,65 @@ func run () {
|
|||||||
button2 := elements.NewButton("turn around")
|
button2 := elements.NewButton("turn around")
|
||||||
button2.OnClick(world.SwitchFunc("bear"))
|
button2.OnClick(world.SwitchFunc("bear"))
|
||||||
|
|
||||||
container.Adopt(label, true)
|
container.AdoptExpand(label)
|
||||||
container.Adopt(button0, false)
|
container.Adopt(button0, button1, button2)
|
||||||
container.Adopt(button1, false)
|
|
||||||
container.Adopt(button2, false)
|
|
||||||
button0.Focus()
|
button0.Focus()
|
||||||
},
|
},
|
||||||
"wet": func () {
|
"wet": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabelWrapped (
|
||||||
"you get completely soaked.\n" +
|
"you get completely soaked.\n" +
|
||||||
"you die of hypothermia.", true)
|
"you die of hypothermia.")
|
||||||
|
|
||||||
button0 := elements.NewButton("try again")
|
button0 := elements.NewButton("try again")
|
||||||
button0.OnClick(world.SwitchFunc("start"))
|
button0.OnClick(world.SwitchFunc("start"))
|
||||||
button1 := elements.NewButton("exit")
|
button1 := elements.NewButton("exit")
|
||||||
button1.OnClick(tomo.Stop)
|
button1.OnClick(tomo.Stop)
|
||||||
|
|
||||||
container.Adopt(label, true)
|
container.AdoptExpand(label)
|
||||||
container.Adopt(button0, false)
|
container.Adopt(button0, button1)
|
||||||
container.Adopt(button1, false)
|
|
||||||
button0.Focus()
|
button0.Focus()
|
||||||
},
|
},
|
||||||
"house": func () {
|
"house": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabelWrapped (
|
||||||
"you are standing in front of a delapidated " +
|
"you are standing in front of a delapidated " +
|
||||||
"house.", true)
|
"house.")
|
||||||
|
|
||||||
button1 := elements.NewButton("go inside")
|
button1 := elements.NewButton("go inside")
|
||||||
button1.OnClick(world.SwitchFunc("inside"))
|
button1.OnClick(world.SwitchFunc("inside"))
|
||||||
button0 := elements.NewButton("turn back")
|
button0 := elements.NewButton("turn back")
|
||||||
button0.OnClick(world.SwitchFunc("start"))
|
button0.OnClick(world.SwitchFunc("start"))
|
||||||
|
|
||||||
container.Adopt(label, true)
|
container.AdoptExpand(label)
|
||||||
container.Adopt(button1, false)
|
container.Adopt(button0, button1)
|
||||||
container.Adopt(button0, false)
|
|
||||||
button1.Focus()
|
button1.Focus()
|
||||||
},
|
},
|
||||||
"inside": func () {
|
"inside": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabelWrapped (
|
||||||
"you are standing inside of the house.\n" +
|
"you are standing inside of the house.\n" +
|
||||||
"it is dark, but rays of light stream " +
|
"it is dark, but rays of light stream " +
|
||||||
"through the window.\n" +
|
"through the window.\n" +
|
||||||
"there is nothing particularly interesting " +
|
"there is nothing particularly interesting " +
|
||||||
"here.", true)
|
"here.")
|
||||||
|
|
||||||
button0 := elements.NewButton("go back outside")
|
button0 := elements.NewButton("go back outside")
|
||||||
button0.OnClick(world.SwitchFunc("house"))
|
button0.OnClick(world.SwitchFunc("house"))
|
||||||
|
|
||||||
container.Adopt(label, true)
|
container.AdoptExpand(label)
|
||||||
container.Adopt(button0, false)
|
container.Adopt(button0)
|
||||||
button0.Focus()
|
button0.Focus()
|
||||||
},
|
},
|
||||||
"bear": func () {
|
"bear": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabelWrapped (
|
||||||
"you come face to face with a bear.\n" +
|
"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 := elements.NewButton("try again")
|
||||||
button0.OnClick(world.SwitchFunc("start"))
|
button0.OnClick(world.SwitchFunc("start"))
|
||||||
button1 := elements.NewButton("exit")
|
button1 := elements.NewButton("exit")
|
||||||
button1.OnClick(tomo.Stop)
|
button1.OnClick(tomo.Stop)
|
||||||
|
|
||||||
container.Adopt(label, true)
|
container.AdoptExpand(label)
|
||||||
container.Adopt(button0, false)
|
container.Adopt(button0, button1)
|
||||||
container.Adopt(button1, false)
|
|
||||||
button0.Focus()
|
button0.Focus()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@ func main () {
|
|||||||
func run () {
|
func run () {
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 200, 216))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 200, 216))
|
||||||
window.SetTitle("Clock")
|
window.SetTitle("Clock")
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
clock := fun.NewAnalogClock(time.Now())
|
clock := fun.NewAnalogClock(time.Now())
|
||||||
container.Adopt(clock, true)
|
label := elements.NewLabel(formatTime())
|
||||||
label := elements.NewLabel(formatTime(), false)
|
container.AdoptExpand(clock)
|
||||||
container.Adopt(label, false)
|
container.Adopt(label)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
@ -12,12 +12,12 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
|
||||||
window.SetTitle("horizontal stack")
|
window.SetTitle("horizontal stack")
|
||||||
|
|
||||||
container := elements.NewHBox(true, true)
|
container := elements.NewHBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt(elements.NewLabel("this is sample text", true), true)
|
container.AdoptExpand(elements.NewLabelWrapped("this is sample text"))
|
||||||
container.Adopt(elements.NewLabel("this is sample text", true), true)
|
container.AdoptExpand(elements.NewLabelWrapped("this is sample text"))
|
||||||
container.Adopt(elements.NewLabel("this is sample text", true), true)
|
container.AdoptExpand(elements.NewLabelWrapped("this is sample text"))
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
@ -12,29 +12,31 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 0))
|
||||||
window.SetTitle("Icons")
|
window.SetTitle("Icons")
|
||||||
|
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt(elements.NewLabel("Just some of the wonderful icons we have:", false), false)
|
container.Adopt (
|
||||||
container.Adopt(elements.NewSpacer(true), false)
|
elements.NewLabel("Just some of the wonderful icons we have:"),
|
||||||
container.Adopt(icons(tomo.IconHome, tomo.IconHistory), true)
|
elements.NewLine())
|
||||||
container.Adopt(icons(tomo.IconFile, tomo.IconNetwork), true)
|
container.AdoptExpand (
|
||||||
container.Adopt(icons(tomo.IconOpen, tomo.IconRemoveFavorite), true)
|
icons(tomo.IconHome, tomo.IconHistory),
|
||||||
container.Adopt(icons(tomo.IconCursor, tomo.IconDistort), true)
|
icons(tomo.IconFile, tomo.IconNetwork),
|
||||||
|
icons(tomo.IconOpen, tomo.IconRemoveFavorite),
|
||||||
|
icons(tomo.IconCursor, tomo.IconDistort))
|
||||||
|
|
||||||
closeButton := elements.NewButton("Yes verynice")
|
closeButton := elements.NewButton("Yes verynice")
|
||||||
closeButton.SetIcon(tomo.IconYes)
|
closeButton.SetIcon(tomo.IconYes)
|
||||||
closeButton.OnClick(tomo.Stop)
|
closeButton.OnClick(tomo.Stop)
|
||||||
container.Adopt(closeButton, false)
|
container.Adopt(closeButton)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func icons (min, max tomo.Icon) (container *containers.Box) {
|
func icons (min, max tomo.Icon) (container *elements.Box) {
|
||||||
container = containers.NewHBox(false, true)
|
container = elements.NewHBox(elements.SpaceMargin)
|
||||||
for index := min; index <= max; index ++ {
|
for index := min; index <= max; index ++ {
|
||||||
container.Adopt(elements.NewIcon(index, tomo.IconSizeSmall), true)
|
container.AdoptExpand(elements.NewIcon(index, tomo.IconSizeSmall))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import "git.tebibyte.media/sashakoshka/tomo"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo/popups"
|
import "git.tebibyte.media/sashakoshka/tomo/popups"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
|
||||||
|
|
||||||
func main () {
|
func main () {
|
||||||
tomo.Run(run)
|
tomo.Run(run)
|
||||||
@ -25,7 +24,7 @@ func run () {
|
|||||||
file.Close()
|
file.Close()
|
||||||
if err != nil { fatalError(window, err); return }
|
if err != nil { fatalError(window, err); return }
|
||||||
|
|
||||||
container := containers.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
logoImage := elements.NewImage(logo)
|
logoImage := elements.NewImage(logo)
|
||||||
button := elements.NewButton("Show me a gopher instead")
|
button := elements.NewButton("Show me a gopher instead")
|
||||||
button.OnClick (func () {
|
button.OnClick (func () {
|
||||||
@ -34,11 +33,11 @@ func run () {
|
|||||||
gopher, _, err :=
|
gopher, _, err :=
|
||||||
image.Decode(bytes.NewReader(gopher.GopherPng()))
|
image.Decode(bytes.NewReader(gopher.GopherPng()))
|
||||||
if err != nil { fatalError(window, err); return }
|
if err != nil { fatalError(window, err); return }
|
||||||
container.Adopt(elements.NewImage(gopher),true)
|
container.AdoptExpand(elements.NewImage(gopher))
|
||||||
})
|
})
|
||||||
|
|
||||||
container.Adopt(logoImage, true)
|
container.AdoptExpand(logoImage)
|
||||||
container.Adopt(button, false)
|
container.Adopt(button)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
button.Focus()
|
button.Focus()
|
||||||
|
@ -12,7 +12,7 @@ func main () {
|
|||||||
func run () {
|
func run () {
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
||||||
window.SetTitle("Enter Details")
|
window.SetTitle("Enter Details")
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
// create inputs
|
// create inputs
|
||||||
@ -45,13 +45,8 @@ func run () {
|
|||||||
fingerLength.OnChange(check)
|
fingerLength.OnChange(check)
|
||||||
|
|
||||||
// add elements to container
|
// add elements to container
|
||||||
container.Adopt(elements.NewLabel("Choose your words carefully.", false), true)
|
container.AdoptExpand(elements.NewLabel("Choose your words carefully."))
|
||||||
container.Adopt(firstName, false)
|
container.Adopt(firstName, lastName, fingerLength, elements.NewLine(), button)
|
||||||
container.Adopt(lastName, false)
|
|
||||||
container.Adopt(fingerLength, false)
|
|
||||||
container.Adopt(elements.NewSpacer(true), false)
|
|
||||||
container.Adopt(button, false)
|
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ func main () {
|
|||||||
func run () {
|
func run () {
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 480, 360))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 480, 360))
|
||||||
window.SetTitle("example label")
|
window.SetTitle("example label")
|
||||||
window.Adopt(elements.NewLabel(text, true))
|
window.Adopt(elements.NewLabelWrapped(text))
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 300, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 300, 0))
|
||||||
window.SetTitle("List Sidebar")
|
window.SetTitle("List Sidebar")
|
||||||
|
|
||||||
container := elements.NewHBox(true, true)
|
container := elements.NewHBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
var currentPage tomo.Element
|
var currentPage tomo.Element
|
||||||
@ -22,29 +22,30 @@ func run () {
|
|||||||
if currentPage != nil {
|
if currentPage != nil {
|
||||||
container.Disown(currentPage)
|
container.Disown(currentPage)
|
||||||
}
|
}
|
||||||
container.Adopt(newPage, true)
|
container.AdoptExpand(newPage)
|
||||||
currentPage = newPage
|
currentPage = newPage
|
||||||
}
|
}
|
||||||
|
|
||||||
intro := elements.NewLabel (
|
intro := elements.NewLabelWrapped (
|
||||||
"The List element can be easily used as a sidebar. " +
|
"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 := elements.NewButton("I do nothing!")
|
||||||
button.OnClick (func () {
|
button.OnClick (func () {
|
||||||
popups.NewDialog(popups.DialogKindInfo, window, "", "Sike!")
|
popups.NewDialog(popups.DialogKindInfo, window, "", "Sike!")
|
||||||
})
|
})
|
||||||
mouse := testing.NewMouse()
|
mouse := testing.NewMouse()
|
||||||
input := elements.NewTextBox("Write some text", "")
|
input := elements.NewTextBox("Write some text", "")
|
||||||
form := elements.NewVBox(false, true)
|
form := elements.NewVBox (
|
||||||
form.Adopt(elements.NewLabel("I have:", false), false)
|
elements.SpaceMargin,
|
||||||
form.Adopt(elements.NewSpacer(true), false)
|
elements.NewLabel("I have:"),
|
||||||
form.Adopt(elements.NewCheckbox("Skin", true), false)
|
elements.NewLine(),
|
||||||
form.Adopt(elements.NewCheckbox("Blood", false), false)
|
elements.NewCheckbox("Skin", true),
|
||||||
form.Adopt(elements.NewCheckbox("Bone", false), false)
|
elements.NewCheckbox("Blood", false),
|
||||||
|
elements.NewCheckbox("Bone", false))
|
||||||
art := testing.NewArtist()
|
art := testing.NewArtist()
|
||||||
|
|
||||||
makePage := func (name string, callback func ()) tomo.Selectable {
|
makePage := func (name string, callback func ()) tomo.Selectable {
|
||||||
cell := elements.NewCell(elements.NewLabel(name, false))
|
cell := elements.NewCell(elements.NewLabel(name))
|
||||||
cell.OnSelectionChange (func () {
|
cell.OnSelectionChange (func () {
|
||||||
if cell.Selected() { callback() }
|
if cell.Selected() { callback() }
|
||||||
})
|
})
|
||||||
@ -60,7 +61,7 @@ func run () {
|
|||||||
makePage("art", func () { turnPage(art) }))
|
makePage("art", func () { turnPage(art) }))
|
||||||
list.Collapse(96, 0)
|
list.Collapse(96, 0)
|
||||||
|
|
||||||
container.Adopt(list, false)
|
container.Adopt(list)
|
||||||
turnPage(intro)
|
turnPage(intro)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
|
@ -14,8 +14,9 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(200, 200, 256, 256))
|
window, _ := tomo.NewWindow(tomo.Bounds(200, 200, 256, 256))
|
||||||
window.SetTitle("Main")
|
window.SetTitle("Main")
|
||||||
|
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox (
|
||||||
container.Adopt(elements.NewLabel("Main window", false), true)
|
elements.SpaceBoth,
|
||||||
|
elements.NewLabel("Main window"))
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
@ -31,8 +32,9 @@ func createPanel (parent tomo.MainWindow, id int, bounds image.Rectangle) {
|
|||||||
window, _ := parent.NewPanel(bounds)
|
window, _ := parent.NewPanel(bounds)
|
||||||
title := fmt.Sprint("Panel #", id)
|
title := fmt.Sprint("Panel #", id)
|
||||||
window.SetTitle(title)
|
window.SetTitle(title)
|
||||||
container := containers.NewVBox(true, true)
|
container := elements.NewVBox (
|
||||||
container.Adopt(elements.NewLabel(title, false), true)
|
elements.SpaceBoth,
|
||||||
|
elements.NewLabel(title))
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,10 @@ func run () {
|
|||||||
if err != nil { panic(err.Error()) }
|
if err != nil { panic(err.Error()) }
|
||||||
window.SetTitle("Dialog Boxes")
|
window.SetTitle("Dialog Boxes")
|
||||||
|
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
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 := elements.NewButton("popups.DialogKindInfo")
|
||||||
infoButton.OnClick (func () {
|
infoButton.OnClick (func () {
|
||||||
@ -27,7 +27,7 @@ func run () {
|
|||||||
"Information",
|
"Information",
|
||||||
"You are wacky")
|
"You are wacky")
|
||||||
})
|
})
|
||||||
container.Adopt(infoButton, false)
|
container.Adopt(infoButton)
|
||||||
infoButton.Focus()
|
infoButton.Focus()
|
||||||
|
|
||||||
questionButton := elements.NewButton("popups.DialogKindQuestion")
|
questionButton := elements.NewButton("popups.DialogKindQuestion")
|
||||||
@ -41,7 +41,7 @@ func run () {
|
|||||||
popups.Button { "No", func () { } },
|
popups.Button { "No", func () { } },
|
||||||
popups.Button { "Not sure", func () { } })
|
popups.Button { "Not sure", func () { } })
|
||||||
})
|
})
|
||||||
container.Adopt(questionButton, false)
|
container.Adopt(questionButton)
|
||||||
|
|
||||||
warningButton := elements.NewButton("popups.DialogKindWarning")
|
warningButton := elements.NewButton("popups.DialogKindWarning")
|
||||||
warningButton.OnClick (func () {
|
warningButton.OnClick (func () {
|
||||||
@ -51,7 +51,7 @@ func run () {
|
|||||||
"Warning",
|
"Warning",
|
||||||
"They are fast approaching.")
|
"They are fast approaching.")
|
||||||
})
|
})
|
||||||
container.Adopt(warningButton, false)
|
container.Adopt(warningButton)
|
||||||
|
|
||||||
errorButton := elements.NewButton("popups.DialogKindError")
|
errorButton := elements.NewButton("popups.DialogKindError")
|
||||||
errorButton.OnClick (func () {
|
errorButton.OnClick (func () {
|
||||||
@ -61,7 +61,7 @@ func run () {
|
|||||||
"Error",
|
"Error",
|
||||||
"There is nowhere left to go.")
|
"There is nowhere left to go.")
|
||||||
})
|
})
|
||||||
container.Adopt(errorButton, false)
|
container.Adopt(errorButton)
|
||||||
|
|
||||||
menuButton := elements.NewButton("menu")
|
menuButton := elements.NewButton("menu")
|
||||||
menuButton.OnClick (func () {
|
menuButton.OnClick (func () {
|
||||||
@ -70,14 +70,14 @@ func run () {
|
|||||||
tomo.Bounds(0, 0, 64, 64).
|
tomo.Bounds(0, 0, 64, 64).
|
||||||
Add(menuButton.Entity().Bounds().Min))
|
Add(menuButton.Entity().Bounds().Min))
|
||||||
if err != nil { println(err.Error()) }
|
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()
|
menu.Show()
|
||||||
})
|
})
|
||||||
container.Adopt(menuButton, false)
|
container.Adopt(menuButton)
|
||||||
|
|
||||||
cancelButton := elements.NewButton("No thank you.")
|
cancelButton := elements.NewButton("No thank you.")
|
||||||
cancelButton.OnClick(tomo.Stop)
|
cancelButton.OnClick(tomo.Stop)
|
||||||
container.Adopt(cancelButton, false)
|
container.Adopt(cancelButton)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
@ -13,16 +13,15 @@ func main () {
|
|||||||
func run () {
|
func run () {
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
||||||
window.SetTitle("Approaching")
|
window.SetTitle("Approaching")
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt (elements.NewLabel (
|
container.AdoptExpand(elements.NewLabel("Rapidly approaching your location..."))
|
||||||
"Rapidly approaching your location...", false), false)
|
|
||||||
bar := elements.NewProgressBar(0)
|
bar := elements.NewProgressBar(0)
|
||||||
container.Adopt(bar, false)
|
container.Adopt(bar)
|
||||||
button := elements.NewButton("Stop")
|
button := elements.NewButton("Stop")
|
||||||
button.SetEnabled(false)
|
button.SetEnabled(false)
|
||||||
container.Adopt(button, false)
|
container.Adopt(button)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
@ -21,7 +21,7 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 640, 480))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 640, 480))
|
||||||
window.SetTitle("Raycaster")
|
window.SetTitle("Raycaster")
|
||||||
|
|
||||||
container := elements.NewVBox(false, false)
|
container := elements.NewVBox(elements.SpaceNone)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
wallTexture, _ := TextureFrom(bytes.NewReader(wallTextureBytes))
|
wallTexture, _ := TextureFrom(bytes.NewReader(wallTextureBytes))
|
||||||
@ -48,16 +48,16 @@ func run () {
|
|||||||
wallTexture,
|
wallTexture,
|
||||||
})
|
})
|
||||||
|
|
||||||
topBar := containers.NewHBox(true, true)
|
topBar := elements.NewHBox(elements.SpaceBoth)
|
||||||
staminaBar := elements.NewProgressBar(game.Stamina())
|
staminaBar := elements.NewProgressBar(game.Stamina())
|
||||||
healthBar := elements.NewProgressBar(game.Health())
|
healthBar := elements.NewProgressBar(game.Health())
|
||||||
|
|
||||||
topBar.Adopt(elements.NewLabel("Stamina:", false), false)
|
topBar.Adopt(elements.NewLabel("Stamina:"))
|
||||||
topBar.Adopt(staminaBar, true)
|
topBar.AdoptExpand(staminaBar)
|
||||||
topBar.Adopt(elements.NewLabel("Health:", false), false)
|
topBar.Adopt(elements.NewLabel("Health:"))
|
||||||
topBar.Adopt(healthBar, true)
|
topBar.AdoptExpand(healthBar)
|
||||||
container.Adopt(topBar, false)
|
container.Adopt(topBar)
|
||||||
container.Adopt(game, true)
|
container.AdoptExpand(game)
|
||||||
game.Focus()
|
game.Focus()
|
||||||
|
|
||||||
game.OnStatUpdate (func () {
|
game.OnStatUpdate (func () {
|
||||||
|
@ -12,12 +12,12 @@ func main () {
|
|||||||
func run () {
|
func run () {
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 240))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 360, 240))
|
||||||
window.SetTitle("Scroll")
|
window.SetTitle("Scroll")
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
textBox := elements.NewTextBox("", copypasta)
|
textBox := elements.NewTextBox("", copypasta)
|
||||||
|
|
||||||
disconnectedContainer := elements.NewHBox(false, true)
|
disconnectedContainer := elements.NewHBox(elements.SpaceMargin)
|
||||||
list := elements.NewList (
|
list := elements.NewList (
|
||||||
2,
|
2,
|
||||||
elements.NewCell(elements.NewCheckbox("Item 0", true)),
|
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 19", false)),
|
||||||
elements.NewCell(elements.NewCheckbox("Item 20", true)),
|
elements.NewCell(elements.NewCheckbox("Item 20", true)),
|
||||||
elements.NewCell(elements.NewCheckbox("Item 21", false)),
|
elements.NewCell(elements.NewCheckbox("Item 21", false)),
|
||||||
elements.NewCell (elements.NewScroll (elements.NewTextBox (
|
elements.NewCell(elements.NewScroll (
|
||||||
"", "I bet you weren't expecting this!"), true, false)))
|
elements.ScrollHorizontal,
|
||||||
|
elements.NewTextBox("", "I bet you weren't expecting this!"))))
|
||||||
list.Collapse(0, 32)
|
list.Collapse(0, 32)
|
||||||
scrollBar := elements.NewScrollBar(true)
|
scrollBar := elements.NewScrollBar(true)
|
||||||
list.OnScrollBoundsChange (func () {
|
list.OnScrollBoundsChange (func () {
|
||||||
@ -55,16 +56,16 @@ func run () {
|
|||||||
list.ScrollTo(viewport)
|
list.ScrollTo(viewport)
|
||||||
})
|
})
|
||||||
|
|
||||||
container.Adopt(elements.NewLabel("A ScrollContainer:", false), false)
|
container.Adopt(elements.NewLabel("A ScrollContainer:"))
|
||||||
container.Adopt(elements.NewScroll(textBox, true, false), false)
|
container.Adopt(elements.NewScroll(elements.ScrollHorizontal, textBox))
|
||||||
disconnectedContainer.Adopt(list, false)
|
disconnectedContainer.Adopt(list)
|
||||||
disconnectedContainer.Adopt (elements.NewLabel (
|
disconnectedContainer.AdoptExpand(elements.NewLabelWrapped (
|
||||||
"Notice how the scroll bar to the right can be used to " +
|
"Notice how the scroll bar to the right can be used to " +
|
||||||
"control the list, despite not even touching it. It is " +
|
"control the list, despite not even touching it. It is " +
|
||||||
"indeed a thing you can do. It is also terrible UI design so " +
|
"indeed a thing you can do. It is also terrible UI design so " +
|
||||||
"don't do it.", true), true)
|
"don't do it."))
|
||||||
disconnectedContainer.Adopt(scrollBar, false)
|
disconnectedContainer.Adopt(scrollBar)
|
||||||
container.Adopt(disconnectedContainer, true)
|
container.AdoptExpand(disconnectedContainer)
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
@ -12,15 +12,15 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
||||||
window.SetTitle("Spaced Out")
|
window.SetTitle("Spaced Out")
|
||||||
|
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox (
|
||||||
window.Adopt(container)
|
elements.SpaceBoth,
|
||||||
|
elements.NewLabel("This is at the top"),
|
||||||
container.Adopt (elements.NewLabel("This is at the top", false), false)
|
elements.NewLine(),
|
||||||
container.Adopt (elements.NewSpacer(true), false)
|
elements.NewLabel("This is in the middle"))
|
||||||
container.Adopt (elements.NewLabel("This is in the middle", false), false)
|
container.AdoptExpand(elements.NewSpacer())
|
||||||
container.Adopt (elements.NewSpacer(false), true)
|
container.Adopt(elements.NewLabel("This is at the bottom"))
|
||||||
container.Adopt (elements.NewLabel("This is at the bottom", false), false)
|
|
||||||
|
|
||||||
|
window.Adopt(container)
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,12 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
||||||
window.SetTitle("Switches")
|
window.SetTitle("Switches")
|
||||||
|
|
||||||
container := elements.NewVBox(true, true)
|
container := elements.NewVBox(elements.SpaceBoth)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt(elements.NewSwitch("hahahah", false), false)
|
container.Adopt(elements.NewSwitch("hahahah", false))
|
||||||
container.Adopt(elements.NewSwitch("hehehehheheh", false), false)
|
container.Adopt(elements.NewSwitch("hehehehheheh", false))
|
||||||
container.Adopt(elements.NewSwitch("you can flick da swicth", false), false)
|
container.Adopt(elements.NewSwitch("you can flick da swicth", false))
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
@ -13,26 +13,25 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 128, 128))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 128, 128))
|
||||||
window.SetTitle("vertical stack")
|
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")
|
button := elements.NewButton("drawing pad")
|
||||||
okButton := elements.NewButton("OK")
|
okButton := elements.NewButton("OK")
|
||||||
button.OnClick (func () {
|
button.OnClick (func () {
|
||||||
container.DisownAll()
|
container.DisownAll()
|
||||||
container.Adopt(elements.NewLabel("Draw here:", false), false)
|
container.Adopt(elements.NewLabel("Draw here (not really):"))
|
||||||
container.Adopt(testing.NewMouse(), true)
|
container.AdoptExpand(testing.NewMouse())
|
||||||
container.Adopt(okButton, false)
|
container.Adopt(okButton)
|
||||||
okButton.Focus()
|
okButton.Focus()
|
||||||
})
|
})
|
||||||
okButton.OnClick(tomo.Stop)
|
okButton.OnClick(tomo.Stop)
|
||||||
|
|
||||||
container.Adopt(label, true)
|
container.AdoptExpand(label)
|
||||||
container.Adopt(button, false)
|
container.Adopt(button, okButton)
|
||||||
container.Adopt(okButton, false)
|
|
||||||
okButton.Focus()
|
|
||||||
|
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
|
okButton.Focus()
|
||||||
window.OnClose(tomo.Stop)
|
window.OnClose(tomo.Stop)
|
||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user