From c4582b0b30e3020a92baf299572d8617872d45e5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 11 Jan 2024 17:19:47 -0600 Subject: [PATCH] type value any Signed-off-by: Jeff Carr --- andlabs/action.go | 15 +++------- andlabs/add.go | 10 +------ andlabs/addText.go | 13 ++++----- andlabs/box.go | 6 ++-- andlabs/button.go | 2 +- andlabs/checkbox.go | 4 +-- andlabs/combobox.go | 2 +- andlabs/debug.go | 2 +- andlabs/delete.go | 6 ++-- andlabs/dropdown.go | 10 +++---- andlabs/group.go | 2 +- andlabs/label.go | 2 +- andlabs/main.go | 2 +- andlabs/place.go | 14 +++++----- andlabs/setText.go | 39 +++----------------------- andlabs/slider.go | 2 +- andlabs/spinner.go | 2 +- andlabs/tab.go | 4 +-- andlabs/textbox.go | 4 +-- andlabs/widget.go | 10 ------- andlabs/window.go | 5 ++-- nocui/common.go | 67 +++++++++++++++++++++++++++++++-------------- 22 files changed, 96 insertions(+), 127 deletions(-) diff --git a/andlabs/action.go b/andlabs/action.go index 35f4f7b..e0cdcff 100644 --- a/andlabs/action.go +++ b/andlabs/action.go @@ -130,12 +130,6 @@ func (n *node) move(newParent *node) { if (p.tk.uiBox != nil) { p.tk.uiBox.Append(n.tk.uiControl, stretchy) } - // log.Log(NOW, "is there a tParent parent? =", tParent.parent) - // tParent.uiBox.Delete(0) - - // this didn't work: - // tWidget.uiControl.Disable() - // sleep(.8) default: log.Log(ERROR, "TODO: need to implement move() for type =", n.WidgetType) log.Log(ERROR, "TODO: need to implement move() for where =", p.ParentId) @@ -157,7 +151,7 @@ func (n *node) Delete() { case widget.Grid: // t.uiGrid.SetPadded(true) case widget.Box: - log.Log(NOW, "tWidget.boxC =", p.Name) + log.Log(NOW, "tWidget.boxC =", p.progname) log.Log(NOW, "is there a tParent parent? =", p.parent) if (p.tk.boxC < 1) { log.Log(NOW, "Can not delete from Box. already empty. tWidget.boxC =", p.tk.boxC) @@ -177,8 +171,7 @@ func (n *node) Delete() { } func rawAction(a *widget.Action) { - log.Log(INFO, "rawAction() START a.ActionType =", a.ActionType) - log.Log(INFO, "rawAction() START a.S =", a.S) + log.Log(INFO, "rawAction() START a.ActionType =", a.ActionType, "a.Value", a.Value) if (a.ActionType == widget.InitToolkit) { // TODO: make sure to only do this once @@ -209,7 +202,7 @@ func rawAction(a *widget.Action) { } if (a.ActionType == widget.Dump) { - log.Log(NOW, "rawAction() Dump =", a.ActionType, a.WidgetType, n.Name) + log.Log(NOW, "rawAction() Dump =", a.ActionType, a.WidgetType, n.progname) me.rootNode.listChildren(true) return } @@ -238,7 +231,7 @@ func rawAction(a *widget.Action) { case widget.GetText: switch a.WidgetType { case widget.Textbox: - a.S = n.S + a.Value = n.value } case widget.Set: n.setText(a) diff --git a/andlabs/add.go b/andlabs/add.go index c09ddf1..ffe2cc4 100644 --- a/andlabs/add.go +++ b/andlabs/add.go @@ -5,14 +5,6 @@ import ( "go.wit.com/gui/widget" ) -func actionDump(b bool, a *widget.Action) { - log.Log(NOW, "actionDump() Widget.Type =", a.ActionType) - log.Log(NOW, "actionDump() Widget.S =", a.S) - log.Log(NOW, "actionDump() Widget.I =", a.I) - log.Log(NOW, "actionDump() WidgetId =", a.WidgetId) - log.Log(NOW, "actionDump() ParentId =", a.ParentId) -} - func add(a *widget.Action) { if (a.WidgetType == widget.Root) { me.rootNode = addNode(a) @@ -65,6 +57,6 @@ func add(a *widget.Action) { p.newImage(n) return default: - log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.Name) + log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.progname) } } diff --git a/andlabs/addText.go b/andlabs/addText.go index 291dca3..74249a4 100644 --- a/andlabs/addText.go +++ b/andlabs/addText.go @@ -6,22 +6,21 @@ import ( ) func (n *node) addText(a *widget.Action) { - log.Log(CHANGE, "addText() START with a.S =", a.S) + log.Log(CHANGE, "addText() START with a.Value =", a.Value) t := n.tk if (t == nil) { - log.Log(ERROR, "addText error. tk == nil", n.Name, n.WidgetId) - actionDump(debugError, a) + log.Log(ERROR, "addText error. tk == nil", n.progname, n.WidgetId) return } - log.Log(CHANGE, "addText() Attempt on", n.WidgetType, "with", a.S) + log.Log(CHANGE, "addText() Attempt on", n.WidgetType, "with", a.Value) switch n.WidgetType { case widget.Dropdown: - n.AddDropdownName(a.S) + n.AddDropdownName(getString(a.Value)) case widget.Combobox: - t.AddComboboxName(a.S) + t.AddComboboxName(getString(a.Value)) default: log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType) } - log.Log(CHANGE, "addText() END with a.S =", a.S) + log.Log(CHANGE, "addText() END with a.Value =", a.Value) } diff --git a/andlabs/box.go b/andlabs/box.go index 93a4fef..290c06b 100644 --- a/andlabs/box.go +++ b/andlabs/box.go @@ -1,6 +1,8 @@ package main import ( + "go.wit.com/gui/widget" + "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" ) @@ -10,7 +12,7 @@ func (p *node) newBox(n *node) { newt := new(guiWidget) var box *ui.Box - if (n.horizontal) { + if n.direction == widget.Horizontal { box = ui.NewHorizontalBox() } else { box = ui.NewVerticalBox() @@ -47,7 +49,7 @@ func (p *node) newBox(n *node) { func (n *node) rawBox() *ui.Box { var box *ui.Box - if (n.horizontal) { + if n.direction == widget.Horizontal { box = ui.NewHorizontalBox() } else { box = ui.NewVerticalBox() diff --git a/andlabs/button.go b/andlabs/button.go index 0dcb0e5..675fad5 100644 --- a/andlabs/button.go +++ b/andlabs/button.go @@ -9,7 +9,7 @@ func (p *node) newButton(n *node) { t := p.tk newt := new(guiWidget) - b := ui.NewButton(n.Text) + b := ui.NewButton(getString(n.value)) newt.uiButton = b newt.uiControl = b newt.parent = t diff --git a/andlabs/checkbox.go b/andlabs/checkbox.go index a5ea3bc..49f9045 100644 --- a/andlabs/checkbox.go +++ b/andlabs/checkbox.go @@ -8,11 +8,11 @@ import ( func (p *node) newCheckbox(n *node) { newt := new(guiWidget) - newt.uiCheckbox = ui.NewCheckbox(n.Text) + newt.uiCheckbox = ui.NewCheckbox(n.label) newt.uiControl = newt.uiCheckbox newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { - n.B = newt.checked() + n.value = newt.checked() n.doUserEvent() }) diff --git a/andlabs/combobox.go b/andlabs/combobox.go index 6339f62..cc3603e 100644 --- a/andlabs/combobox.go +++ b/andlabs/combobox.go @@ -19,7 +19,7 @@ func (p *node) newCombobox(n *node) { newt.val = make(map[int]string) cb.OnChanged(func(spin *ui.EditableCombobox) { - n.A = spin.Text() + n.value = spin.Text() log.Warn("combobox changed =" + spin.Text() + ".") n.doUserEvent() }) diff --git a/andlabs/debug.go b/andlabs/debug.go index 96640a4..7e6bb24 100644 --- a/andlabs/debug.go +++ b/andlabs/debug.go @@ -94,7 +94,7 @@ func (n *node) dumpWidget(b bool) { } info = n.WidgetType.String() - d = strconv.Itoa(n.WidgetId) + " " + info + " " + n.Name + d = strconv.Itoa(n.WidgetId) + " " + info + " " + n.progname var tabs string for i := 0; i < listChildrenDepth; i++ { diff --git a/andlabs/delete.go b/andlabs/delete.go index a2c50ae..d528b66 100644 --- a/andlabs/delete.go +++ b/andlabs/delete.go @@ -25,7 +25,7 @@ func (n *node) destroy() { switch n.WidgetType { case widget.Button: - log.Log(NOW, "Should delete Button here:", n.Name) + log.Log(NOW, "Should delete Button here:", n.progname) log.Log(NOW, "Parent:") pt.Dump(true) log.Log(NOW, "Child:") @@ -33,7 +33,7 @@ func (n *node) destroy() { if (pt.uiBox == nil) { log.Log(NOW, "Don't know how to destroy this") } else { - log.Log(NOW, "Fuck it, destroy the whole box", n.parent.Name) + log.Log(NOW, "Fuck it, destroy the whole box", n.parent.progname) // pt.uiBox.Destroy() // You have a bug: You cannot destroy a uiControl while it still has a parent. pt.uiBox.SetPadded(false) pt.uiBox.Delete(4) @@ -43,7 +43,7 @@ func (n *node) destroy() { } case widget.Window: - log.Log(NOW, "Should delete Window here:", n.Name) + log.Log(NOW, "Should delete Window here:", n.progname) default: log.Log(NOW, "Fuckit, let's destroy a button") if (ct.uiButton != nil) { diff --git a/andlabs/dropdown.go b/andlabs/dropdown.go index ff83ac2..d2c493b 100644 --- a/andlabs/dropdown.go +++ b/andlabs/dropdown.go @@ -10,7 +10,7 @@ import ( func (p *node) newDropdown(n *node) { newt := new(guiWidget) - log.Log(INFO, "gui.Toolbox.newDropdown() START", n.Name) + log.Log(INFO, "gui.Toolbox.newDropdown() START", n.progname) cb := ui.NewCombobox() newt.uiCombobox = cb @@ -24,9 +24,9 @@ func (p *node) newDropdown(n *node) { i := spin.Selected() if (newt.val == nil) { log.Log(ERROR, "make map didn't work") - n.S = "map did not work. ui.Combobox error" + n.value = "map did not work. ui.Combobox error" } else { - n.S = newt.val[i] + n.value = newt.val[i] } n.doUserEvent() }) @@ -60,7 +60,7 @@ func (n *node) AddDropdownName(s string) { t := n.tk if (t == nil) { - log.Log(INFO, "AddDropdownName() toolkit struct == nil. name=", n.Name, s) + log.Log(INFO, "AddDropdownName() toolkit struct == nil. name=", n.progname, s) return } t.addDropdownName(s) @@ -76,5 +76,5 @@ func (n *node) SetDropdownName(a *widget.Action, s string) { } t.SetDropdown(1) // TODO: send back to wit/gui goroutine with the chan - n.S = s + n.value = s } diff --git a/andlabs/group.go b/andlabs/group.go index 768d03a..8555d07 100644 --- a/andlabs/group.go +++ b/andlabs/group.go @@ -8,7 +8,7 @@ import ( func (p *node) newGroup(n *node) { newt := new(guiWidget) - g := ui.NewGroup(n.Name) + g := ui.NewGroup(getString(n.value)) g.SetMargined(margin) newt.uiGroup = g newt.uiControl = g diff --git a/andlabs/label.go b/andlabs/label.go index 51537a1..4199059 100644 --- a/andlabs/label.go +++ b/andlabs/label.go @@ -7,7 +7,7 @@ import ( func (p *node) newLabel(n *node) { newt := new(guiWidget) - c := ui.NewLabel(n.Name) + c := ui.NewLabel(getString(n.value)) newt.uiLabel = c newt.uiControl = c diff --git a/andlabs/main.go b/andlabs/main.go index c735aea..ac52a5c 100644 --- a/andlabs/main.go +++ b/andlabs/main.go @@ -20,7 +20,7 @@ func catchActionChannel() { log.Log(INFO, "catchActionChannel() for loop") select { case a := <-pluginChan: - log.Log(INFO, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name) + log.Log(INFO, "catchActionChannel() SELECT widget id =", a.WidgetId, a.ProgName) log.Log(INFO, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType) muAction.Lock() // TODO ui.QueueMain(f) diff --git a/andlabs/place.go b/andlabs/place.go index 59a55d9..2658f99 100644 --- a/andlabs/place.go +++ b/andlabs/place.go @@ -34,11 +34,11 @@ import ( // -- (0,1) -- (1,1) -- (1,1) -- // ----------------------------- func (p *node) place(n *node) bool { - log.Log(INFO, "place() START", n.WidgetType, n.Name) + log.Log(INFO, "place() START", n.WidgetType, n.progname) if (p.tk == nil) { - log.Log(ERROR, "p.tk == nil", p.Name, p.ParentId, p.WidgetType, p.tk) - log.Log(ERROR, "n = ", n.Name, n.ParentId, n.WidgetType, n.tk) + log.Log(ERROR, "p.tk == nil", p.progname, p.ParentId, p.WidgetType, p.tk) + log.Log(ERROR, "n = ", n.progname, n.ParentId, n.WidgetType, n.tk) panic("p.tk == nil") } @@ -56,7 +56,7 @@ func (p *node) place(n *node) bool { return true case widget.Group: if (p.tk.uiBox == nil) { - log.Log(WARN, "place() andlabs hack group to use add a box", n.Name, n.WidgetType, "horizontal =", n.horizontal) + log.Log(WARN, "place() andlabs hack group to use add a box", n.progname, n.WidgetType) p.tk.uiBox = n.rawBox() p.tk.uiGroup.SetChild(p.tk.uiBox) } @@ -72,10 +72,10 @@ func (p *node) place(n *node) bool { panic("n.tk.uiControl == nil") } log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab") - // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.Name, n.Text, n.WidgetType) - // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.Name, p.Text, p.WidgetType) + // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.progname, n.Text, n.WidgetType) + // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.progname, p.Text, p.WidgetType) // panic("n.tk.uiControl == nil") - p.tk.uiTab.Append(n.Text, n.tk.uiControl) + p.tk.uiTab.Append(getString(n.value), n.tk.uiControl) p.tk.boxC += 1 return true case widget.Box: diff --git a/andlabs/setText.go b/andlabs/setText.go index 9aabd99..88b4df0 100644 --- a/andlabs/setText.go +++ b/andlabs/setText.go @@ -1,48 +1,17 @@ package main import ( - "reflect" - "strconv" - "go.wit.com/log" "go.wit.com/gui/widget" ) func (n *node) setText(a *widget.Action) { - var name string - var A any - var k reflect.Kind - A = a.A - if a.A == nil { - log.Warn("setText a.A == nil") - A = "" - } - - k = reflect.TypeOf(A).Kind() - - switch k { - case reflect.Int: - var i int - i = A.(int) - name = strconv.Itoa(i) - case reflect.String: - name = A.(string) - case reflect.Bool: - if A.(bool) == true { - name = "true" - } else { - name = "false" - } - default: - log.Warn("setText uknown kind", k, "value =", A) - name = "" - } + name := getString(a.Value) log.Log(CHANGE, "setText() START with text =", name) t := n.tk if (t == nil) { - log.Log(ERROR, "setText error. tk == nil", n.Name, n.WidgetId) - actionDump(debugError, a) + log.Log(ERROR, "setText error. tk == nil", n.progname, n.WidgetId) return } log.Log(CHANGE, "setText() Attempt on", n.WidgetType, "with", name) @@ -68,9 +37,9 @@ func (n *node) setText(a *widget.Action) { case widget.Button: t.uiButton.SetText(name) case widget.Slider: - log.Log(ERROR, "setText() on slider unknown", a.ActionType, "on checkbox", n.Name) + log.Log(ERROR, "setText() on slider unknown", a.ActionType, "on checkbox", n.progname) case widget.Spinner: - log.Log(ERROR, "setText() on spinner unknown", a.ActionType, "on checkbox", n.Name) + log.Log(ERROR, "setText() on spinner unknown", a.ActionType, "on checkbox", n.progname) case widget.Dropdown: var orig int var i int = -1 diff --git a/andlabs/slider.go b/andlabs/slider.go index 5098943..532f437 100644 --- a/andlabs/slider.go +++ b/andlabs/slider.go @@ -13,7 +13,7 @@ func (p *node) newSlider(n *node) { newt.uiControl = s s.OnChanged(func(spin *ui.Slider) { - n.I = newt.uiSlider.Value() + n.value = newt.uiSlider.Value() n.doUserEvent() }) diff --git a/andlabs/spinner.go b/andlabs/spinner.go index bab7a29..6b4fec1 100644 --- a/andlabs/spinner.go +++ b/andlabs/spinner.go @@ -13,7 +13,7 @@ func (p *node) newSpinner(n *node) { newt.uiControl = s s.OnChanged(func(s *ui.Spinbox) { - n.I = newt.uiSpinbox.Value() + n.value = newt.uiSpinbox.Value() n.doUserEvent() }) diff --git a/andlabs/tab.go b/andlabs/tab.go index 77e8443..232b8e8 100644 --- a/andlabs/tab.go +++ b/andlabs/tab.go @@ -37,7 +37,7 @@ func (p *node) newTab(n *node) { if (t.uiTab == nil) { // this means you have to make a new tab log.Log(TOOLKIT, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId) - newt = rawTab(t.uiWindow, n.Text) + newt = rawTab(t.uiWindow, getString(n.value)) t.uiTab = newt.uiTab } else { // this means you have to append a tab @@ -49,7 +49,7 @@ func (p *node) newTab(n *node) { newt.uiWindow = t.uiWindow newt.uiTab = t.uiTab } else { - newt = t.appendTab(n.Text) + newt = t.appendTab(getString(n.value)) } } diff --git a/andlabs/textbox.go b/andlabs/textbox.go index 7cb5d63..d766b45 100644 --- a/andlabs/textbox.go +++ b/andlabs/textbox.go @@ -14,7 +14,7 @@ func (p *node) newTextbox(n *node) { newt.uiControl = e e.OnChanged(func(spin *ui.Entry) { - n.S = spin.Text() + n.value = spin.Text() n.doUserEvent() }) } else { @@ -23,7 +23,7 @@ func (p *node) newTextbox(n *node) { newt.uiControl = e e.OnChanged(func(spin *ui.MultilineEntry) { - n.S = spin.Text() + n.value = spin.Text() n.doUserEvent() }) } diff --git a/andlabs/widget.go b/andlabs/widget.go index a96eb02..414ca3d 100644 --- a/andlabs/widget.go +++ b/andlabs/widget.go @@ -8,21 +8,11 @@ import ( func initWidget(n *node) *guiWidget { var w *guiWidget w = new(guiWidget) - // Set(w, "default") if n.WidgetType == widget.Root { n.WidgetId = 0 me.rootNode = n return w } - - if (n.WidgetType == widget.Box) { - if (n.B) { - n.horizontal = true - } else { - n.horizontal = false - } - } - return w } diff --git a/andlabs/window.go b/andlabs/window.go index 68fe921..d9dd106 100644 --- a/andlabs/window.go +++ b/andlabs/window.go @@ -17,11 +17,10 @@ func (t *guiWidget) ErrorWindow(msg1 string, msg2 string) { func newWindow(n *node) { var newt *guiWidget - newt = new(guiWidget) // menubar bool is if the OS defined border on the window should be used - win := ui.NewWindow(n.Name, n.X, n.Y, menubar) + win := ui.NewWindow(n.progname, n.X, n.Y, menubar) win.SetBorderless(canvas) win.SetMargined(margin) win.OnClosing(func(*ui.Window) bool { @@ -38,7 +37,7 @@ func newWindow(n *node) { } func (n *node) SetWindowTitle(title string) { - log.Log(CHANGE, "toolkit NewWindow", n.Text, "title", title) + log.Log(CHANGE, "toolkit NewWindow", getString(n.value), "title", title) win := n.tk.uiWindow if (win == nil) { log.Log(ERROR, "Error: no window", n.WidgetId) diff --git a/nocui/common.go b/nocui/common.go index bfb76c8..cd5b7f1 100644 --- a/nocui/common.go +++ b/nocui/common.go @@ -12,6 +12,9 @@ package main */ import ( + "reflect" + "strconv" + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -31,16 +34,19 @@ type node struct { WidgetType widget.WidgetType ParentId int // parent ID - Name string - Text string + // Name string + // Text string + + progname string + label string + + // horizontal means layout widgets like books on a bookshelf + // vertical means layout widgets like books in a stack + direction widget.Orientation // This is how the values are passed back and forth // values from things like checkboxes & dropdown's - B bool - I int - S string - - A any // switch to this or deprecate this? pros/cons? + value any // This is used for things like a slider(0,100) X int @@ -54,9 +60,7 @@ type node struct { vals []string // dropdown menu items - // horizontal=true means layout widgets like books on a bookshelf - // horizontal=false means layout widgets like books in a stack - horizontal bool `default:false` + // horizontal bool `default:false` hasTabs bool // does the window have tabs? currentTab bool // the visible tab @@ -93,12 +97,7 @@ func (n *node) doUserEvent() { } var a widget.Action a.WidgetId = n.WidgetId - a.Name = n.Name - a.Text = n.Text - a.S = n.S - a.I = n.I - a.B = n.B - a.A = n.A + a.Value = n.value a.ActionType = widget.User log.Log(INFO, "doUserEvent() START: send a user event to the callback channel") callback <- a @@ -113,11 +112,9 @@ func addNode(a *widget.Action) *node { n.ParentId = a.ParentId // copy the data from the action message - n.Name = a.Name - n.Text = a.Text - n.I = a.I - n.S = a.S - n.B = a.B + n.progname = a.ProgName + n.value = a.Value + n.direction = a.Direction n.X = a.X n.Y = a.Y @@ -166,3 +163,31 @@ func Callback(guiCallback chan widget.Action) { func PluginChannel() chan widget.Action { return pluginChan } + +func getString(A any) string { + if A == nil { + log.Warn("getString() got nil") + return "" + } + var k reflect.Kind + k = reflect.TypeOf(A).Kind() + + switch k { + case reflect.Int: + var i int + i = A.(int) + return strconv.Itoa(i) + case reflect.String: + return A.(string) + case reflect.Bool: + if A.(bool) == true { + return "true" + } else { + return "false" + } + default: + log.Warn("getString uknown kind", k, "value =", A) + return "" + } + return "" +}