type value any

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-11 17:19:47 -06:00
parent 4bf3307671
commit c4582b0b30
22 changed files with 96 additions and 127 deletions

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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()

View File

@ -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

View File

@ -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()
})

View File

@ -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()
})

View File

@ -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++ {

View File

@ -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) {

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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()
})

View File

@ -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()
})

View File

@ -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))
}
}

View File

@ -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()
})
}

View File

@ -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
}

View File

@ -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)

View File

@ -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 ""
}