diff options
Diffstat (limited to 'toolkit')
29 files changed, 1069 insertions, 1041 deletions
diff --git a/toolkit/andlabs/action.go b/toolkit/andlabs/action.go new file mode 100644 index 0000000..3272414 --- /dev/null +++ b/toolkit/andlabs/action.go @@ -0,0 +1,253 @@ +package main + +import ( + "git.wit.org/wit/gui/toolkit" +) + +func show(w *toolkit.Widget) { + if (w == nil) { + log(debugError, "nil is probably already hidden") + return + } + log(debugError, "show()", w.Name) + + t := mapToolkits[w] + if (t == nil) { + log(debugToolkit, "show() toolkit struct == nil. for", w.Name) + return + } + + if (w.B) { + t.uiControl.Show() + } else { + t.uiControl.Hide() + } +} + +func enable(w *toolkit.Widget) { + if (w == nil) { + log(debugError, "nil is probably already hidden") + return + } + log(debugError, "enable()", w.Name) + + t := mapToolkits[w] + if (t == nil) { + log(debugToolkit, "enable() toolkit struct == nil. for", w.Name) + return + } + + if (w.B) { + t.uiControl.Enable() + } else { + t.uiControl.Disable() + } +} + +func pad(a *toolkit.Action) { + if (a.Widget == nil) { + log(debugError, "pad() ERROR: nil is probably already hidden") + return + } + log(debugError, "pad()", a.Widget.Name) + + t := mapToolkits[a.Widget] + if (t == nil) { + log(debugToolkit, "pad() toolkit struct == nil. for", a.Widget.Name) + return + } + + switch a.Widget.Type { + case toolkit.Group: + switch a.Type { + case toolkit.Margin: + t.uiGroup.SetMargined(true) + case toolkit.Unmargin: + t.uiGroup.SetMargined(false) + case toolkit.Pad: + t.uiGroup.SetMargined(true) + case toolkit.Unpad: + t.uiGroup.SetMargined(false) + } + case toolkit.Tab: + switch a.Type { + case toolkit.Margin: + tabSetMargined(t.uiTab, true) + case toolkit.Unmargin: + tabSetMargined(t.uiTab, false) + case toolkit.Pad: + tabSetMargined(t.uiTab, true) + case toolkit.Unpad: + tabSetMargined(t.uiTab, false) + } + case toolkit.Window: + switch a.Type { + case toolkit.Margin: + t.uiWindow.SetMargined(true) + case toolkit.Unmargin: + t.uiWindow.SetMargined(false) + case toolkit.Pad: + t.uiWindow.SetBorderless(false) + case toolkit.Unpad: + t.uiWindow.SetBorderless(true) + } + case toolkit.Grid: + switch a.Type { + case toolkit.Margin: + t.uiGrid.SetPadded(true) + case toolkit.Unmargin: + t.uiGrid.SetPadded(false) + case toolkit.Pad: + t.uiGrid.SetPadded(true) + case toolkit.Unpad: + t.uiGrid.SetPadded(false) + } + case toolkit.Box: + switch a.Type { + case toolkit.Margin: + t.uiBox.SetPadded(true) + case toolkit.Unmargin: + t.uiBox.SetPadded(false) + case toolkit.Pad: + t.uiBox.SetPadded(true) + case toolkit.Unpad: + t.uiBox.SetPadded(false) + } + case toolkit.Textbox: + log(debugError, "TODO: implement expand for", a.Type) + log(debugError, "TODO: implement expand for", a.Type) + log(debugError, "TODO: implement expand for", a.Type) + log(debugError, "TODO: implement expand for", a.Type) + default: + log(debugError, "TODO: implement pad() for", a.Type) + } +} + +func move(a *toolkit.Action) { + if (a.Where == nil) { + log(debugError, "move() ERROR: can not move to nil") + return + } + if (a.Widget == nil) { + log(debugError, "move() ERROR: can not move nil") + return + } + log(debugNow, "move()", a.Widget.Name, "to", a.Where.Name) + + tWidget := mapToolkits[a.Widget] + if (tWidget == nil) { + log(debugError, "move() ERROR: toolkit struct == nil. for", a.Widget.Name) + return + } + + tWhere := mapToolkits[a.Where] + if (tWhere == nil) { + log(debugError, "move() ERROR: toolkit struct == nil. for", a.Where.Name) + return + } + + switch a.Where.Type { + case toolkit.Group: + switch a.Type { + case toolkit.Margin: + tWhere.uiGroup.SetMargined(true) + } + case toolkit.Tab: + switch a.Type { + case toolkit.Margin: + // tabSetMargined(tWhere.uiTab, true) + } + case toolkit.Window: + switch a.Type { + case toolkit.Pad: + // t.uiWindow.SetBorderless(false) + } + case toolkit.Grid: + switch a.Type { + case toolkit.Pad: + // t.uiGrid.SetPadded(true) + } + case toolkit.Box: + log(debugNow, "TODO: move() for a =", a.Type) + log(debugNow, "TODO: move() where =", a.Where.Type) + log(debugNow, "TODO: move() for widget =", a.Widget.Type) + + stretchy = true + tWhere.uiBox.Append(tWidget.uiControl, stretchy) + // log(debugNow, "is there a tWhere parent? =", tWhere.parent) + // tWhere.uiBox.Delete(0) + + // this didn't work: + // tWidget.uiControl.Disable() + // sleep(.8) + default: + log(debugError, "TODO: need to implement move() for a =", a.Type) + log(debugError, "TODO: need to implement move() for where =", a.Where.Type) + log(debugError, "TODO: need to implement move() for widget =", a.Widget.Type) + } +} + +func uiDelete(a *toolkit.Action) { + if (a.Where == nil) { + log(debugError, "uiDelete() ERROR: can not uiDelete to nil") + return + } + if (a.Widget == nil) { + log(debugError, "uiDelete() ERROR: can not uiDelete nil") + return + } + log(debugNow, "uiDelete()", a.Widget.Name, "to", a.Where.Name) + + tWidget := mapToolkits[a.Widget] + if (tWidget == nil) { + log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.Widget.Name) + return + } + + tWhere := mapToolkits[a.Where] + if (tWhere == nil) { + log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.Where.Name) + return + } + + switch a.Where.Type { + case toolkit.Group: + switch a.Type { + case toolkit.Margin: + tWhere.uiGroup.SetMargined(true) + } + case toolkit.Tab: + switch a.Type { + case toolkit.Margin: + // tabSetMargined(tWhere.uiTab, true) + } + case toolkit.Window: + switch a.Type { + case toolkit.Pad: + // t.uiWindow.SetBorderless(false) + } + case toolkit.Grid: + switch a.Type { + case toolkit.Pad: + // t.uiGrid.SetPadded(true) + } + case toolkit.Box: + log(debugNow, "tWidget.boxC =", tWhere.Name) + log(debugNow, "is there a tWhere parent? =", tWhere.parent) + if (tWidget.boxC < 1) { + log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", tWhere.boxC) + return + } + tWidget.uiBox.Delete(0) + tWidget.boxC -= 1 + + // this didn't work: + // tWidget.uiControl.Disable() + // sleep(.8) + // tWhere.uiBox.Append(tWidget.uiControl, stretchy) + default: + log(debugError, "TODO: need to implement uiDelete() for a =", a.Type) + log(debugError, "TODO: need to implement uiDelete() for where =", a.Where.Type) + log(debugError, "TODO: need to implement uiDelete() for widget =", a.Widget.Type) + } +} diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go new file mode 100644 index 0000000..707a87f --- /dev/null +++ b/toolkit/andlabs/add.go @@ -0,0 +1,154 @@ +package main + +import ( + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" + + "git.wit.org/wit/gui/toolkit" +) + +func actionDump(b bool, a *toolkit.Action) { + log(b, "dump() Widget.Type =", a.Type) + log(b, "dump() Widget.S =", a.S) + log(b, "dump() Widget.I =", a.I) + log(b, "dump() Widget =", a.Widget) + log(b, "dump() Where =", a.Where) +} + +func add(a *toolkit.Action) { + if (a.Widget == nil) { + log(debugError, "add() error. w.Widget == nil") + actionDump(debugError, a) + return + } + // for now, window gets handled without checking where == nil) + if (a.Widget.Type == toolkit.Window) { + doWindow(a) + return + } + + t := mapToolkits[a.Where] + if (t == nil) { + // listMap(debugError) // memory corruption? + log(debugError, "add() Widget.Name =", a.Widget.Name, a.Widget.Type) + // log(debugError, "add() Where.Name =", a.Where.Name) + log(debugError, "ERROR add() ERROR a.Where map to t == nil.") + return + } + + switch a.Widget.Type { + case toolkit.Window: + doWindow(a) + return + case toolkit.Tab: + doTab(a) + return + case toolkit.Label: + newLabel(a) + return + case toolkit.Button: + newButton(a) + return + case toolkit.Grid: + newGrid(a) + return + case toolkit.Checkbox: + newCheckbox(a) + return + case toolkit.Spinner: + newSpinner(a) + return + case toolkit.Slider: + newSlider(a) + return + case toolkit.Dropdown: + newDropdown(a) + return + case toolkit.Combobox: + newCombobox(a) + return + case toolkit.Textbox: + newTextbox(a) + return + case toolkit.Group: + newGroup(a) + return + case toolkit.Box: + newBox(a) + return + case toolkit.Image: + newImage(a) + return + default: + log(debugError, "add() error TODO: ", a.Widget.Type, a.Widget.Name) + } +} + +// This routine is very specific to this toolkit +// It's annoying and has to be copied to each widget when there are changes +// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten +// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here! +// but it's time to write direct GTK, QT, macos and windows toolkit plugins +// -- jcarr 2023/03/09 + +// Grid numbering examples by (X,Y) +// --------- +// -- (1) -- +// -- (2) -- +// --------- +// +// ----------------------------- +// -- (1,1) -- (1,2) -- (1,3) -- +// -- (2,1) -- (2,2) -- (2,3) -- +// ----------------------------- + +// internally for andlabs/ui +// (x&y flipped and start at zero) +// ----------------------------- +// -- (0,0) -- (1,0) -- (1,0) -- +// -- (0,1) -- (1,1) -- (1,1) -- +// ----------------------------- +func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool { + log(debugAction, "place() START", a.Widget.Type, a.Widget.Name) + + if (newt.uiControl == nil) { + log(debugError, "place() ERROR uiControl == nil", a.Where.Type, a.Where.Name) + return false + } + + switch a.Where.Type { + case toolkit.Grid: + log(debugGrid, "add() Grid try at Where X,Y =", a.Where.X, a.Where.Y) + newt.gridX = a.Where.X + newt.gridY = a.Where.Y + log(debugGrid, "add() Grid try at gridX,gridY", newt.gridX, newt.gridY) + // at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero + t.uiGrid.Append(newt.uiControl, + newt.gridY - 1, newt.gridX - 1, 1, 1, + false, ui.AlignFill, false, ui.AlignFill) + return true + case toolkit.Group: + if (t.uiBox == nil) { + t.uiGroup.SetChild(newt.uiControl) + log(debugGrid, "add() hack Group to use this as the box?", a.Widget.Name, a.Widget.Type) + t.uiBox = newt.uiBox + } else { + t.uiBox.Append(newt.uiControl, stretchy) + } + return true + case toolkit.Tab: + t.uiBox.Append(newt.uiControl, stretchy) + t.boxC += 1 + return true + case toolkit.Box: + t.uiBox.Append(newt.uiControl, stretchy) + t.boxC += 1 + return true + case toolkit.Window: + t.uiWindow.SetChild(newt.uiControl) + return true + default: + log(debugError, "add() how?", a.Where.Type) + } + return false +} diff --git a/toolkit/andlabs/append.go b/toolkit/andlabs/append.go deleted file mode 100644 index 4578c94..0000000 --- a/toolkit/andlabs/append.go +++ /dev/null @@ -1,103 +0,0 @@ -package main - -import ( - "git.wit.org/wit/gui/toolkit" - - "github.com/andlabs/ui" - _ "github.com/andlabs/ui/winmanifest" -) - -// move all the append code here -func (t *andlabsT) doAppend(kind toolkit.WidgetType, newt *andlabsT, c *ui.Control) { - if (kind == toolkit.Grid) { - log(debugToolkit, "doAppend() attempt to append a ui.Control into a uiGrid") - // hack to add shit to a grid - button1 := ui.NewButton("a(0,2)") - newt.uiGrid.Append(button1, - 0, 2, 1, 1, - false, ui.AlignFill, false, ui.AlignFill) - button2 := ui.NewButton("a(1,2)") - newt.uiGrid.Append(button2, - 1, 2, 1, 1, - false, ui.AlignFill, false, ui.AlignFill) - - if (t.uiBox != nil) { - log(debugToolkit, "doAppend() on uiGrid to a uiBox") - if (newt.Name == "output") { - t.uiBox.Append(newt.uiGrid, true) - } else { - t.uiBox.Append(newt.uiGrid, stretchy) - } - return - } - log(debugToolkit, "doAppend() on uiGrid failed") - return - } - - if (kind == toolkit.Group) { - log(debugToolkit, "doAppend() attempt a uiGroup") - if (t.uiBox != nil) { - if (newt.Name == "output") { - t.uiBox.Append(newt.uiGroup, true) - } else { - t.uiBox.Append(newt.uiGroup, stretchy) - } - return - } - - if (t.uiWindow != nil) { - log(debugToolkit, "This is a raw window without a box. probably make a box here and add the group to that") - newt.Dump(debugToolkit) - t.uiBox = ui.NewHorizontalBox() - t.uiWindow.SetChild(t.uiBox) - log(debugToolkit, "tried to make a box", t.uiBox) - if (newt.Name == "output") { - log(debugToolkit, "tried to t.uiBox.Append(*c, true)") - if (t.uiBox == nil) { - log(debugToolkit, "tried to t.uiBox.Append(*c, true)") - } - t.uiBox.Append(newt.uiGroup, true) - } else { - log(debugToolkit, "tried to t.uiBox.Append(*c, stretchy)") - t.uiBox.Append(newt.uiGroup, stretchy) - } - return - } - - log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it") - log(debugError, "probably could just make a box here?") - exit("internal wit/gui error") - } - - if (kind == toolkit.Textbox) { - if (t.uiBox == nil) { - log(debugError, "NewTextbox() node.UiBox == nil. I can't add a range UI element without a place to put it") - log(debugError, "probably could just make a box here?") - exit("internal wit/gui error") - } - // TODO: temporary hack to make the output textbox 'fullscreen' - if (newt.Name == "output") { - t.uiBox.Append(*c, true) - } else { - t.uiBox.Append(*c, stretchy) - } - return - } - - if (t.uiWindow != nil) { - log(debugToolkit, "This is a raw window without a box. probably make a box here and add the group to that") - t.uiBox = ui.NewHorizontalBox() - t.uiWindow.SetChild(t.uiBox) - log(debugToolkit, "tried to make a box") - if (newt.Name == "output") { - t.uiBox.Append(*c, true) - } else { - t.uiBox.Append(*c, stretchy) - } - return - } - - log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it") - log(debugError, "probably could just make a box here?") - exit("internal wit/gui error") -} diff --git a/toolkit/andlabs/box.go b/toolkit/andlabs/box.go index 265d7c8..cc7451d 100644 --- a/toolkit/andlabs/box.go +++ b/toolkit/andlabs/box.go @@ -1,54 +1,46 @@ package main -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" +import ( + "git.wit.org/wit/gui/toolkit" -// create a new box -func (t *andlabsT) getBox() *ui.Box { - return t.uiBox -} - -// create a new box -func (t *andlabsT) newBox() *andlabsT { - log(debugToolkit, "newBox() START create default") - t.Dump(debugToolkit) - if (t.uiGroup != nil) { - log(debugToolkit, "\tnewBox() is a Group") - var newTK andlabsT + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" +) - vbox := ui.NewVerticalBox() - vbox.SetPadded(padded) - t.uiGroup.SetChild(vbox) - newTK.uiBox = vbox +// make new Box here +func newBox(a *toolkit.Action) { + w := a.Widget + parentW := a.Where + log(debugToolkit, "newBox()", w.Name) - return &newTK + t := mapToolkits[parentW] + if (t == nil) { + log(debugToolkit, "newBox() toolkit struct == nil. name=", parentW.Name, w.Name) + listMap(debugToolkit) } - if (t.uiBox != nil) { - log(debugToolkit, "\tnewBox() is a Box") - var newTK andlabsT + newt := t.rawBox(w.Name, a.B) + newt.boxC = 0 + place(a, t, newt) + mapWidgetsToolkits(a, newt) +} - vbox := ui.NewVerticalBox() - vbox.SetPadded(padded) - t.uiBox.Append(vbox, stretchy) - newTK.uiBox = vbox - newTK.Name = t.Name +// make new Box using andlabs/ui +func (t *andlabsT) rawBox(title string, b bool) *andlabsT { + var newt andlabsT + var box *ui.Box + newt.Name = title - return &newTK + log(debugToolkit, "rawBox() create", newt.Name) + + if (b) { + box = ui.NewHorizontalBox() + } else { + box = ui.NewVerticalBox() } - if (t.uiWindow != nil) { - log(debugToolkit, "\tnewBox() is a Window") - var newT andlabsT + box.SetPadded(padded) - vbox := ui.NewVerticalBox() - vbox.SetPadded(padded) - t.uiWindow.SetChild(vbox) - newT.uiBox = vbox - newT.Name = t.Name + newt.uiBox = box + newt.uiControl = box - // panic("WTF") - return &newT - } - log(debugToolkit, "\tnewBox() FAILED. Couldn't figure out where to make a box") - t.Dump(debugToolkit) - return nil + return &newt } diff --git a/toolkit/andlabs/button.go b/toolkit/andlabs/button.go index 4ae791c..741ce3a 100644 --- a/toolkit/andlabs/button.go +++ b/toolkit/andlabs/button.go @@ -7,24 +7,23 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func newButton(parentW *toolkit.Widget, w *toolkit.Widget) { +func newButton(a *toolkit.Action) { var t, newt *andlabsT var b *ui.Button + w := a.Widget log(debugToolkit, "newButton()", w.Name) - t = mapToolkits[parentW] + t = mapToolkits[a.Where] if (t == nil) { - log(debugToolkit, "newButton() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "newButton() toolkit struct == nil. name=", a.Where.Name, w.Name) return } - if t.broken() { - return - } newt = new(andlabsT) b = ui.NewButton(w.Name) newt.uiButton = b + newt.uiControl = b newt.tw = w newt.parent = t @@ -32,66 +31,6 @@ func newButton(parentW *toolkit.Widget, w *toolkit.Widget) { newt.commonChange(newt.tw) }) - log(debugToolkit, "newButton() about to append to Box parent t:", w.Name) - log(debugToolkit, "newButton() about to append to Box new t:", w.Name) - if (debugToolkit) { - ShowDebug () - } - - if (t.uiBox != nil) { - t.uiBox.Append(b, stretchy) - } else if (t.uiWindow != nil) { - t.uiWindow.SetChild(b) - } else { - log(debugError, "ERROR: wit/gui andlabs couldn't place this button in a box or a window") - log(debugError, "ERROR: wit/gui andlabs couldn't place this button in a box or a window") - return - } - - mapWidgetsToolkits(w, newt) -} - -// This routine is very specific to this toolkit -// It's annoying and has to be copied to each widget when there are changes -// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten -// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here! -// but it's time to write direct GTK, QT, macos and windows toolkit plugins -// -- jcarr 2023/03/09 - -func doButton(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newButton(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Button() ct.broken", ct) - return - } - if (ct.uiButton == nil) { - log(debugError, "Button() uiButton == nil", ct) - return - } - log(debugToolkit, "Going to attempt:", c.Action) - switch c.Action { - case "Enable": - ct.uiButton.Enable() - case "Disable": - ct.uiButton.Disable() - case "Show": - ct.uiButton.Show() - case "Hide": - ct.uiButton.Hide() - case "Set": - ct.uiButton.SetText(c.S) - default: - log(debugError, "Can't do", c.Action, "to a Button") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/checkbox.go b/toolkit/andlabs/checkbox.go index d28d3dc..2ff7ccf 100644 --- a/toolkit/andlabs/checkbox.go +++ b/toolkit/andlabs/checkbox.go @@ -11,14 +11,8 @@ func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT { var newt andlabsT newt.tw = w - if t.broken() { - return nil - } - newt.uiCheckbox = ui.NewCheckbox(w.Name) - newt.uiBox = t.uiBox - // t.doAppend(&newt, *newt.uiCheckbox) - t.uiBox.Append(newt.uiCheckbox, stretchy) + newt.uiControl = newt.uiCheckbox newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { newt.tw.B = newt.checked() @@ -30,14 +24,12 @@ func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT { } func (t *andlabsT) checked() bool { - if t.broken() { - return false - } - return t.uiCheckbox.Checked() } -func newCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) { +func newCheckbox(a *toolkit.Action) { + w := a.Widget + parentW := a.Where log(debugToolkit, "newCheckbox()", w.Name) t := mapToolkits[parentW] @@ -46,45 +38,6 @@ func newCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) { return } newt := t.newCheckbox(w) - mapWidgetsToolkits(w, newt) -} - -func doCheckbox(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newCheckbox(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(true, "checkbox() ct.broken", ct) - return - } - if (ct.uiCheckbox == nil) { - log(true, "checkbox() uiCheckbox == nil", ct) - return - } - log(debugChange, "Going to attempt:", c.Action) - switch c.Action { - case "Enable": - ct.uiCheckbox.Enable() - case "Disable": - ct.uiCheckbox.Disable() - case "Show": - ct.uiCheckbox.Show() - case "Hide": - ct.uiCheckbox.Hide() - case "SetText": - ct.uiCheckbox.SetText(c.S) - case "Set": - ct.uiCheckbox.SetChecked(c.B) - default: - log(debugError, "Can't do", c.Action, "to a checkbox") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/combobox.go b/toolkit/andlabs/combobox.go index 3395406..e200b3b 100644 --- a/toolkit/andlabs/combobox.go +++ b/toolkit/andlabs/combobox.go @@ -10,15 +10,10 @@ func (t *andlabsT) newCombobox(w *toolkit.Widget) *andlabsT { var newt andlabsT log(debugToolkit, "newCombobox() START", w.Name) - if t.broken() { - return nil - } - newt.tw = w s := ui.NewEditableCombobox() newt.uiEditableCombobox = s - newt.uiBox = t.uiBox - t.uiBox.Append(s, stretchy) + newt.uiControl = s // initialize the index newt.c = 0 @@ -46,7 +41,9 @@ func (t *andlabsT) AddComboboxName(title string) { t.c = t.c + 1 } -func newCombobox(parentW *toolkit.Widget, w *toolkit.Widget) { +func newCombobox(a *toolkit.Action) { + w := a.Widget + parentW := a.Where log(debugToolkit, "newCombobox()", w.Name) t := mapToolkits[parentW] @@ -56,45 +53,6 @@ func newCombobox(parentW *toolkit.Widget, w *toolkit.Widget) { return } newt := t.newCombobox(w) - mapWidgetsToolkits(w, newt) -} - -func doCombobox(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newCombobox(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(true, "Combobox() ct.broken", ct) - return - } - if (ct.uiEditableCombobox == nil) { - log(true, "Combobox() uiEditableCombobox == nil", ct) - return - } - log(debugChange, "Going to attempt:", c.Action) - switch c.Action { - case "Add": - ct.AddComboboxName(c.S) - case "Enable": - ct.uiEditableCombobox.Enable() - case "Disable": - ct.uiEditableCombobox.Disable() - case "Show": - ct.uiEditableCombobox.Show() - case "Hide": - ct.uiEditableCombobox.Hide() - case "Set": - ct.uiEditableCombobox.SetText(c.S) - default: - log(debugError, "Can't do", c.Action, "to a Combobox") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go index 2e3997b..5cfaaa5 100644 --- a/toolkit/andlabs/common.go +++ b/toolkit/andlabs/common.go @@ -2,11 +2,10 @@ package main import ( "git.wit.org/wit/gui/toolkit" -// "github.com/davecgh/go-spew/spew" ) func (t *andlabsT) commonChange(tw *toolkit.Widget) { - log(debugChange, "commonChange() START widget =", t.Name, t.Type) + log(debugChange, "commonChange() START widget =", t.tw.Name, t.tw.Type) if (tw == nil) { log(true, "commonChange() What the fuck. there is no widget t.tw == nil") return @@ -19,44 +18,6 @@ func (t *andlabsT) commonChange(tw *toolkit.Widget) { log(debugChange, "commonChange() END Widget.Custom()", t.tw.Name, t.tw.Type) } -// does some sanity checks on the internal structs of the binary tree -// TODO: probably this should not panic unless it's running in devel mode (?) -// TODO: redo this now that WidgetType is used and send() is used to package plugins -func (t *andlabsT) broken() bool { - /* - if (t.parent != nil) { - return false - } - if (t.uiBox == nil) { - if (t.uiWindow != nil) { - log(debugToolkit, "UiBox == nil. This is an empty window. Try to add a box") - t.newBox() - return false - } - log(true, "UiBox == nil. I can't add a widget without a place to put it") - // log(debugToolkit, "probably could just make a box here?") - // corruption or something horrible? - t.Dump(true) - panic("wit/gui toolkit/andlabs func broken() invalid goroutine access into this toolkit?") - panic("wit/gui toolkit/andlabs func broken() this probably should not cause the app to panic here (?)") - return true - } - if (t.uiWindow == nil) { - log(debugToolkit, "UiWindow == nil. I can't add a widget without a place to put it (IGNORING FOR NOW)") - t.Dump(debugToolkit) - return false - } - */ - return false -} -func broken(w *toolkit.Widget) bool { - if (w == nil) { - log(true, "widget == nil. I can't do anything widget") - return true - } - return false -} - func dump(p *toolkit.Widget, c *toolkit.Widget, b bool) { log(b, "Parent:") pt := mapToolkits[p] diff --git a/toolkit/andlabs/debug.go b/toolkit/andlabs/debug.go index f2902ca..7d69485 100644 --- a/toolkit/andlabs/debug.go +++ b/toolkit/andlabs/debug.go @@ -14,7 +14,10 @@ var margin bool // add space around the frames of windows var debugToolkit bool var debugChange bool var debugPlugin bool +var debugAction bool var debugFlags bool +var debugGrid bool +var debugNow bool = true var debugError bool = true // This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc @@ -37,8 +40,9 @@ func setDefaultBehavior(s bool) { func ShowDebug () { log(true, "debugToolkit =", debugToolkit) log(true, "debugChange =", debugChange) - log(true, "debugPlugin =", debugPlugin) + log(true, "debugAction =", debugPlugin) log(true, "debugFlags =", debugFlags) + log(true, "debugNow =", debugNow) log(true, "debugError =", debugError) } @@ -87,7 +91,6 @@ func widgetDump(b bool, w *toolkit.Widget) { } log(b, "widget.Name =", w.Name) - log(b, "widget.Action =", w.Action) log(b, "widget.Type =", w.Type) log(b, "widget.Custom =", w.Custom) log(b, "widget.B =", w.B) diff --git a/toolkit/andlabs/delete.go b/toolkit/andlabs/delete.go index 4232521..d335324 100644 --- a/toolkit/andlabs/delete.go +++ b/toolkit/andlabs/delete.go @@ -18,7 +18,7 @@ func destroy(p *toolkit.Widget, c *toolkit.Widget) { return } - switch ct.Type { + switch ct.tw.Type { case toolkit.Button: log(true, "Should delete Button here:", c.Name) log(true, "Parent:") @@ -41,8 +41,8 @@ func destroy(p *toolkit.Widget, c *toolkit.Widget) { log(true, "Should delete Window here:", c.Name) default: log(true, "Don't know how to delete c =", c.Type, c.Name) - log(true, "Don't know how to delete pt =", pt.Type, pt.Name, pt.uiButton) - log(true, "Don't know how to delete ct =", ct.Type, ct.Name, ct.uiButton) + log(true, "Don't know how to delete pt =", pt.tw.Type, pt.tw.Name, pt.uiButton) + log(true, "Don't know how to delete ct =", ct.tw.Type, ct.tw.Name, ct.uiButton) log(true, "Parent:") pt.Dump(true) log(true, "Child:") diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go index 35d391b..eac1324 100644 --- a/toolkit/andlabs/dropdown.go +++ b/toolkit/andlabs/dropdown.go @@ -10,15 +10,10 @@ func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT { var newt andlabsT log(debugToolkit, "gui.Toolbox.newDropdown() START", w.Name) - if t.broken() { - return nil - } - newt.tw = w s := ui.NewCombobox() newt.uiCombobox = s - newt.uiBox = t.uiBox - t.uiBox.Append(s, stretchy) + newt.uiControl = s // initialize the index newt.c = 0 @@ -57,16 +52,16 @@ func (t *andlabsT) SetDropdown(i int) { t.uiCombobox.SetSelected(i) } -func AddDropdownName(w *toolkit.Widget, s string) { - log(debugToolkit, "gui.andlabs.AddDropdownName()", w.Name, "add:", s) +func AddDropdownName(a *toolkit.Action) { + log(debugToolkit, "gui.andlabs.AddDropdownName()", a.Widget.Name, "add:", a.S) - t := mapToolkits[w] + t := mapToolkits[a.Widget] if (t == nil) { - log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", w.Name, s) + log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", a.Widget.Name, a.S) listMap(debugToolkit) return } - t.AddDropdownName(s) + t.AddDropdownName(a.S) } func SetDropdownName(w *toolkit.Widget, s string) { @@ -82,7 +77,9 @@ func SetDropdownName(w *toolkit.Widget, s string) { t.tw.S = s } -func newDropdown(parentW *toolkit.Widget, w *toolkit.Widget) { +func newDropdown(a *toolkit.Action) { + w := a.Widget + parentW := a.Where log(debugToolkit, "gui.andlabs.newDropdown()", w.Name) t := mapToolkits[parentW] @@ -92,68 +89,6 @@ func newDropdown(parentW *toolkit.Widget, w *toolkit.Widget) { return } newt := t.newDropdown(w) - mapWidgetsToolkits(w, newt) -} - -func doDropdown(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newDropdown(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Dropdown() ct.broken", ct) - return - } - if (ct.uiCombobox == nil) { - log(debugError, "Dropdown() uiCombobox == nil", ct) - return - } - log(debugChange, "Going to attempt:", c.Action) - switch c.Action { - case "Add": - ct.AddDropdownName(c.S) - // ct.uiCombobox.Enable() - case "Enable": - ct.uiCombobox.Enable() - case "Disable": - ct.uiCombobox.Disable() - case "Show": - ct.uiCombobox.Show() - case "Hide": - ct.uiCombobox.Hide() - case "Set": - ct.uiCombobox.SetSelected(1) - case "SetText": - var orig int - var i int = -1 - var s string - orig = ct.uiCombobox.Selected() - log(debugError, "TODO: set a Dropdown by the name selected =", orig, ct.c, c.S) - // try to find the string - for i, s = range ct.val { - log(debugError, "i, s", i, s) - if (c.S == s) { - ct.uiCombobox.SetSelected(i) - return - } - } - // if i == -1, then there are not any things in the menu to select - if (i == -1) { - return - } - // if the string was never set, then set the dropdown to the last thing added to the menu - if (orig == -1) { - ct.uiCombobox.SetSelected(i) - } - default: - log(debugError, "Can't do", c.Action, "to a Dropdown") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/grid.go b/toolkit/andlabs/grid.go index 47a70e3..f009ab3 100644 --- a/toolkit/andlabs/grid.go +++ b/toolkit/andlabs/grid.go @@ -12,80 +12,21 @@ import ( // -- (1,1) -- (2,1) -- (3,1) -- // -- (1,2) -- (2,1) -- (3,1) -- // ----------------------------- -func newGrid(parentW *toolkit.Widget, w *toolkit.Widget) { +func newGrid(a *toolkit.Action) { var newt *andlabsT - log(debugToolkit, "NewGrid()", w.Name) + log(debugToolkit, "newGrid()", a.Widget.Name, "to", a.Where.Type) - t := mapToolkits[parentW] - if (t == nil) { - listMap(debugError) - log(debugError, "ERROR newGrid() listMap()") - log(debugError, "ERROR FFFFFFFFFFFF listMap()") - log(debugError, "ERROR FFFFFFFFFFFF listMap()") - return - } - - log(debugToolkit, "NewGrid()", w.Name) - if t.broken() { - return - } + t := mapToolkits[a.Where] newt = new(andlabsT) c := ui.NewGrid() newt.uiGrid = c - newt.uiBox = t.uiBox - newt.tw = w - t.doAppend(toolkit.Grid, newt, nil) - mapWidgetsToolkits(w, newt) -} + newt.uiControl = c + newt.tw = a.Widget + newt.gridX = 0 + newt.gridY = 0 -func doGrid(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newGrid(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Grid() ct.broken", ct) - return - } - if (ct.uiGrid == nil) { - log(debugError, "Grid() uiGrid == nil", ct) - return - } - log(debugChange, "Going to attempt:", c.Action) - switch c.Action { - case "Enable": - ct.uiGrid.Enable() - case "Disable": - ct.uiGrid.Disable() - case "Show": - ct.uiGrid.Show() - case "Hide": - log(debugError, "trying Hide on grid") - ct.uiGrid.Hide() - case "SetMargin": - log(debugError, "trying SetMargin on grid") - ct.uiGrid.SetPadded(c.B) - case "Set": - log(debugError, "Can I use 'Set' to place a *Node in a Grid?") - /* - case "AddGrid": - log(true, "how do I add a thing to a grid?") - dump(p, c, true) - newt.uiGrid.Append(button1, - 0, 2, 1, 1, - false, ui.AlignFill, false, ui.AlignFill) - */ - default: - log(debugError, "Can't do", c.Action, "to a Grid") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/group.go b/toolkit/andlabs/group.go index 717da42..a44c5b6 100644 --- a/toolkit/andlabs/group.go +++ b/toolkit/andlabs/group.go @@ -7,7 +7,9 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func newGroup(parentW *toolkit.Widget, w *toolkit.Widget) { +func newGroup(a *toolkit.Action) { + w := a.Widget + parentW := a.Where log(debugToolkit, "NewGroup()", w.Name) t := mapToolkits[parentW] @@ -16,7 +18,8 @@ func newGroup(parentW *toolkit.Widget, w *toolkit.Widget) { listMap(debugToolkit) } newt := t.rawGroup(w.Name) - mapWidgetsToolkits(w, newt) + place(a, t, newt) + mapWidgetsToolkits(a, newt) } // make new Group here @@ -29,69 +32,15 @@ func (t *andlabsT) rawGroup(title string) *andlabsT { g := ui.NewGroup(newt.Name) g.SetMargined(margin) newt.uiGroup = g + newt.uiControl = g - t.doAppend(toolkit.Group, &newt, nil) +// hbox := ui.NewVerticalBox() +// hbox.SetPadded(padded) +// g.SetChild(hbox) - hbox := ui.NewVerticalBox() - hbox.SetPadded(padded) - g.SetChild(hbox) - - newt.uiBox = hbox - newt.uiWindow = t.uiWindow - newt.uiTab = t.uiTab +// newt.uiBox = hbox +// newt.uiWindow = t.uiWindow +// newt.uiTab = t.uiTab return &newt } - -// This routine is very specific to this toolkit -// It's annoying and has to be copied to each widget when there are changes -// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten -// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here! -// but it's time to write direct GTK, QT, macos and windows toolkit plugins -// -- jcarr 2023/03/09 - -func doGroup(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - log(debugChange, "Going to attempt:", c.Action) - if (c.Action == "New") { - newGroup(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Group() ct.broken", ct) - return - } - if (ct.uiGroup == nil) { - log(debugError, "Label() uiGroup == nil", ct) - return - } - switch c.Action { - case "Enable": - ct.uiGroup.Enable() - case "Disable": - ct.uiGroup.Disable() - case "Show": - ct.uiGroup.Show() - case "Hide": - ct.uiGroup.Hide() - case "Get": - c.S = ct.uiGroup.Title() - case "Set": - ct.uiGroup.SetTitle(c.S) - case "SetText": - ct.uiGroup.SetTitle(c.S) - case "SetMargin": - ct.uiGroup.SetMargined(c.B) - case "Destroy": - ct.uiGroup.Destroy() - default: - log(debugError, "Can't do", c.Action, "to a Group") - } -} diff --git a/toolkit/andlabs/image.go b/toolkit/andlabs/image.go new file mode 100644 index 0000000..d16f711 --- /dev/null +++ b/toolkit/andlabs/image.go @@ -0,0 +1,68 @@ +package main + +import ( + "git.wit.org/wit/gui/toolkit" + + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" +) + +// make new Image here +func newImage(a *toolkit.Action) { + w := a.Widget + parentW := a.Where + log(debugToolkit, "newImage()", w.Name) + + t := mapToolkits[parentW] + if (t == nil) { + log(debugToolkit, "newImage() toolkit struct == nil. name=", parentW.Name, w.Name) + listMap(debugToolkit) + } + newt := t.rawImage(w.Name) + place(a, t, newt) + mapWidgetsToolkits(a, newt) +} + +// make new Image using andlabs/ui +func (t *andlabsT) rawImage(title string) *andlabsT { + var newt andlabsT + var img *ui.Image + newt.Name = title + + log(debugToolkit, "rawImage() create", newt.Name) + + img = ui.NewImage(16, 16) + + newt.uiImage = img + // newt.uiControl = img + + return &newt +} +/* + if (w.Name == "image") { + log(true, "NewTextbox() trying to add a new image") + i := ui.NewImage(16, 16) + img, _, err := image.Decode(bytes.NewReader(rawImage)) + if err != nil { + panic(err) + } + nr, ok := img.(*image.RGBA) + if !ok { + i2 := image.NewRGBA(img.Bounds()) + draw.Draw(i2, i2.Bounds(), img, img.Bounds().Min, draw.Src) + nr = i2 + } + i.Append(nr) + t.uiBox.Append(i, true) + + var img *ui.Image + var icon []byte + var imgA image.Image + + icon, _ = res.ReadFile("resources/ping6.working.png") + // imgA, _, err := image.Decode(bytes.NewReader(b)) + imgA, _, _ = image.Decode(icon) + img.Append(imgA) + img.Append(icon) + } +*/ diff --git a/toolkit/andlabs/label.go b/toolkit/andlabs/label.go index 6fa4baa..144c2c1 100644 --- a/toolkit/andlabs/label.go +++ b/toolkit/andlabs/label.go @@ -7,11 +7,12 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func newLabel(parentW *toolkit.Widget, w *toolkit.Widget) { +func newLabel(a *toolkit.Action) { var newt *andlabsT + w := a.Widget log(debugToolkit, "NewLabel()", w.Name) - t := mapToolkits[parentW] + t := mapToolkits[a.Where] if (t == nil) { listMap(debugError) log(debugError, "ERROR newLabel() listMap()") @@ -21,68 +22,13 @@ func newLabel(parentW *toolkit.Widget, w *toolkit.Widget) { } log(debugToolkit, "NewLabel()", w.Name) - if t.broken() { - return - } newt = new(andlabsT) c := ui.NewLabel(w.Name) newt.uiLabel = c + newt.uiControl = c - newt.uiBox = t.uiBox - newt.tw = w - if (defaultBehavior) { - t.uiBox.Append(c, stretchy) - } - - mapWidgetsToolkits(w, newt) -} - -// This routine is very specific to this toolkit -// It's annoying and has to be copied to each widget when there are changes -// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten -// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here! -// but it's time to write direct GTK, QT, macos and windows toolkit plugins -// -- jcarr 2023/03/09 - -func doLabel(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - log(debugChange, "Going to attempt:", c.Action) - if (c.Action == "New") { - newLabel(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Label() ct.broken", ct) - return - } - if (ct.uiLabel == nil) { - - log(debugError, "Label() uiLabel == nil", ct) - return - } - switch c.Action { - case "Enable": - ct.uiLabel.Enable() - case "Disable": - ct.uiLabel.Disable() - case "Show": - ct.uiLabel.Show() - case "Hide": - ct.uiLabel.Hide() - case "SetText": - ct.uiLabel.SetText(c.S) - case "Set": - ct.uiLabel.SetText(c.S) - default: - log(debugError, "Can't do", c.Action, "to a Label") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/plugin.go b/toolkit/andlabs/plugin.go index 8cac830..60cdbfa 100644 --- a/toolkit/andlabs/plugin.go +++ b/toolkit/andlabs/plugin.go @@ -19,73 +19,224 @@ import "git.wit.org/wit/gui/toolkit" // TODO: make sure you can't escape this goroutine // func Send(p *toolkit.Widget, c *toolkit.Widget) { - if (p == nil) { - log(debugPlugin, "Send() parent = nil") - } else { - log(debugPlugin, "Send() parent =", p.Name, ",", p.Type) + log(debugPlugin, "Send() goodbye. not used anymore") +} + +func Action(a *toolkit.Action) { + if (a == nil) { + log(debugPlugin, "Action = nil") + return + } + f := func() { + rawAction(a) } - log(debugPlugin, "Send() child =", c.Name, ",", c.Action, ",", c.Type) - /* - if (c.Action == "SetMargin") { - log(debugError, "need to implement SetMargin here") - setMargin(c, c.B) + // f() + Queue(f) +} + +func rawAction(a *toolkit.Action) { + + log(debugAction, "Action() START a.Type =", a.Type) + log(debugAction, "Action() START a.S =", a.S) + log(debugAction, "Action() START a.Widget =", a.Widget) + + switch a.Type { + case toolkit.Add: + add(a) + case toolkit.Show: + a.Widget.B = true + show(a.Widget) + case toolkit.Hide: + a.Widget.B = false + show(a.Widget) + case toolkit.Enable: + a.Widget.B = true + enable(a.Widget) + case toolkit.Disable: + a.Widget.B = false + enable(a.Widget) + case toolkit.Get: + setText(a) + case toolkit.GetText: + switch a.Widget.Type { + case toolkit.Textbox: + t := mapToolkits[a.Widget] + a.S = t.s + } + case toolkit.Set: + setText(a) + case toolkit.SetFlag: + flag(a) + case toolkit.SetText: + setText(a) + case toolkit.AddText: + setText(a) + case toolkit.Margin: + pad(a) + case toolkit.Unmargin: + pad(a) + case toolkit.Pad: + pad(a) + case toolkit.Unpad: + pad(a) + case toolkit.Delete: + uiDelete(a) + case toolkit.Flag: + flag(a) + case toolkit.Move: + log(debugNow, "attempt to move() =", a.Type, a.Widget) + move(a) + default: + log(debugError, "Action() Unknown =", a.Type, a.Widget) + } + log(debugAction, "Action() END =", a.Type, a.Widget) +} + +func flag(a *toolkit.Action) { + // log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type) + // log(debugFlags, "plugin Send() flag child =", c.Name, c.Type) + // log(debugFlags, "plugin Send() flag child.Action =", c.Action) + // log(debugFlags, "plugin Send() flag child.S =", c.S) + // log(debugFlags, "plugin Send() flag child.B =", c.B) + // log(debugFlags, "plugin Send() what to flag?") + // should set the checkbox to this value + switch a.S { + case "Toolkit": + debugToolkit = a.B + case "Change": + debugChange = a.B + case "Plugin": + debugPlugin = a.B + case "Flags": + debugFlags = a.B + case "Error": + debugError = a.B + case "Now": + debugNow = a.B + case "Show": + ShowDebug() + default: + log(debugError, "Can't set unknown flag", a.S) + } +} + +func setText(a *toolkit.Action) { + w := a.Widget + if (w == nil) { + log(debugError, "setText error. w.Widget == nil") + actionDump(debugError, a) return } - */ + t := mapToolkits[w] + log(debugChange, "setText() Attempt on", w.Type, "with", a.S) - switch c.Type { + switch w.Type { case toolkit.Window: - doWindow(c) + t.uiWindow.SetTitle(a.S) case toolkit.Tab: - doTab(p, c) case toolkit.Group: - doGroup(p, c) - case toolkit.Button: - doButton(p, c) + t.uiGroup.SetTitle(a.S) case toolkit.Checkbox: - doCheckbox(p, c) - case toolkit.Label: - doLabel(p, c) + switch a.Type { + case toolkit.SetText: + t.uiCheckbox.SetText(a.S) + case toolkit.Get: + w.B = t.uiCheckbox.Checked() + case toolkit.Set: + t.uiCheckbox.SetChecked(a.B) + w.B = a.B + default: + log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + } case toolkit.Textbox: - doTextbox(p, c) + switch a.Type { + case toolkit.Set: + t.uiMultilineEntry.SetText(a.S) + case toolkit.SetText: + t.uiMultilineEntry.SetText(a.S) + case toolkit.Get: + w.S = t.s + case toolkit.GetText: + w.S = t.s + default: + log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + } + case toolkit.Label: + t.uiLabel.SetText(a.S) + case toolkit.Button: + t.uiButton.SetText(a.S) case toolkit.Slider: - doSlider(p, c) + switch a.Type { + case toolkit.Get: + w.I = t.uiSlider.Value() + case toolkit.Set: + t.uiSlider.SetValue(a.I) + default: + log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + } case toolkit.Spinner: - doSpinner(p, c) + switch a.Type { + case toolkit.Get: + w.I = t.uiSpinbox.Value() + case toolkit.Set: + t.uiSpinbox.SetValue(a.I) + default: + log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + } case toolkit.Dropdown: - doDropdown(p, c) + switch a.Type { + case toolkit.AddText: + AddDropdownName(a) + case toolkit.Set: + var orig int + var i int = -1 + var s string + orig = t.uiCombobox.Selected() + log(debugChange, "try to set the Dropdown to", a.S, "from", orig) + // try to find the string + for i, s = range t.val { + log(debugChange, "i, s", i, s) + if (a.S == s) { + t.uiCombobox.SetSelected(i) + log(debugChange, "setText() Dropdown worked.", w.S) + return + } + } + log(debugError, "setText() Dropdown did not find:", a.S) + // if i == -1, then there are not any things in the menu to select + if (i == -1) { + return + } + // if the string was never set, then set the dropdown to the last thing added to the menu + if (orig == -1) { + t.uiCombobox.SetSelected(i) + } + case toolkit.Get: + w.S = t.s + case toolkit.GetText: + w.S = t.s + default: + log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + } case toolkit.Combobox: - doCombobox(p, c) - case toolkit.Grid: - doGrid(p, c) - case toolkit.Flag: - // log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type) - // log(debugFlags, "plugin Send() flag child =", c.Name, c.Type) - // log(debugFlags, "plugin Send() flag child.Action =", c.Action) - // log(debugFlags, "plugin Send() flag child.S =", c.S) - // log(debugFlags, "plugin Send() flag child.B =", c.B) - // log(debugFlags, "plugin Send() what to flag?") - // should set the checkbox to this value - switch c.S { - case "Toolkit": - debugToolkit = c.B - case "Change": - debugChange = c.B - case "Plugin": - debugPlugin = c.B - case "Flags": - debugFlags = c.B - case "Error": - debugError = c.B - case "Show": - ShowDebug() + switch a.Type { + case toolkit.AddText: + t.AddComboboxName(a.S) + case toolkit.Set: + t.uiEditableCombobox.SetText(a.S) + t.s = a.S + case toolkit.SetText: + t.uiEditableCombobox.SetText(a.S) + t.s = a.S + case toolkit.Get: + w.S = t.s + case toolkit.GetText: + w.S = t.s default: - log(debugError, "Can't set unknown flag", c.S) + log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) } default: - log(debugError, "plugin Send() unknown parent =", p.Name, p.Type) - log(debugError, "plugin Send() unknown child =", c.Name, c.Type) - log(debugError, "plugin Send() Don't know how to do", c.Type, "yet") + log(debugError, "plugin Send() Don't know how to setText on", w.Type, "yet", a.Type) } } diff --git a/toolkit/andlabs/process.go b/toolkit/andlabs/process.go new file mode 100644 index 0000000..d70877e --- /dev/null +++ b/toolkit/andlabs/process.go @@ -0,0 +1,72 @@ +// myplugin/myplugin.go +package main + +/* +from chatgpt: + +// put this in widget.go +import ( + "fmt" + // "toolkit" +) + +type Plugin interface { + Process(input chan string, output chan string) +} + +// put this in wit/gui/toolkit/* +type myPlugin struct{} + +var Plugin myPlugin + +func (p *myPlugin) Process(input chan string, output chan string) { + go func() { + for msg := range input { + // Your processing logic goes here + result := fmt.Sprintf("Processed: %s", msg) + output <- result + } + }() +} + +// main.go put this in wit/gui +package main + +import ( + "fmt" + "plugin" + "pluginapi" +) + +func main() { + plug, err := plugin.Open("myplugin.so") + if err != nil { + panic(err) + } + + symPlugin, err := plug.Lookup("Plugin") + if err != nil { + panic(err) + } + + p, ok := symPlugin.(pluginapi.Plugin) + if !ok { + panic("Invalid plugin type") + } + + input := make(chan string) + output := make(chan string) + + p.Process(input, output) + + input <- "Hello, World!" + close(input) + + for result := range output { + fmt.Println(result) + } +} + +*/ + +// func main() {} diff --git a/toolkit/andlabs/slider.go b/toolkit/andlabs/slider.go index f31bc25..181b258 100644 --- a/toolkit/andlabs/slider.go +++ b/toolkit/andlabs/slider.go @@ -12,18 +12,10 @@ func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT { log(debugToolkit, w.Name, w.Type, w.X, w.Y) var newt andlabsT - if (t.uiBox == nil) { - log(debugToolkit, "node.UiBox == nil. I can't add a range UI element without a place to put it") - log(debugToolkit, "probably could just make a box here?") - exit("internal golang wit/gui/toolkit error") - return nil - } - s := ui.NewSlider(w.X, w.Y) newt.uiSlider = s - newt.uiBox = t.uiBox + newt.uiControl = s newt.tw = w - t.uiBox.Append(s, stretchy) s.OnChanged(func(spin *ui.Slider) { newt.tw.I = newt.uiSlider.Value() @@ -33,8 +25,10 @@ func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT { return &newt } -func newSlider(parentW *toolkit.Widget, w *toolkit.Widget) { +func newSlider(a *toolkit.Action) { var newt *andlabsT + w := a.Widget + parentW := a.Where log(debugToolkit, "newSlider()", w.Name) t := mapToolkits[parentW] @@ -42,53 +36,9 @@ func newSlider(parentW *toolkit.Widget, w *toolkit.Widget) { log(debugError, "newSlider() ERROR toolkit struct == nil. name=", parentW.Name, w.Name) return } + w.X = a.X + w.Y = a.Y newt = t.newSlider(w) - mapWidgetsToolkits(w, newt) -} - -// This routine is very specific to this toolkit -// It's annoying and has to be copied to each widget when there are changes -// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten -// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here! -// but it's time to write direct GTK, QT, macos and windows toolkit plugins -// -- jcarr 2023/03/09 - -func doSlider(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - log(debugChange, "Going to attempt:", c.Action) - if (c.Action == "New") { - newSlider(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Slider() ct.broken", ct) - return - } - if (ct.uiSlider == nil) { - log(debugError, "Label() uiSlider == nil", ct) - return - } - switch c.Action { - case "Enable": - ct.uiSlider.Enable() - case "Disable": - ct.uiSlider.Disable() - case "Show": - ct.uiSlider.Show() - case "Hide": - ct.uiSlider.Hide() - case "Set": - ct.uiSlider.SetValue(c.I) - case "Get": - c.I = ct.uiSlider.Value() - default: - log(debugError, "Can't do", c.Action, "to a Slider") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/spinner.go b/toolkit/andlabs/spinner.go index 2e87541..6a47472 100644 --- a/toolkit/andlabs/spinner.go +++ b/toolkit/andlabs/spinner.go @@ -12,16 +12,10 @@ func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { log(debugToolkit, "newSpinner()", w.X, w.Y) var newt andlabsT - if (t.uiBox == nil) { - log(debugToolkit, "newSpinner() node.UiBox == nil. I can't add a range UI element without a place to put it") - return nil - } - s := ui.NewSpinbox(w.X, w.Y) newt.uiSpinbox = s - newt.uiBox = t.uiBox + newt.uiControl = s newt.tw = w - t.uiBox.Append(s, stretchy) s.OnChanged(func(s *ui.Spinbox) { newt.tw.I = newt.uiSpinbox.Value() @@ -31,61 +25,19 @@ func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { return &newt } -func newSpinner(parentW *toolkit.Widget, w *toolkit.Widget) { +func newSpinner(a *toolkit.Action) { var newt *andlabsT + w := a.Widget + parentW := a.Where t := mapToolkits[parentW] if (t == nil) { log(debugError, "NewSpinner() toolkit struct == nil. name=", parentW.Name, w.Name) return } + w.X = a.X + w.Y = a.Y newt = t.newSpinner(w) - mapWidgetsToolkits(w, newt) -} - -// This routine is very specific to this toolkit -// It's annoying and has to be copied to each widget when there are changes -// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten -// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here! -// but it's time to write direct GTK, QT, macos and windows toolkit plugins -// -- jcarr 2023/03/09 - -func doSpinner(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - log(debugChange, "Going to attempt:", c.Action) - if (c.Action == "New") { - newSpinner(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Spinner() ct.broken", ct) - return - } - if (ct.uiSpinbox == nil) { - log(debugError, "Label() uiSpinbox == nil", ct) - return - } - switch c.Action { - case "Enable": - ct.uiSpinbox.Enable() - case "Disable": - ct.uiSpinbox.Disable() - case "Show": - ct.uiSpinbox.Show() - case "Hide": - ct.uiSpinbox.Hide() - case "Set": - ct.uiSpinbox.SetValue(c.I) - case "Get": - c.I = ct.uiSpinbox.Value() - default: - log(debugError, "Can't do", c.Action, "to a Spinbox") - } + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go index 3353401..9b053af 100644 --- a/toolkit/andlabs/structs.go +++ b/toolkit/andlabs/structs.go @@ -10,15 +10,16 @@ type andlabsT struct { id string Name string - Type toolkit.WidgetType + // Type toolkit.WidgetType Width int Height int tw *toolkit.Widget parent *andlabsT + uiControl ui.Control + uiBox *ui.Box uiButton *ui.Button - uiControl *ui.Control uiCombobox *ui.Combobox uiCheckbox *ui.Checkbox uiEntry *ui.Entry @@ -31,11 +32,21 @@ type andlabsT struct { uiMultilineEntry *ui.MultilineEntry uiEditableCombobox *ui.EditableCombobox uiGrid *ui.Grid + uiImage *ui.Image + gridX int + gridY int // used as a counter to work around limitations of widgets like combobox // this is probably fucked up and in many ways wrong because of unsafe goroutine threading // but it's working for now due to the need for need for a correct interaction layer betten toolkits c int + i int + b bool + s string val map[int]string + + // andlabs/ui only accesses widget id numbers + boxC int // how many things on in a box + boxW map[int]int // find a widget in a box text string } diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go index 9dcd3fa..b0920ac 100644 --- a/toolkit/andlabs/tab.go +++ b/toolkit/andlabs/tab.go @@ -54,11 +54,11 @@ func (t *andlabsT) newTab(name string) *andlabsT { // This sets _all_ the tabs to Margin = true // // TODO: do proper tab tracking (will be complicated). low priority -func tabSetMargined(tab *ui.Tab) { +func tabSetMargined(tab *ui.Tab, b bool) { c := tab.NumPages() for i := 0; i < c; i++ { - log(debugToolkit, "SetMargined", i, margin) - tab.SetMargined(i, margin) + log(debugToolkit, "SetMargined", i, b) + tab.SetMargined(i, b) } } @@ -80,11 +80,12 @@ func rawTab(w *ui.Window, name string) *andlabsT { hbox := ui.NewHorizontalBox() // this makes everything go along the horizon hbox.SetPadded(padded) tab.Append(name, hbox) - tabSetMargined(tab) // TODO: run this in the right place(?) + tabSetMargined(tab, margin) // TODO: run this in the right place(?) w.SetChild(tab) newt.uiWindow = w newt.uiTab = tab + newt.uiControl = tab newt.uiBox = hbox return &newt } @@ -118,7 +119,9 @@ func (t *andlabsT) appendTab(name string) *andlabsT { return &newT } -func newTab(parentW *toolkit.Widget, w *toolkit.Widget) { +func newTab(a *toolkit.Action) { + parentW := a.Where + w := a.Widget var newt *andlabsT log(debugToolkit, "gui.andlabs.NewTab()", w.Name) @@ -128,55 +131,9 @@ func newTab(parentW *toolkit.Widget, w *toolkit.Widget) { return } newt = t.newTab(w.Name) - mapWidgetsToolkits(w, newt) + mapWidgetsToolkits(a, newt) } -func doTab(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newTab(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Tab() ct.broken", ct) - return - } - if (ct.uiTab == nil) { - - log(debugError, "Tab() uiTab == nil", ct) - return - } - log(debugChange, "Going to attempt:", c.Action) - switch c.Action { - case "Enable": - ct.uiTab.Enable() - case "Disable": - ct.uiTab.Disable() - case "Show": - ct.uiTab.Show() - case "Hide": - ct.uiTab.Hide() - case "Get": - c.I = ct.uiTab.NumPages() - case "Add": - log(true, "how do I add a tab here in doTab()?") - dump(p, c, true) - case "SetMargin": - i := ct.uiTab.NumPages() - log(true, "tab.NumPages() =", i) - for i > 0 { - i -= 1 - log(true, "uiTab.SetMargined(true) for i =", i) - ct.uiTab.SetMargined(i, c.B) - } - default: - log(debugError, "Can't do", c.Action, "to a Tab") - } +func doTab(a *toolkit.Action) { + newTab(a) } diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go index 9f7c3b4..cff61f2 100644 --- a/toolkit/andlabs/textbox.go +++ b/toolkit/andlabs/textbox.go @@ -7,142 +7,38 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) { - log(debugToolkit, "NewTexbox()", w.Name) - - t := mapToolkits[parentW] - if (t == nil) { - listMap(debugError) - log(debugError, "newTextbox() listMap()") - log(debugError, "FFFFFFFFFFFF listMap()") - log(debugError, "FFFFFFFFFFFF listMap()") - } - - // t.NewTextbox(w) -// func (t *andlabsT) NewTextbox(w *toolkit.Widget) *andlabsT { - var newt *andlabsT - newt = new(andlabsT) - - log(debugToolkit, "gui.Toolkit.NewTextbox()", w.Name) - if t.broken() { - return - } +// func newTextbox(a *toolkit.Action) { +func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT { + var newt andlabsT c := ui.NewNonWrappingMultilineEntry() newt.uiMultilineEntry = c + newt.uiControl = c - newt.uiBox = t.uiBox newt.Name = w.Name newt.tw = w - if (defaultBehavior) { - t.uiBox.Append(c, true) - } else { - t.uiBox.Append(c, stretchy) - } - - /* - // don't bother with "images" on andlabs/ui - "image" - "bytes" - _ "image/png" - "image/draw" - - if (w.Name == "image") { - log(true, "NewTextbox() trying to add a new image") - i := ui.NewImage(16, 16) - img, _, err := image.Decode(bytes.NewReader(rawImage)) - if err != nil { - panic(err) - } - nr, ok := img.(*image.RGBA) - if !ok { - i2 := image.NewRGBA(img.Bounds()) - draw.Draw(i2, i2.Bounds(), img, img.Bounds().Min, draw.Src) - nr = i2 - } - i.Append(nr) - t.uiBox.Append(i, true) - - var img *ui.Image - var icon []byte - var imgA image.Image - - icon, _ = res.ReadFile("resources/ping6.working.png") - // imgA, _, err := image.Decode(bytes.NewReader(b)) - imgA, _, _ = image.Decode(icon) - img.Append(imgA) - img.Append(icon) - } - */ c.OnChanged(func(spin *ui.MultilineEntry) { - w.S = newt.uiMultilineEntry.Text() + t.s = spin.Text() // this is still dangerous // newt.commonChange(newt.tw) log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry") }) - mapWidgetsToolkits(w, newt) + return &newt } +func newTextbox(a *toolkit.Action) { + w := a.Widget + parentW := a.Where + log(debugToolkit, "newCombobox()", w.Name) -func doTextbox(p *toolkit.Widget, c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newTextbox(p, c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if ct.broken() { - log(debugError, "Textbox() ct.broken", ct) - return - } - if (ct.uiMultilineEntry == nil) { - log(debugError, "Textbox() uiMultilineEntry == nil", ct) + t := mapToolkits[parentW] + if (t == nil) { + log(debugToolkit, "newCombobox() toolkit struct == nil. name=", parentW.Name, w.Name) + listMap(debugToolkit) return } - // the dns control panel isn't crashing anymore (?) - Queue(ct.doSimpleAction) -} - -func (t *andlabsT) doSimpleAction() { - if (t.tw == nil) { - log(true, "doSimpleAction() got an empty widget") - log(true, "THIS SHOULD NEVER HAPPEN") - panic("crap. panic. widget == nil") - } - log(debugChange, "Going to attempt:", t.tw.Action) - switch t.tw.Action { - case "Enable": - if (t.uiEntry != nil) { - t.uiEntry.Enable() - } else if (t.uiMultilineEntry != nil) { - t.uiMultilineEntry.Enable() - } else { - log(debugError, "don't know what to enable", t.Name) - } - case "Disable": - if (t.uiEntry != nil) { - t.uiEntry.Disable() - } else if (t.uiMultilineEntry != nil) { - t.uiMultilineEntry.Disable() - } else { - log(debugError, "don't know what to disable", t.Name) - } - case "Show": - t.uiMultilineEntry.Show() - case "Hide": - t.uiMultilineEntry.Hide() - case "SetText": - t.uiMultilineEntry.SetText(t.tw.S) - case "Set": - t.uiMultilineEntry.SetText(t.tw.S) - default: - log(debugError, "Can't do", t.tw.Action, "to a Textbox") - } + newt := t.newTextbox(w) + place(a, t, newt) + mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/widget.go b/toolkit/andlabs/widget.go index 2ea15d1..e4a2bb7 100644 --- a/toolkit/andlabs/widget.go +++ b/toolkit/andlabs/widget.go @@ -9,10 +9,11 @@ import ( var mapWidgets map[*andlabsT]*toolkit.Widget var mapToolkits map[*toolkit.Widget]*andlabsT -// This lists out the know mappings +// This lists out the known mappings +// deprecate and use instead the GUI interface func listMap(b bool) { - log(b, "listMap() HERE") - log(b, "listMap() HERE") + log(b, "listMap() disabled HERE. output too big") + return for t, w := range mapWidgets { log(b, "andlabs =", t.Name, "widget =", w.Name) } @@ -25,7 +26,8 @@ func listMap(b bool) { log(b, "listMap() HERE FIXME. output too big") } -func mapWidgetsToolkits(w *toolkit.Widget, t *andlabsT) { +func mapWidgetsToolkits(a *toolkit.Action, t *andlabsT) { + w := a.Widget if ((mapToolkits[w] == nil) && (mapWidgets[t] == nil)) { log(debugToolkit, "map a new widget", w, t) mapToolkits[w] = t @@ -63,5 +65,5 @@ func mapWidgetsToolkits(w *toolkit.Widget, t *andlabsT) { widgetDump(debugError, wt) } } - log(debugToolkit, "map of widget worked", w.Type, ",", w.Name, ",", w.Action) + log(debugToolkit, "map of widget worked", w.Type, ",", w.Name) } diff --git a/toolkit/andlabs/window.go b/toolkit/andlabs/window.go index 8251e30..9181d5f 100644 --- a/toolkit/andlabs/window.go +++ b/toolkit/andlabs/window.go @@ -15,7 +15,8 @@ func (t *andlabsT) ErrorWindow(msg1 string, msg2 string) { ui.MsgBoxError(t.uiWindow, msg1, msg2) } -func newWindow(w *toolkit.Widget) { +func newWindow(a *toolkit.Action) { + w := a.Widget var newt *andlabsT log(debugToolkit, "toolkit NewWindow", w.Name, w.Width, w.Height) @@ -37,10 +38,11 @@ func newWindow(w *toolkit.Widget) { }) win.Show() newt.uiWindow = win + newt.uiControl = win // newt.UiWindowBad = win // deprecate this as soon as possible newt.Name = w.Name - mapWidgetsToolkits(w, newt) + mapWidgetsToolkits(a, newt) return } @@ -54,46 +56,6 @@ func (t *andlabsT) SetWindowTitle(title string) { } } -func doWindow(c *toolkit.Widget) { - if broken(c) { - return - } - if (c.Action == "New") { - newWindow(c) - return - } - ct := mapToolkits[c] - if (ct == nil) { - log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) - return - } - if (ct.uiWindow == nil) { - log(debugError, "Window() uiWindow == nil", ct) - return - } - log(debugChange, "Going to attempt:", c.Action) - switch c.Action { - case "Show": - ct.uiWindow.Show() - case "Hide": - ct.uiWindow.Hide() - case "Enable": - ct.uiWindow.Enable() - case "Disable": - ct.uiWindow.Disable() - case "Get": - c.S = ct.uiWindow.Title() - case "Set": - ct.uiWindow.SetTitle(c.S) - case "SetText": - ct.uiWindow.SetTitle(c.S) - case "SetMargin": - ct.uiWindow.SetMargined(c.B) - case "SetBorder": - ct.uiWindow.SetBorderless(c.B) - case "Delete": - ct.uiWindow.Destroy() - default: - log(debugError, "Can't do", c.Action, "to a Window") - } +func doWindow(a *toolkit.Action) { + newWindow(a) } diff --git a/toolkit/democui/debug.go b/toolkit/democui/debug.go index 817ee6e..d024925 100644 --- a/toolkit/democui/debug.go +++ b/toolkit/democui/debug.go @@ -89,7 +89,6 @@ func widgetDump(b bool, w *toolkit.Widget) { } log(b, "widget.Name =", w.Name) - log(b, "widget.Action =", w.Action) log(b, "widget.Type =", w.Type) log(b, "widget.Custom =", w.Custom) log(b, "widget.B =", w.B) diff --git a/toolkit/democui/plugin.go b/toolkit/democui/plugin.go index 0b26f8f..2c0d42e 100644 --- a/toolkit/democui/plugin.go +++ b/toolkit/democui/plugin.go @@ -44,7 +44,7 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { } else { log(debugPlugin, "Send() parent =", p.Name, ",", p.Type) } - log(debugPlugin, "Send() child =", c.Name, ",", c.Action, ",", c.Type) + log(debugPlugin, "Send() child =", c.Name, ",", c.Type) /* if (c.Action == "SetMargin") { @@ -81,6 +81,7 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { case toolkit.Grid: // doGrid(p, c) */ + /* case toolkit.Flag: // log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type) // log(debugFlags, "plugin Send() flag child =", c.Name, c.Type) @@ -105,6 +106,7 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { default: log(debugError, "Can't set unknown flag", c.S) } + */ default: log(debugError, "plugin Send() unknown parent =", p.Name, p.Type) log(debugError, "plugin Send() unknown child =", c.Name, c.Type) diff --git a/toolkit/gocui/debug.go b/toolkit/gocui/debug.go index 817ee6e..1e424f7 100644 --- a/toolkit/gocui/debug.go +++ b/toolkit/gocui/debug.go @@ -89,7 +89,7 @@ func widgetDump(b bool, w *toolkit.Widget) { } log(b, "widget.Name =", w.Name) - log(b, "widget.Action =", w.Action) + // log(b, "widget.Action =", w.Action) log(b, "widget.Type =", w.Type) log(b, "widget.Custom =", w.Custom) log(b, "widget.B =", w.B) diff --git a/toolkit/gocui/plugin.go b/toolkit/gocui/plugin.go index 2b01acc..f0f45d3 100644 --- a/toolkit/gocui/plugin.go +++ b/toolkit/gocui/plugin.go @@ -44,7 +44,7 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { } else { log(debugPlugin, "Send() parent =", p.Name, ",", p.Type) } - log(debugPlugin, "Send() child =", c.Name, ",", c.Action, ",", c.Type) + log(debugPlugin, "Send() child =", c.Name, ",", c.Type) /* if (c.Action == "SetMargin") { @@ -83,6 +83,7 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { case toolkit.Grid: // doGrid(p, c) */ + /* case toolkit.Flag: // log(debugFlags, "plugin Send() flag parent =", p.Name, p.Type) // log(debugFlags, "plugin Send() flag child =", c.Name, c.Type) @@ -107,6 +108,7 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { default: log(debugError, "Can't set unknown flag", c.S) } + */ default: log(debugError, "plugin Send() unknown parent =", p.Name, p.Type) log(debugError, "plugin Send() unknown child =", c.Name, c.Type) diff --git a/toolkit/widget.go b/toolkit/widget.go index 30169ba..450cd8b 100644 --- a/toolkit/widget.go +++ b/toolkit/widget.go @@ -1,18 +1,24 @@ package toolkit +type WidgetType int +type ActionType int + // passes information between the toolkit library (plugin) // // All Toolkit interactions should be done via a channel or Queue() -// TODO: FIND THIS NOTE AND FIGURE OUT HOW TO IMPLEMENT IT +// TODO: FIGURE OUT HOW TO IMPLEMENT THIS // // This is the only thing that is passed between the toolkit plugin // // what names should be used? This is not part of [[Graphical Widget]] -// Event() seems like a good name. +// Event() seems like a good name. +// Event is used too much: web dev, cloud, etc +// I'm using "Action". Maybe it should really be +// "Interaction" as per wikipedia [[User interface]] // Could a protobuf be used here? (Can functions be passed?) type Widget struct { Name string - Action string // "New", "Delete", "Set", aka something to do + // Action string // "New", "Delete", "Set", aka something to do Type WidgetType // This function is how you interact with the toolkit @@ -20,6 +26,7 @@ type Widget struct { // Hopefully this will be the barrier between the goroutines // TODO: move this interaction to channels Custom func() + Callback func() // re-adding an id to test channels id int @@ -48,26 +55,88 @@ type Widget struct { Expand bool } -type WidgetType int +type Action struct { + Type ActionType + + // this should be the widget + // if the action is New, Hide, Enable, etc + Widget *Widget + + // this is the widget + // where the other one should be put on New, Move, etc + Where *Widget + + // This is how the values are passed back and forth + // values from things like checkboxes & dropdown's + // The string is also used to set the button name + B bool + I int + // maybe safe if there is correctly working Custom() between goroutines? + // (still probably not, almost certainly not. not possible. layer violation?) + S string // not safe to have 'S' + + // This GUI is intended for simple things + // We are not laying out PDF's here + // This is used for things like a slider(0,100) + Width int + Height int + X int + Y int + + // Put space around elements to improve look & feel + Margin bool + + // Make widgets fill up the space available + Expand bool +} + // https://ieftimov.com/post/golang-datastructures-trees/ +// TODO: protobuf ? const ( Unknown WidgetType = iota Window - Tab - Group - Frame + Tab // internally, this should be a window (?) + Frame // should windows and tab's be frames (?) + Grid // a grid of frames ? + Group // internally, this should be a grid (?) + Box // internally, this should be a grid (?) Button Checkbox Dropdown - Combobox + Combobox // dropdown with edit=true (?) Label - Textbox + Textbox // is this a Label with edit=true? Slider Spinner - Grid - Box Image + Area + Form + Font + Color + Dialog +) + +const ( + Add ActionType = iota + Delete + Get + Set + SetFlag + GetText + SetText + AddText + Show + Hide + Enable + Disable + Margin + Unmargin + Pad + Unpad + Append + Move + Dump Flag ) @@ -77,10 +146,14 @@ func (s WidgetType) String() string { return "Window" case Tab: return "Tab" - case Group: - return "Group" case Frame: return "Frame" + case Grid: + return "Grid" + case Group: + return "Group" + case Box: + return "Box" case Button: return "Button" case Checkbox: @@ -97,18 +170,68 @@ func (s WidgetType) String() string { return "Slider" case Spinner: return "Spinner" - case Grid: - return "Grid" - case Box: - return "Box" case Image: return "Image" - case Flag: - return "Flag" + case Area: + return "Area" + case Form: + return "Form" + case Font: + return "Font" + case Color: + return "Color" + case Dialog: + return "Dialog" case Unknown: return "Unknown" } - return "GuiToolkitTUndefinedType" + return "Widget.Type.String() Error" +} + +func (s ActionType) String() string { + switch s { + case Add: + return "Add" + case Delete: + return "Delete" + case Get: + return "Get" + case Set: + return "Set" + case SetFlag: + return "SetFlag" + case GetText: + return "GetText" + case SetText: + return "SetText" + case AddText: + return "AddText" + case Show: + return "Show" + case Hide: + return "Hide" + case Enable: + return "Enable" + case Disable: + return "Disable" + case Margin: + return "Margin" + case Unmargin: + return "Unmargin" + case Pad: + return "Pad" + case Unpad: + return "Unpad" + case Append: + return "Append" + case Move: + return "Move" + case Flag: + return "Flag" + case Dump: + return "Dump" + } + return "Action.Type.String() Error" } // this is hopefully just used in a very few places for |
