summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/spinbox.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2022-10-16 08:07:13 -0500
committerJeff Carr <[email protected]>2022-10-16 08:07:13 -0500
commit2141e04328dcf4e4d6857fcc0a7cb551fc84fa07 (patch)
treef8b2a5d8cf17f9ccfcfa8c1699fe4a52ea8338e2 /toolkit/andlabs/spinbox.go
parent3c899365154e48aefbc0b5ee48cd089f49339cb2 (diff)
Add slander and spinbox in toolkit/andlabs
fix the helloworld demo move slider into toolkit/ move more into the toolkit directory add spinbox() fix example minor update fix examples Fix andlabs.ui.Slider() to work again correctly implement custom OnChange() callback Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/andlabs/spinbox.go')
-rw-r--r--toolkit/andlabs/spinbox.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/toolkit/andlabs/spinbox.go b/toolkit/andlabs/spinbox.go
new file mode 100644
index 0000000..dca0502
--- /dev/null
+++ b/toolkit/andlabs/spinbox.go
@@ -0,0 +1,86 @@
+package toolkit
+
+import "log"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+
+import "github.com/davecgh/go-spew/spew"
+
+var DebugToolkit bool = false
+
+// stores the raw toolkit internals
+type Toolkit struct {
+ id string
+
+ Name string
+ Width int
+ Height int
+
+ OnChanged func(*Toolkit)
+
+ uiControl *ui.Control
+ uiButton *ui.Button
+ uiSlider *ui.Slider
+ uiSpinbox *ui.Spinbox
+ uiWindow *ui.Window
+ uiTab *ui.Tab
+ uiBox *ui.Box
+ uiText *ui.EditableCombobox
+}
+
+func (t *Toolkit) Value() int {
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.Value() Enter")
+ scs := spew.ConfigState{MaxDepth: 1}
+ scs.Dump(t)
+ }
+ if (t == nil) {
+ log.Println("gui.Toolkit.Value() can not get value t == nil")
+ return 0
+ }
+ if (t.uiSlider != nil) {
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.Value() =", t.uiSlider.Value)
+ }
+ return t.uiSlider.Value()
+ }
+ if (t.uiSpinbox != nil) {
+ if (DebugToolkit) {
+ log.Println("gui.Toolkit.Value() =", t.uiSpinbox.Value)
+ }
+ return t.uiSpinbox.Value()
+ }
+ log.Println("gui.Toolkit.Value() Could not find a ui element to get a value from")
+ return 0
+}
+
+func NewSpinbox(b *ui.Box, name string, x int, y int) *Toolkit {
+ // 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 &t
+ }
+ spin := ui.NewSpinbox(x, y)
+ t.uiSpinbox = spin
+ t.uiBox = b
+ t.uiBox.Append(spin, false)
+
+ spin.OnChanged(func(spin *ui.Spinbox) {
+ 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
+}