DEMO: change the toolkit demo to not use 'tabs'

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2022-10-17 15:02:13 -05:00
parent 2c8031b849
commit f079de80b6
2 changed files with 140 additions and 9 deletions

126
toolkit/andlabs/demo.go Normal file
View File

@ -0,0 +1,126 @@
package toolkit
import "log"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew"
func BlankWindow(w *ui.Window) *ui.Box {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
w.SetChild(hbox)
return hbox
}
func DemoNumbersPage(w *ui.Window) *Toolkit {
var t Toolkit
t.uiBox = makeNumbersPage()
t.uiBox.SetPadded(true)
w.SetChild(t.uiBox)
if (DebugToolkit) {
log.Println("gui.Toolbox.DemoNumbersPage()")
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
return &t
}
/*
func Demo(b *ui.Box) *Toolkit {
x := 22
y := 33
// make new node here
log.Println("gui.Toolbox.NewSpinbox()", x, y)
var t Toolkit
if (b == nil) {
log.Println("gui.ToolboxNode.NewSpinbox() node.UiBox == nil. I can't add a range UI element without a place to put it")
return nil
}
s := ui.NewSlider(x, y)
t.uiSlider = s
t.uiBox = b
t.uiBox.Append(s, false)
s.OnChanged(func(spin *ui.Slider) {
i := spin.Value()
if (DebugToolkit) {
log.Println("gui.Toolbox.ui.OnChanged() val =", i)
scs := spew.ConfigState{MaxDepth: 1}
scs.Dump(t)
}
if (t.OnChanged != nil) {
log.Println("gui.Toolbox.OnChanged() entered val =", i)
t.OnChanged(&t)
}
})
return &t
}
*/
func makeNumbersPage() *ui.Box {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
group := ui.NewGroup("Numbers")
group.SetMargined(true)
hbox.Append(group, true)
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
spinbox := ui.NewSpinbox(0, 100)
slider := ui.NewSlider(0, 100)
pbar := ui.NewProgressBar()
spinbox.OnChanged(func(*ui.Spinbox) {
slider.SetValue(spinbox.Value())
pbar.SetValue(spinbox.Value())
})
slider.OnChanged(func(*ui.Slider) {
spinbox.SetValue(slider.Value())
pbar.SetValue(slider.Value())
})
vbox.Append(spinbox, false)
vbox.Append(slider, false)
vbox.Append(pbar, false)
ip := ui.NewProgressBar()
ip.SetValue(-1)
vbox.Append(ip, false)
group = ui.NewGroup("Lists")
group.SetMargined(true)
hbox.Append(group, true)
vbox = ui.NewVerticalBox()
vbox.SetPadded(true)
group.SetChild(vbox)
cbox := ui.NewCombobox()
cbox.Append("Combobox Item 1")
cbox.Append("Combobox Item 2")
cbox.Append("Combobox Item 3")
vbox.Append(cbox, false)
ecbox := ui.NewEditableCombobox()
ecbox.Append("Editable Item 1")
ecbox.Append("Editable Item 2")
ecbox.Append("Editable Item 3")
vbox.Append(ecbox, false)
rb := ui.NewRadioButtons()
rb.Append("Radio Button 1")
rb.Append("Radio Button 2")
rb.Append("Radio Button 3")
vbox.Append(rb, false)
return hbox
}

View File

@ -1,7 +1,8 @@
package gui package gui
import "log" import "log"
import "time" // import "time"
import toolkit "git.wit.org/wit/gui/toolkit/andlabs"
func NewStandardWindow(title string) *Node { func NewStandardWindow(title string) *Node {
log.Println("NewStandardWindow() creating", title) log.Println("NewStandardWindow() creating", title)
@ -13,19 +14,23 @@ func NewStandardWindow(title string) *Node {
return NewWindow() return NewWindow()
} }
func ToolkitDemoWindow() { func ToolkitDemoWindow() {
var w, t, g *Node var w, d *Node
var tk *toolkit.Toolkit
w = NewStandardWindow("Demo the GUI Toolkit") w = NewStandardWindow("Demo the GUI Toolkit")
// w.DemoAndlabsUiTab("ran AddDemoAndlabsUiTab()") d = w.makeNode("demo", 767, 676 + Config.counter)
t = w.AddTab("Set time delay", nil) d.Name = "demo"
g = t.AddGroup("nanoseconds")
s := g.NewSlider("t", 2, 80) tk = toolkit.DemoNumbersPage(w.uiWindow)
s.OnChanged = func (td *Node) { tk.OnChanged = func(t *toolkit.Toolkit) {
t := time.Duration(s.Int()) log.Println("toolkit.NewSlider() value =", t.Value())
log.Println("ToolkitDemoWindow() OnChanged() delay =", t); if (d.OnChanged != nil) {
log.Println("toolkit.Demo() running node.OnChanged")
d.OnChanged(d)
}
} }
d.Toolkit = tk
log.Println("ToolkitDemoWindow() END") log.Println("ToolkitDemoWindow() END")
} }