Got a bunch of examples working
This commit is contained in:
parent
e16195d274
commit
ed6de3a36f
@ -48,7 +48,7 @@ type TextBox struct {
|
|||||||
// a value. When the value is empty, the placeholder will be displayed in gray
|
// a value. When the value is empty, the placeholder will be displayed in gray
|
||||||
// text.
|
// text.
|
||||||
func NewTextBox (placeholder, value string) (element *TextBox) {
|
func NewTextBox (placeholder, value string) (element *TextBox) {
|
||||||
element = &TextBox { }
|
element = &TextBox { enabled: true }
|
||||||
element.theme.Case = tomo.C("tomo", "textBox")
|
element.theme.Case = tomo.C("tomo", "textBox")
|
||||||
element.entity = tomo.NewEntity(element).(textBoxEntity)
|
element.entity = tomo.NewEntity(element).(textBoxEntity)
|
||||||
element.placeholder = placeholder
|
element.placeholder = placeholder
|
||||||
|
@ -8,7 +8,6 @@ import _ "image/jpeg"
|
|||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/data"
|
import "git.tebibyte.media/sashakoshka/tomo/data"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/popups"
|
import "git.tebibyte.media/sashakoshka/tomo/popups"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -27,9 +26,9 @@ func run () {
|
|||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 256, 0))
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 256, 0))
|
||||||
window.SetTitle("Clipboard")
|
window.SetTitle("Clipboard")
|
||||||
|
|
||||||
container := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
textInput := elements.NewTextBox("", "")
|
textInput := elements.NewTextBox("", "")
|
||||||
controlRow := containers.NewContainer(layouts.Horizontal { true, false })
|
controlRow := containers.NewHBox(false, true)
|
||||||
copyButton := elements.NewButton("Copy")
|
copyButton := elements.NewButton("Copy")
|
||||||
copyButton.SetIcon(tomo.IconCopy)
|
copyButton.SetIcon(tomo.IconCopy)
|
||||||
pasteButton := elements.NewButton("Paste")
|
pasteButton := elements.NewButton("Paste")
|
||||||
@ -123,7 +122,7 @@ func run () {
|
|||||||
func imageWindow (parent tomo.Window, image image.Image) {
|
func imageWindow (parent tomo.Window, image image.Image) {
|
||||||
window, _ := parent.NewModal(tomo.Bounds(0, 0, 0, 0))
|
window, _ := parent.NewModal(tomo.Bounds(0, 0, 0, 0))
|
||||||
window.SetTitle("Clipboard Image")
|
window.SetTitle("Clipboard Image")
|
||||||
container := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
closeButton := elements.NewButton("Ok")
|
closeButton := elements.NewButton("Ok")
|
||||||
closeButton.SetIcon(tomo.IconYes)
|
closeButton.SetIcon(tomo.IconYes)
|
||||||
closeButton.OnClick(window.Close)
|
closeButton.OnClick(window.Close)
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func run () {
|
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
|
||||||
window.SetTitle("dialog")
|
|
||||||
|
|
||||||
container := containers.NewContainer(layouts.Dialog { true, true })
|
|
||||||
window.Adopt(container)
|
|
||||||
|
|
||||||
container.Adopt(elements.NewLabel("you will explode", false), true)
|
|
||||||
cancel := elements.NewButton("Cancel")
|
|
||||||
cancel.SetEnabled(false)
|
|
||||||
container.Adopt(cancel, false)
|
|
||||||
okButton := elements.NewButton("OK")
|
|
||||||
container.Adopt(okButton, false)
|
|
||||||
okButton.Focus()
|
|
||||||
|
|
||||||
window.OnClose(tomo.Stop)
|
|
||||||
window.Show()
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/flow"
|
import "git.tebibyte.media/sashakoshka/tomo/flow"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -14,7 +13,7 @@ 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 := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
var world flow.Flow
|
var world flow.Flow
|
||||||
@ -31,13 +30,11 @@ func run () {
|
|||||||
button2 := elements.NewButton("turn around")
|
button2 := elements.NewButton("turn around")
|
||||||
button2.OnClick(world.SwitchFunc("bear"))
|
button2.OnClick(world.SwitchFunc("bear"))
|
||||||
|
|
||||||
container.Warp ( func () {
|
container.Adopt(label, true)
|
||||||
container.Adopt(label, true)
|
container.Adopt(button0, false)
|
||||||
container.Adopt(button0, false)
|
container.Adopt(button1, false)
|
||||||
container.Adopt(button1, false)
|
container.Adopt(button2, false)
|
||||||
container.Adopt(button2, false)
|
button0.Focus()
|
||||||
button0.Focus()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
"wet": func () {
|
"wet": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabel (
|
||||||
@ -49,12 +46,10 @@ func run () {
|
|||||||
button1 := elements.NewButton("exit")
|
button1 := elements.NewButton("exit")
|
||||||
button1.OnClick(tomo.Stop)
|
button1.OnClick(tomo.Stop)
|
||||||
|
|
||||||
container.Warp (func () {
|
container.Adopt(label, true)
|
||||||
container.Adopt(label, true)
|
container.Adopt(button0, false)
|
||||||
container.Adopt(button0, false)
|
container.Adopt(button1, false)
|
||||||
container.Adopt(button1, false)
|
button0.Focus()
|
||||||
button0.Focus()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
"house": func () {
|
"house": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabel (
|
||||||
@ -66,12 +61,10 @@ func run () {
|
|||||||
button0 := elements.NewButton("turn back")
|
button0 := elements.NewButton("turn back")
|
||||||
button0.OnClick(world.SwitchFunc("start"))
|
button0.OnClick(world.SwitchFunc("start"))
|
||||||
|
|
||||||
container.Warp (func () {
|
container.Adopt(label, true)
|
||||||
container.Adopt(label, true)
|
container.Adopt(button1, false)
|
||||||
container.Adopt(button1, false)
|
container.Adopt(button0, false)
|
||||||
container.Adopt(button0, false)
|
button1.Focus()
|
||||||
button1.Focus()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
"inside": func () {
|
"inside": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabel (
|
||||||
@ -84,11 +77,9 @@ func run () {
|
|||||||
button0 := elements.NewButton("go back outside")
|
button0 := elements.NewButton("go back outside")
|
||||||
button0.OnClick(world.SwitchFunc("house"))
|
button0.OnClick(world.SwitchFunc("house"))
|
||||||
|
|
||||||
container.Warp (func () {
|
container.Adopt(label, true)
|
||||||
container.Adopt(label, true)
|
container.Adopt(button0, false)
|
||||||
container.Adopt(button0, false)
|
button0.Focus()
|
||||||
button0.Focus()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
"bear": func () {
|
"bear": func () {
|
||||||
label := elements.NewLabel (
|
label := elements.NewLabel (
|
||||||
@ -100,12 +91,10 @@ func run () {
|
|||||||
button1 := elements.NewButton("exit")
|
button1 := elements.NewButton("exit")
|
||||||
button1.OnClick(tomo.Stop)
|
button1.OnClick(tomo.Stop)
|
||||||
|
|
||||||
container.Warp (func () {
|
container.Adopt(label, true)
|
||||||
container.Adopt(label, true)
|
container.Adopt(button0, false)
|
||||||
container.Adopt(button0, false)
|
container.Adopt(button1, false)
|
||||||
container.Adopt(button1, false)
|
button0.Focus()
|
||||||
button0.Focus()
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
world.Switch("start")
|
world.Switch("start")
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import "os"
|
import "os"
|
||||||
import "time"
|
import "time"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/fun"
|
||||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
||||||
@ -17,7 +16,7 @@ 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 := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
clock := fun.NewAnalogClock(time.Now())
|
clock := fun.NewAnalogClock(time.Now())
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -14,7 +13,7 @@ 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 := containers.NewContainer(layouts.Horizontal { true, true })
|
container := containers.NewHBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt(elements.NewLabel("this is sample text", true), true)
|
container.Adopt(elements.NewLabel("this is sample text", true), true)
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -14,7 +13,7 @@ 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 := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt(elements.NewLabel("Just some of the wonderful icons we have:", false), false)
|
container.Adopt(elements.NewLabel("Just some of the wonderful icons we have:", false), false)
|
||||||
@ -24,9 +23,8 @@ func run () {
|
|||||||
container.Adopt(icons(tomo.IconOpen, tomo.IconRemoveFavorite), true)
|
container.Adopt(icons(tomo.IconOpen, tomo.IconRemoveFavorite), true)
|
||||||
container.Adopt(icons(tomo.IconCursor, tomo.IconDistort), true)
|
container.Adopt(icons(tomo.IconCursor, tomo.IconDistort), true)
|
||||||
|
|
||||||
closeButton := elements.NewButton("Ok")
|
closeButton := elements.NewButton("Yes verynice")
|
||||||
closeButton.SetIcon(tomo.IconYes)
|
closeButton.SetIcon(tomo.IconYes)
|
||||||
closeButton.ShowText(false)
|
|
||||||
closeButton.OnClick(tomo.Stop)
|
closeButton.OnClick(tomo.Stop)
|
||||||
container.Adopt(closeButton, false)
|
container.Adopt(closeButton, false)
|
||||||
|
|
||||||
@ -34,8 +32,8 @@ func run () {
|
|||||||
window.Show()
|
window.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func icons (min, max tomo.Icon) (container *containers.Container) {
|
func icons (min, max tomo.Icon) (container *containers.Box) {
|
||||||
container = containers.NewContainer(layouts.Horizontal { true, false })
|
container = containers.NewHBox(false, true)
|
||||||
for index := min; index <= max; index ++ {
|
for index := min; index <= max; index ++ {
|
||||||
container.Adopt(elements.NewIcon(index, tomo.IconSizeSmall), true)
|
container.Adopt(elements.NewIcon(index, tomo.IconSizeSmall), true)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import _ "image/png"
|
|||||||
import "github.com/jezek/xgbutil/gopher"
|
import "github.com/jezek/xgbutil/gopher"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
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/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -17,7 +16,7 @@ func main () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run () {
|
func run () {
|
||||||
window, _ := tomo.NewWindow(2, 2)
|
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 0, 0))
|
||||||
window.SetTitle("Tomo Logo")
|
window.SetTitle("Tomo Logo")
|
||||||
|
|
||||||
file, err := os.Open("assets/banner.png")
|
file, err := os.Open("assets/banner.png")
|
||||||
@ -26,16 +25,17 @@ func run () {
|
|||||||
file.Close()
|
file.Close()
|
||||||
if err != nil { fatalError(window, err); return }
|
if err != nil { fatalError(window, err); return }
|
||||||
|
|
||||||
container := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
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 () { container.Warp (func () {
|
button.OnClick (func () {
|
||||||
container.DisownAll()
|
window.SetTitle("Not the Tomo Logo")
|
||||||
gopher, _, err :=
|
container.DisownAll()
|
||||||
image.Decode(bytes.NewReader(gopher.GopherPng()))
|
gopher, _, err :=
|
||||||
if err != nil { fatalError(window, err); return }
|
image.Decode(bytes.NewReader(gopher.GopherPng()))
|
||||||
container.Adopt(elements.NewImage(gopher),true)
|
if err != nil { fatalError(window, err); return }
|
||||||
}) })
|
container.Adopt(elements.NewImage(gopher),true)
|
||||||
|
})
|
||||||
|
|
||||||
container.Adopt(logoImage, true)
|
container.Adopt(logoImage, true)
|
||||||
container.Adopt(button, false)
|
container.Adopt(button, false)
|
||||||
|
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
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/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -14,7 +13,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 := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
// create inputs
|
// create inputs
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
import "image"
|
import "image"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -16,7 +15,7 @@ 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 := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
container.Adopt(elements.NewLabel("Main window", false), true)
|
container.Adopt(elements.NewLabel("Main window", false), true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ 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.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
container.Adopt(elements.NewLabel(title, false), true)
|
container.Adopt(elements.NewLabel(title, false), true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
window.Show()
|
window.Show()
|
||||||
|
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
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/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -16,7 +15,7 @@ func run () {
|
|||||||
if err != nil { panic(err.Error()) }
|
if err != nil { panic(err.Error()) }
|
||||||
window.SetTitle("Dialog Boxes")
|
window.SetTitle("Dialog Boxes")
|
||||||
|
|
||||||
container := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt(elements.NewLabel("Try out different dialogs:", false), true)
|
container.Adopt(elements.NewLabel("Try out different dialogs:", false), true)
|
||||||
@ -67,9 +66,10 @@ func run () {
|
|||||||
|
|
||||||
menuButton := elements.NewButton("menu")
|
menuButton := elements.NewButton("menu")
|
||||||
menuButton.OnClick (func () {
|
menuButton.OnClick (func () {
|
||||||
|
// TODO: make a better way to get the bounds of something
|
||||||
menu, err := window.NewMenu (
|
menu, err := window.NewMenu (
|
||||||
tomo.Bounds(0, 0, 64, 64).
|
tomo.Bounds(0, 0, 64, 64).
|
||||||
Add(menuButton.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.NewLabel("I'm a shy window...", true))
|
||||||
menu.Show()
|
menu.Show()
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import "time"
|
import "time"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
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/layouts"
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
import "git.tebibyte.media/sashakoshka/tomo/elements"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
||||||
@ -15,7 +14,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("Approaching")
|
window.SetTitle("Approaching")
|
||||||
container := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt (elements.NewLabel (
|
container.Adopt (elements.NewLabel (
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
import "image"
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
*Raycaster
|
*Raycaster
|
||||||
@ -31,21 +29,17 @@ func NewGame (world World, textures Textures) (game *Game) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) DrawTo (
|
func (game *Game) Start () {
|
||||||
canvas canvas.Canvas,
|
if game.running == true { return }
|
||||||
bounds image.Rectangle,
|
game.running = true
|
||||||
onDamage func (image.Rectangle),
|
go game.run()
|
||||||
) {
|
}
|
||||||
if canvas == nil {
|
|
||||||
select {
|
func (game *Game) Stop () {
|
||||||
case game.stopChan <- true:
|
select {
|
||||||
default:
|
case game.stopChan <- true:
|
||||||
}
|
default:
|
||||||
} else if !game.running {
|
}
|
||||||
game.running = true
|
|
||||||
go game.run()
|
|
||||||
}
|
|
||||||
game.Raycaster.DrawTo(canvas, bounds, onDamage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (game *Game) Stamina () float64 {
|
func (game *Game) Stamina () float64 {
|
||||||
@ -110,7 +104,7 @@ func (game *Game) tick () {
|
|||||||
game.stamina = 0
|
game.stamina = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
tomo.Do(game.Draw)
|
tomo.Do(game.Invalidate)
|
||||||
if statUpdate && game.onStatUpdate != nil {
|
if statUpdate && game.onStatUpdate != nil {
|
||||||
tomo.Do(game.onStatUpdate)
|
tomo.Do(game.onStatUpdate)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import _ "embed"
|
|||||||
import _ "image/png"
|
import _ "image/png"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
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/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -17,11 +16,13 @@ func main () {
|
|||||||
tomo.Run(run)
|
tomo.Run(run)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME this entire example seems to be broken
|
||||||
|
|
||||||
func run () {
|
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 := containers.NewContainer(layouts.Vertical { false, false })
|
container := containers.NewVBox(false, false)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
wallTexture, _ := TextureFrom(bytes.NewReader(wallTextureBytes))
|
wallTexture, _ := TextureFrom(bytes.NewReader(wallTextureBytes))
|
||||||
@ -48,7 +49,7 @@ func run () {
|
|||||||
wallTexture,
|
wallTexture,
|
||||||
})
|
})
|
||||||
|
|
||||||
topBar := containers.NewContainer(layouts.Horizontal { true, true })
|
topBar := containers.NewHBox(true, true)
|
||||||
staminaBar := elements.NewProgressBar(game.Stamina())
|
staminaBar := elements.NewProgressBar(game.Stamina())
|
||||||
healthBar := elements.NewProgressBar(game.Health())
|
healthBar := elements.NewProgressBar(game.Health())
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ package main
|
|||||||
import "math"
|
import "math"
|
||||||
import "image"
|
import "image"
|
||||||
import "image/color"
|
import "image/color"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/input"
|
import "git.tebibyte.media/sashakoshka/tomo/input"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
import "git.tebibyte.media/sashakoshka/tomo/artist"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
|
import "git.tebibyte.media/sashakoshka/tomo/artist/shapes"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/core"
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
import "git.tebibyte.media/sashakoshka/tomo/default/config"
|
||||||
|
|
||||||
type ControlState struct {
|
type ControlState struct {
|
||||||
@ -21,10 +22,8 @@ type ControlState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Raycaster struct {
|
type Raycaster struct {
|
||||||
*core.Core
|
entity tomo.FocusableEntity
|
||||||
*core.FocusableCore
|
|
||||||
core core.CoreControl
|
|
||||||
focusableControl core.FocusableCoreControl
|
|
||||||
config config.Wrapped
|
config config.Wrapped
|
||||||
|
|
||||||
Camera
|
Camera
|
||||||
@ -49,31 +48,105 @@ func NewRaycaster (world World, textures Textures) (element *Raycaster) {
|
|||||||
textures: textures,
|
textures: textures,
|
||||||
renderDistance: 8,
|
renderDistance: 8,
|
||||||
}
|
}
|
||||||
element.Core, element.core = core.NewCore(element, element.drawAll)
|
element.entity = tomo.NewEntity(element).(tomo.FocusableEntity)
|
||||||
element.FocusableCore,
|
element.entity.SetMinimumSize(64, 64)
|
||||||
element.focusableControl = core.NewFocusableCore(element.core, element.Draw)
|
|
||||||
element.core.SetMinimumSize(64, 64)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (element *Raycaster) Entity () tomo.Entity {
|
||||||
|
return element.entity
|
||||||
|
}
|
||||||
|
|
||||||
|
func (element *Raycaster) Draw (destination canvas.Canvas) {
|
||||||
|
bounds := element.entity.Bounds()
|
||||||
|
// artist.FillRectangle(element.core, artist.Uhex(0x000000FF), bounds)
|
||||||
|
width := bounds.Dx()
|
||||||
|
height := bounds.Dy()
|
||||||
|
halfway := bounds.Max.Y - height / 2
|
||||||
|
|
||||||
|
ray := Ray { Angle: element.Camera.Angle - element.Camera.Fov / 2 }
|
||||||
|
|
||||||
|
for x := 0; x < width; x ++ {
|
||||||
|
ray.X = element.Camera.X
|
||||||
|
ray.Y = element.Camera.Y
|
||||||
|
|
||||||
|
distance, hitPoint, wall, horizontal := ray.Cast (
|
||||||
|
element.world, element.renderDistance)
|
||||||
|
distance *= math.Cos(ray.Angle - element.Camera.Angle)
|
||||||
|
textureX := math.Mod(hitPoint.X + hitPoint.Y, 1)
|
||||||
|
if textureX < 0 { textureX += 1 }
|
||||||
|
|
||||||
|
wallHeight := height
|
||||||
|
if distance > 0 {
|
||||||
|
wallHeight = int((float64(height) / 2.0) / float64(distance))
|
||||||
|
}
|
||||||
|
|
||||||
|
shade := 1.0
|
||||||
|
if horizontal {
|
||||||
|
shade *= 0.8
|
||||||
|
}
|
||||||
|
shade *= 1 - distance / float64(element.renderDistance)
|
||||||
|
if shade < 0 { shade = 0 }
|
||||||
|
|
||||||
|
ceilingColor := color.RGBA { 0x00, 0x00, 0x00, 0xFF }
|
||||||
|
floorColor := color.RGBA { 0x39, 0x49, 0x25, 0xFF }
|
||||||
|
|
||||||
|
// draw
|
||||||
|
data, stride := destination.Buffer()
|
||||||
|
wallStart := halfway - wallHeight
|
||||||
|
wallEnd := halfway + wallHeight
|
||||||
|
|
||||||
|
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
|
||||||
|
switch {
|
||||||
|
case y < wallStart:
|
||||||
|
data[y * stride + x + bounds.Min.X] = ceilingColor
|
||||||
|
|
||||||
|
case y < wallEnd:
|
||||||
|
textureY :=
|
||||||
|
float64(y - halfway) /
|
||||||
|
float64(wallEnd - wallStart) + 0.5
|
||||||
|
// fmt.Println(textureY)
|
||||||
|
|
||||||
|
wallColor := element.textures.At (wall, Vector {
|
||||||
|
textureX,
|
||||||
|
textureY,
|
||||||
|
})
|
||||||
|
wallColor = shadeColor(wallColor, shade)
|
||||||
|
data[y * stride + x + bounds.Min.X] = wallColor
|
||||||
|
|
||||||
|
default:
|
||||||
|
data[y * stride + x + bounds.Min.X] = floorColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// increment angle
|
||||||
|
ray.Angle += element.Camera.Fov / float64(width)
|
||||||
|
}
|
||||||
|
|
||||||
|
// element.drawMinimap()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (element *Raycaster) Invalidate () {
|
||||||
|
element.entity.Invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
func (element *Raycaster) OnControlStateChange (callback func (ControlState)) {
|
func (element *Raycaster) OnControlStateChange (callback func (ControlState)) {
|
||||||
element.onControlStateChange = callback
|
element.onControlStateChange = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Raycaster) Draw () {
|
func (element *Raycaster) Focus () {
|
||||||
if element.core.HasImage() {
|
element.entity.Focus()
|
||||||
element.drawAll()
|
|
||||||
element.core.DamageAll()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (element *Raycaster) Enabled () bool { return true }
|
||||||
|
|
||||||
|
func (element *Raycaster) HandleFocusChange () { }
|
||||||
|
|
||||||
func (element *Raycaster) HandleMouseDown (x, y int, button input.Button) {
|
func (element *Raycaster) HandleMouseDown (x, y int, button input.Button) {
|
||||||
if !element.Focused() { element.Focus() }
|
element.entity.Focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Raycaster) HandleMouseUp (x, y int, button input.Button) { }
|
func (element *Raycaster) HandleMouseUp (x, y int, button input.Button) { }
|
||||||
func (element *Raycaster) HandleMouseMove (x, y int) { }
|
|
||||||
func (element *Raycaster) HandleMouseScroll (x, y int, deltaX, deltaY float64) { }
|
|
||||||
|
|
||||||
func (element *Raycaster) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
|
func (element *Raycaster) HandleKeyDown (key input.Key, modifiers input.Modifiers) {
|
||||||
switch key {
|
switch key {
|
||||||
@ -109,75 +182,6 @@ func (element *Raycaster) HandleKeyUp(key input.Key, modifiers input.Modifiers)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Raycaster) drawAll () {
|
|
||||||
bounds := element.Bounds()
|
|
||||||
// artist.FillRectangle(element.core, artist.Uhex(0x000000FF), bounds)
|
|
||||||
width := bounds.Dx()
|
|
||||||
height := bounds.Dy()
|
|
||||||
halfway := bounds.Max.Y - height / 2
|
|
||||||
|
|
||||||
ray := Ray { Angle: element.Camera.Angle - element.Camera.Fov / 2 }
|
|
||||||
|
|
||||||
for x := 0; x < width; x ++ {
|
|
||||||
ray.X = element.Camera.X
|
|
||||||
ray.Y = element.Camera.Y
|
|
||||||
|
|
||||||
distance, hitPoint, wall, horizontal := ray.Cast (
|
|
||||||
element.world, element.renderDistance)
|
|
||||||
distance *= math.Cos(ray.Angle - element.Camera.Angle)
|
|
||||||
textureX := math.Mod(hitPoint.X + hitPoint.Y, 1)
|
|
||||||
if textureX < 0 { textureX += 1 }
|
|
||||||
|
|
||||||
wallHeight := height
|
|
||||||
if distance > 0 {
|
|
||||||
wallHeight = int((float64(height) / 2.0) / float64(distance))
|
|
||||||
}
|
|
||||||
|
|
||||||
shade := 1.0
|
|
||||||
if horizontal {
|
|
||||||
shade *= 0.8
|
|
||||||
}
|
|
||||||
shade *= 1 - distance / float64(element.renderDistance)
|
|
||||||
if shade < 0 { shade = 0 }
|
|
||||||
|
|
||||||
ceilingColor := color.RGBA { 0x00, 0x00, 0x00, 0xFF }
|
|
||||||
floorColor := color.RGBA { 0x39, 0x49, 0x25, 0xFF }
|
|
||||||
|
|
||||||
// draw
|
|
||||||
data, stride := element.core.Buffer()
|
|
||||||
wallStart := halfway - wallHeight
|
|
||||||
wallEnd := halfway + wallHeight
|
|
||||||
|
|
||||||
for y := bounds.Min.Y; y < bounds.Max.Y; y ++ {
|
|
||||||
switch {
|
|
||||||
case y < wallStart:
|
|
||||||
data[y * stride + x + bounds.Min.X] = ceilingColor
|
|
||||||
|
|
||||||
case y < wallEnd:
|
|
||||||
textureY :=
|
|
||||||
float64(y - halfway) /
|
|
||||||
float64(wallEnd - wallStart) + 0.5
|
|
||||||
// fmt.Println(textureY)
|
|
||||||
|
|
||||||
wallColor := element.textures.At (wall, Vector {
|
|
||||||
textureX,
|
|
||||||
textureY,
|
|
||||||
})
|
|
||||||
wallColor = shadeColor(wallColor, shade)
|
|
||||||
data[y * stride + x + bounds.Min.X] = wallColor
|
|
||||||
|
|
||||||
default:
|
|
||||||
data[y * stride + x + bounds.Min.X] = floorColor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// increment angle
|
|
||||||
ray.Angle += element.Camera.Fov / float64(width)
|
|
||||||
}
|
|
||||||
|
|
||||||
// element.drawMinimap()
|
|
||||||
}
|
|
||||||
|
|
||||||
func shadeColor (c color.RGBA, brightness float64) color.RGBA {
|
func shadeColor (c color.RGBA, brightness float64) color.RGBA {
|
||||||
return color.RGBA {
|
return color.RGBA {
|
||||||
uint8(float64(c.R) * brightness),
|
uint8(float64(c.R) * brightness),
|
||||||
@ -187,8 +191,8 @@ func shadeColor (c color.RGBA, brightness float64) color.RGBA {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (element *Raycaster) drawMinimap () {
|
func (element *Raycaster) drawMinimap (destination canvas.Canvas) {
|
||||||
bounds := element.Bounds()
|
bounds := element.entity.Bounds()
|
||||||
scale := 8
|
scale := 8
|
||||||
for y := 0; y < len(element.world.Data) / element.world.Stride; y ++ {
|
for y := 0; y < len(element.world.Data) / element.world.Stride; y ++ {
|
||||||
for x := 0; x < element.world.Stride; x ++ {
|
for x := 0; x < element.world.Stride; x ++ {
|
||||||
@ -204,7 +208,7 @@ func (element *Raycaster) drawMinimap () {
|
|||||||
cellColor = color.RGBA { 0xFF, 0xFF, 0xFF, 0xFF }
|
cellColor = color.RGBA { 0xFF, 0xFF, 0xFF, 0xFF }
|
||||||
}
|
}
|
||||||
shapes.FillColorRectangle (
|
shapes.FillColorRectangle (
|
||||||
element.core,
|
destination,
|
||||||
cellColor,
|
cellColor,
|
||||||
cellBounds.Inset(1))
|
cellBounds.Inset(1))
|
||||||
}}
|
}}
|
||||||
@ -219,16 +223,16 @@ func (element *Raycaster) drawMinimap () {
|
|||||||
|
|
||||||
playerBounds := image.Rectangle { playerPt, playerPt }.Inset(scale / -8)
|
playerBounds := image.Rectangle { playerPt, playerPt }.Inset(scale / -8)
|
||||||
shapes.FillColorEllipse (
|
shapes.FillColorEllipse (
|
||||||
element.core,
|
destination,
|
||||||
artist.Hex(0xFFFFFFFF),
|
artist.Hex(0xFFFFFFFF),
|
||||||
playerBounds)
|
playerBounds)
|
||||||
shapes.ColorLine (
|
shapes.ColorLine (
|
||||||
element.core,
|
destination,
|
||||||
artist.Hex(0xFFFFFFFF), 1,
|
artist.Hex(0xFFFFFFFF), 1,
|
||||||
playerPt,
|
playerPt,
|
||||||
playerAnglePt)
|
playerAnglePt)
|
||||||
shapes.ColorLine (
|
shapes.ColorLine (
|
||||||
element.core,
|
destination,
|
||||||
artist.Hex(0x00FF00FF), 1,
|
artist.Hex(0x00FF00FF), 1,
|
||||||
playerPt,
|
playerPt,
|
||||||
hitPt)
|
hitPt)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -14,7 +13,7 @@ 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 := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt (elements.NewLabel("This is at the top", false), false)
|
container.Adopt (elements.NewLabel("This is at the top", false), false)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
import "git.tebibyte.media/sashakoshka/tomo"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/layouts"
|
|
||||||
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"
|
import "git.tebibyte.media/sashakoshka/tomo/elements/containers"
|
||||||
@ -14,7 +13,7 @@ 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 := containers.NewContainer(layouts.Vertical { true, true })
|
container := containers.NewVBox(true, true)
|
||||||
window.Adopt(container)
|
window.Adopt(container)
|
||||||
|
|
||||||
container.Adopt(elements.NewSwitch("hahahah", false), false)
|
container.Adopt(elements.NewSwitch("hahahah", false), false)
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo"
|
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/elements/testing"
|
|
||||||
import _ "git.tebibyte.media/sashakoshka/tomo/backends/all"
|
|
||||||
|
|
||||||
func main () {
|
|
||||||
tomo.Run(run)
|
|
||||||
}
|
|
||||||
|
|
||||||
func run () {
|
|
||||||
window, _ := tomo.NewWindow(tomo.Bounds(0, 0, 128, 128))
|
|
||||||
window.SetTitle("hellorld!")
|
|
||||||
window.Adopt(testing.NewMouse())
|
|
||||||
window.OnClose(tomo.Stop)
|
|
||||||
window.Show()
|
|
||||||
}
|
|
@ -60,6 +60,10 @@ func NewDialog (
|
|||||||
messageRow.Adopt(elements.NewLabel(message, false), true)
|
messageRow.Adopt(elements.NewLabel(message, false), true)
|
||||||
|
|
||||||
controlRow.Adopt(elements.NewSpacer(false), true)
|
controlRow.Adopt(elements.NewSpacer(false), true)
|
||||||
|
box.Adopt(messageRow, true)
|
||||||
|
box.Adopt(controlRow, false)
|
||||||
|
window.Adopt(box)
|
||||||
|
|
||||||
if len(buttons) == 0 {
|
if len(buttons) == 0 {
|
||||||
button := elements.NewButton("OK")
|
button := elements.NewButton("OK")
|
||||||
button.SetIcon(tomo.IconYes)
|
button.SetIcon(tomo.IconYes)
|
||||||
@ -80,9 +84,6 @@ func NewDialog (
|
|||||||
button.Focus()
|
button.Focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
box.Adopt(messageRow, true)
|
|
||||||
box.Adopt(controlRow, false)
|
|
||||||
window.Adopt(box)
|
|
||||||
window.Show()
|
window.Show()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user