diff options
| author | Jeff Carr <[email protected]> | 2023-03-29 23:03:04 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-03-29 23:03:04 -0500 |
| commit | 4e28cde838683188bfbd9222746409538828592d (patch) | |
| tree | 3c84fffc14352329bc41e6b58910ff278c99f08c /toolkit/andlabs | |
| parent | d4787a1ebdd08359746516dbb72f1feaf95be5b6 (diff) | |
add semi-working gocuiv0.7.4
commit 947169df5a22c9f9b53f825764747f648c70ff1e
Author: Jeff Carr <[email protected]>
Date: Wed Mar 29 22:44:08 2023 -0500
ready for version v0.7.4
start deprecating toolkit.Widget
switch to variable name 'ParentId'
use 'ActionType' and 'WidgetType'
preliminary redraw()
final definition of variables 'Name' and 'Text'
more cleaning of the code
remove lots of dumb code
bind 'd' key press to dump out debugging info
early color handling in gocui!
Signed-off-by: Jeff Carr <[email protected]>
commit 6013fde8332e8ecbffaf1a0977ba2e1da8ea8775
Author: Jeff Carr <[email protected]>
Date: Sun Mar 26 17:19:20 2023 -0500
improvements towards a working dns control panel
democui has the help menu
try to add mouse support to gocui
make a direct access method
Margin() and Pad() tests
add SPEW
also push devel branch to github
Signed-off-by: Jeff Carr <[email protected]>
commit 6f91f5e080e06cdc0f34b13d23e5fd16ea37259a
Author: Jeff Carr <[email protected]>
Date: Fri Mar 24 20:14:18 2023 -0500
starting to try safe chan and goroutines
fix tab title's
right before attempting to add chan goroutines
removed "where" widget pointer
box added to tab
experiement with log as it's own repo
Signed-off-by: Jeff Carr <[email protected]>
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/andlabs')
| -rw-r--r-- | toolkit/andlabs/action.go | 150 | ||||
| -rw-r--r-- | toolkit/andlabs/add.go | 72 | ||||
| -rw-r--r-- | toolkit/andlabs/box.go | 12 | ||||
| -rw-r--r-- | toolkit/andlabs/button.go | 16 | ||||
| -rw-r--r-- | toolkit/andlabs/checkbox.go | 18 | ||||
| -rw-r--r-- | toolkit/andlabs/combobox.go | 18 | ||||
| -rw-r--r-- | toolkit/andlabs/common.go | 26 | ||||
| -rw-r--r-- | toolkit/andlabs/debug.go | 2 | ||||
| -rw-r--r-- | toolkit/andlabs/delete.go | 19 | ||||
| -rw-r--r-- | toolkit/andlabs/dropdown.go | 34 | ||||
| -rw-r--r-- | toolkit/andlabs/grid.go | 7 | ||||
| -rw-r--r-- | toolkit/andlabs/group.go | 14 | ||||
| -rw-r--r-- | toolkit/andlabs/image.go | 6 | ||||
| -rw-r--r-- | toolkit/andlabs/label.go | 3 | ||||
| -rw-r--r-- | toolkit/andlabs/log.go | 136 | ||||
| -rw-r--r-- | toolkit/andlabs/main.go | 8 | ||||
| -rw-r--r-- | toolkit/andlabs/plugin.go | 100 | ||||
| -rw-r--r-- | toolkit/andlabs/slider.go | 24 | ||||
| -rw-r--r-- | toolkit/andlabs/spinner.go | 22 | ||||
| -rw-r--r-- | toolkit/andlabs/structs.go | 7 | ||||
| -rw-r--r-- | toolkit/andlabs/tab.go | 73 | ||||
| -rw-r--r-- | toolkit/andlabs/textbox.go | 7 | ||||
| -rw-r--r-- | toolkit/andlabs/widget.go | 55 | ||||
| -rw-r--r-- | toolkit/andlabs/window.go | 15 |
24 files changed, 348 insertions, 496 deletions
diff --git a/toolkit/andlabs/action.go b/toolkit/andlabs/action.go index 3272414..9d098df 100644 --- a/toolkit/andlabs/action.go +++ b/toolkit/andlabs/action.go @@ -4,40 +4,40 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func show(w *toolkit.Widget) { - if (w == nil) { +func show(a *toolkit.Action) { + if (a == nil) { log(debugError, "nil is probably already hidden") return } - log(debugError, "show()", w.Name) + log(debugError, "show()", a.WidgetId) - t := mapToolkits[w] + t := andlabs[a.WidgetId] if (t == nil) { - log(debugToolkit, "show() toolkit struct == nil. for", w.Name) + log(debugError, "show() toolkit struct == nil. for", a.WidgetId) return } - if (w.B) { + if (a.B) { t.uiControl.Show() } else { t.uiControl.Hide() } } -func enable(w *toolkit.Widget) { - if (w == nil) { +func enable(a *toolkit.Action) { + if (a == nil) { log(debugError, "nil is probably already hidden") return } - log(debugError, "enable()", w.Name) + log(debugError, "enable() name =", a.WidgetId) - t := mapToolkits[w] + t := andlabs[a.WidgetId] if (t == nil) { - log(debugToolkit, "enable() toolkit struct == nil. for", w.Name) + log(debugToolkit, "enable() toolkit struct == nil. for id =", a.WidgetId) return } - if (w.B) { + if (a.B) { t.uiControl.Enable() } else { t.uiControl.Disable() @@ -45,21 +45,21 @@ func enable(w *toolkit.Widget) { } func pad(a *toolkit.Action) { - if (a.Widget == nil) { + if (a == nil) { log(debugError, "pad() ERROR: nil is probably already hidden") return } - log(debugError, "pad()", a.Widget.Name) + log(debugError, "pad()") - t := mapToolkits[a.Widget] + t := andlabs[a.WidgetId] if (t == nil) { - log(debugToolkit, "pad() toolkit struct == nil. for", a.Widget.Name) + log(debugError, "pad() toolkit struct == nil. for", a.WidgetId) return } - switch a.Widget.Type { + switch t.Type { case toolkit.Group: - switch a.Type { + switch a.ActionType { case toolkit.Margin: t.uiGroup.SetMargined(true) case toolkit.Unmargin: @@ -70,7 +70,7 @@ func pad(a *toolkit.Action) { t.uiGroup.SetMargined(false) } case toolkit.Tab: - switch a.Type { + switch a.ActionType { case toolkit.Margin: tabSetMargined(t.uiTab, true) case toolkit.Unmargin: @@ -81,7 +81,7 @@ func pad(a *toolkit.Action) { tabSetMargined(t.uiTab, false) } case toolkit.Window: - switch a.Type { + switch a.ActionType { case toolkit.Margin: t.uiWindow.SetMargined(true) case toolkit.Unmargin: @@ -92,7 +92,7 @@ func pad(a *toolkit.Action) { t.uiWindow.SetBorderless(true) } case toolkit.Grid: - switch a.Type { + switch a.ActionType { case toolkit.Margin: t.uiGrid.SetPadded(true) case toolkit.Unmargin: @@ -103,7 +103,7 @@ func pad(a *toolkit.Action) { t.uiGrid.SetPadded(false) } case toolkit.Box: - switch a.Type { + switch a.ActionType { case toolkit.Margin: t.uiBox.SetPadded(true) case toolkit.Unmargin: @@ -114,128 +114,120 @@ func pad(a *toolkit.Action) { 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) + log(debugError, "TODO: implement expand for", a.ActionType) + log(debugError, "TODO: implement expand for", a.ActionType) + log(debugError, "TODO: implement expand for", a.ActionType) + log(debugError, "TODO: implement expand for", a.ActionType) default: - log(debugError, "TODO: implement pad() for", a.Type) + log(debugError, "TODO: implement pad() for", a.ActionType) } } 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) + log(debugNow, "move()", a.WidgetId, "to", a.ParentId) - tWidget := mapToolkits[a.Widget] + tWidget := andlabs[a.WidgetId] if (tWidget == nil) { - log(debugError, "move() ERROR: toolkit struct == nil. for", a.Widget.Name) + log(debugError, "move() ERROR: toolkit struct == nil. for", a.WidgetId) return } - tWhere := mapToolkits[a.Where] - if (tWhere == nil) { - log(debugError, "move() ERROR: toolkit struct == nil. for", a.Where.Name) + tParent := andlabs[a.ParentId] + if (tParent == nil) { + log(debugError, "move() ERROR: toolkit struct == nil. for", a.ParentId) return } - switch a.Where.Type { + switch tParent.Type { case toolkit.Group: - switch a.Type { + switch a.ActionType { case toolkit.Margin: - tWhere.uiGroup.SetMargined(true) + tParent.uiGroup.SetMargined(true) } case toolkit.Tab: - switch a.Type { + switch a.ActionType { case toolkit.Margin: - // tabSetMargined(tWhere.uiTab, true) + // tabSetMargined(tParent.uiTab, true) } case toolkit.Window: - switch a.Type { + switch a.ActionType { case toolkit.Pad: // t.uiWindow.SetBorderless(false) } case toolkit.Grid: - switch a.Type { + switch a.ActionType { 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) + log(debugNow, "TODO: move() for a =", a.ActionType) + log(debugNow, "TODO: move() where =", a.ParentId) + log(debugNow, "TODO: move() for widget =", a.WidgetId) stretchy = true - tWhere.uiBox.Append(tWidget.uiControl, stretchy) - // log(debugNow, "is there a tWhere parent? =", tWhere.parent) - // tWhere.uiBox.Delete(0) + tParent.uiBox.Append(tWidget.uiControl, stretchy) + // log(debugNow, "is there a tParent parent? =", tParent.parent) + // tParent.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) + log(debugError, "TODO: need to implement move() for a =", a.ActionType) + log(debugError, "TODO: need to implement move() for where =", a.ParentId) + log(debugError, "TODO: need to implement move() for widget =", a.WidgetId) } } func uiDelete(a *toolkit.Action) { - if (a.Where == nil) { + if (andlabs[a.ParentId] == nil) { log(debugError, "uiDelete() ERROR: can not uiDelete to nil") return } - if (a.Widget == nil) { + if (andlabs[a.WidgetId] == nil) { log(debugError, "uiDelete() ERROR: can not uiDelete nil") return } - log(debugNow, "uiDelete()", a.Widget.Name, "to", a.Where.Name) + log(debugNow, "uiDelete()", a.WidgetId, "to", a.ParentId) - tWidget := mapToolkits[a.Widget] + tWidget := andlabs[a.WidgetId] if (tWidget == nil) { - log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.Widget.Name) + log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.WidgetId) return } - tWhere := mapToolkits[a.Where] - if (tWhere == nil) { - log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.Where.Name) + tParent := andlabs[a.ParentId] + if (tParent == nil) { + log(debugError, "uiDelete() ERROR: toolkit struct == nil. for", a.ParentId) return } - switch a.Where.Type { + switch tParent.Type { case toolkit.Group: - switch a.Type { + switch a.ActionType { case toolkit.Margin: - tWhere.uiGroup.SetMargined(true) + tParent.uiGroup.SetMargined(true) } case toolkit.Tab: - switch a.Type { + switch a.ActionType { case toolkit.Margin: - // tabSetMargined(tWhere.uiTab, true) + // tabSetMargined(tParent.uiTab, true) } case toolkit.Window: - switch a.Type { + switch a.ActionType { case toolkit.Pad: // t.uiWindow.SetBorderless(false) } case toolkit.Grid: - switch a.Type { + switch a.ActionType { 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) + log(debugNow, "tWidget.boxC =", tParent.Name) + log(debugNow, "is there a tParent parent? =", tParent.parent) if (tWidget.boxC < 1) { - log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", tWhere.boxC) + log(debugNow, "Can not delete from Box. already empty. tWidget.boxC =", tParent.boxC) return } tWidget.uiBox.Delete(0) @@ -244,10 +236,10 @@ func uiDelete(a *toolkit.Action) { // this didn't work: // tWidget.uiControl.Disable() // sleep(.8) - // tWhere.uiBox.Append(tWidget.uiControl, stretchy) + // tParent.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) + log(debugError, "TODO: need to implement uiDelete() for a =", a.ActionType) + log(debugError, "TODO: need to implement uiDelete() for where =", a.ParentId) + log(debugError, "TODO: need to implement uiDelete() for widget =", a.WidgetId) } } diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go index 707a87f..b03ee9c 100644 --- a/toolkit/andlabs/add.go +++ b/toolkit/andlabs/add.go @@ -8,40 +8,46 @@ import ( ) 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) + log(b, "actionDump() Widget.Type =", a.ActionType) + log(b, "actionDump() Widget.S =", a.S) + log(b, "actionDump() Widget.I =", a.I) + log(b, "actionDump() WidgetId =", a.WidgetId) + log(b, "actionDump() ParentId =", a.ParentId) } func add(a *toolkit.Action) { - if (a.Widget == nil) { - log(debugError, "add() error. w.Widget == nil") + if (andlabs[a.WidgetId] != nil) { + log(debugError, "add() error. can't make a widget that already exists. id =", a.WidgetId) actionDump(debugError, a) return } + if (a.WidgetId == 0) { + log(debugError, "add() error. w.WidgetId == 0") + actionDump(debugError, a) + return + } + // for now, window gets handled without checking where == nil) - if (a.Widget.Type == toolkit.Window) { + if (a.WidgetType == toolkit.Window) { doWindow(a) return } - t := mapToolkits[a.Where] - if (t == nil) { + if (andlabs[a.ParentId] == 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.") + log(debugError, "add() Widget.Name =", a.Name) + log(debugError, "add() Widget.Type =", a.WidgetType) + log(debugError, "ERROR add() ERROR a.Parent map to t == nil. WidgetId =", a.WidgetId, "ParentId =", a.ParentId) + exit("can not add()") return } - switch a.Widget.Type { + switch a.WidgetType { case toolkit.Window: doWindow(a) return case toolkit.Tab: - doTab(a) + newTab(a) return case toolkit.Label: newLabel(a) @@ -80,7 +86,7 @@ func add(a *toolkit.Action) { newImage(a) return default: - log(debugError, "add() error TODO: ", a.Widget.Type, a.Widget.Name) + log(debugError, "add() error TODO: ", a.WidgetType, a.Name) } } @@ -109,18 +115,34 @@ func add(a *toolkit.Action) { // -- (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) + log(debugAction, "place() START", a.WidgetType, a.Name) + + // add the structure to the array + if (andlabs[a.WidgetId] == nil) { + log(logInfo, "newTab() MAPPED", a.WidgetId, a.ParentId) + andlabs[a.WidgetId] = newt + newt.Type = a.WidgetType + } else { + log(debugError, "newTab() DO WHAT?", a.WidgetId, a.ParentId) + log(debugError, "THIS IS BAD") + } if (newt.uiControl == nil) { - log(debugError, "place() ERROR uiControl == nil", a.Where.Type, a.Where.Name) + log(debugError, "place() ERROR uiControl == nil", a.ParentId) return false } - switch a.Where.Type { + where := andlabs[a.ParentId] + if (where == nil) { + log(debugError, "place() ERROR where == nil", a.ParentId) + return false + } + + switch 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 Parent X,Y =", a.X, a.Y) + newt.gridX = a.X + newt.gridY = a.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, @@ -130,14 +152,14 @@ func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool { 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) + log(debugGrid, "add() hack Group to use this as the box?", a.Name, a.WidgetType) t.uiBox = newt.uiBox } else { t.uiBox.Append(newt.uiControl, stretchy) } return true case toolkit.Tab: - t.uiBox.Append(newt.uiControl, stretchy) + t.uiTab.Append(a.Text, newt.uiControl) t.boxC += 1 return true case toolkit.Box: @@ -148,7 +170,7 @@ func place(a *toolkit.Action, t *andlabsT, newt *andlabsT) bool { t.uiWindow.SetChild(newt.uiControl) return true default: - log(debugError, "add() how?", a.Where.Type) + log(debugError, "add() how?", a.ParentId) } return false } diff --git a/toolkit/andlabs/box.go b/toolkit/andlabs/box.go index cc7451d..527041d 100644 --- a/toolkit/andlabs/box.go +++ b/toolkit/andlabs/box.go @@ -9,19 +9,17 @@ import ( // make new Box here func newBox(a *toolkit.Action) { - w := a.Widget - parentW := a.Where - log(debugToolkit, "newBox()", w.Name) + log(debugToolkit, "newBox()", a.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "newBox() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "newBox() toolkit struct == nil. name=", a.Name) listMap(debugToolkit) } - newt := t.rawBox(w.Name, a.B) + newt := t.rawBox(a.Text, a.B) newt.boxC = 0 place(a, t, newt) - mapWidgetsToolkits(a, newt) + andlabs[a.WidgetId] = newt } // make new Box using andlabs/ui diff --git a/toolkit/andlabs/button.go b/toolkit/andlabs/button.go index 741ce3a..1f9fdaf 100644 --- a/toolkit/andlabs/button.go +++ b/toolkit/andlabs/button.go @@ -10,27 +10,27 @@ import ( func newButton(a *toolkit.Action) { var t, newt *andlabsT var b *ui.Button - w := a.Widget - log(debugToolkit, "newButton()", w.Name) + log(debugToolkit, "newButton()", a.Name) - t = mapToolkits[a.Where] + t = andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "newButton() toolkit struct == nil. name=", a.Where.Name, w.Name) + log(debugToolkit, "newButton() toolkit struct == nil. name=", a.Name) return } newt = new(andlabsT) - b = ui.NewButton(w.Name) + b = ui.NewButton(a.Text) newt.uiButton = b newt.uiControl = b - newt.tw = w + newt.tw = a.Widget + newt.Type = a.WidgetType newt.parent = t b.OnClicked(func(*ui.Button) { - newt.commonChange(newt.tw) + newt.commonChange(newt.tw, a.WidgetId) }) place(a, t, newt) - mapWidgetsToolkits(a, newt) + // mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/checkbox.go b/toolkit/andlabs/checkbox.go index 2ff7ccf..f73a284 100644 --- a/toolkit/andlabs/checkbox.go +++ b/toolkit/andlabs/checkbox.go @@ -6,10 +6,13 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT { - log(debugToolkit, "newCheckbox()", w.Name, w.Type) +func (t *andlabsT) newCheckbox(a *toolkit.Action) *andlabsT { var newt andlabsT + w := a.Widget + log(debugToolkit, "newCheckbox()", w.Name, w.Type) newt.tw = w + newt.Type = w.Type + newt.wId = a.WidgetId newt.uiCheckbox = ui.NewCheckbox(w.Name) newt.uiControl = newt.uiCheckbox @@ -17,7 +20,7 @@ func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT { newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { newt.tw.B = newt.checked() log(debugChange, "val =", newt.tw.B) - newt.commonChange(newt.tw) + newt.commonChange(newt.tw, a.WidgetId) }) return &newt @@ -28,16 +31,13 @@ func (t *andlabsT) checked() bool { } func newCheckbox(a *toolkit.Action) { - w := a.Widget - parentW := a.Where - log(debugToolkit, "newCheckbox()", w.Name) + log(debugToolkit, "newCheckbox()", a.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { listMap(debugError) return } - newt := t.newCheckbox(w) + newt := t.newCheckbox(a) place(a, t, newt) - mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/combobox.go b/toolkit/andlabs/combobox.go index e200b3b..e7d51a7 100644 --- a/toolkit/andlabs/combobox.go +++ b/toolkit/andlabs/combobox.go @@ -6,11 +6,14 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func (t *andlabsT) newCombobox(w *toolkit.Widget) *andlabsT { +func (t *andlabsT) newCombobox(a *toolkit.Action) *andlabsT { var newt andlabsT + w := a.Widget log(debugToolkit, "newCombobox() START", w.Name) newt.tw = w + newt.wId = a.WidgetId + newt.Type = w.Type s := ui.NewEditableCombobox() newt.uiEditableCombobox = s newt.uiControl = s @@ -21,7 +24,7 @@ func (t *andlabsT) newCombobox(w *toolkit.Widget) *andlabsT { s.OnChanged(func(spin *ui.EditableCombobox) { newt.tw.S = spin.Text() - newt.commonChange(newt.tw) + newt.commonChange(newt.tw, a.WidgetId) }) return &newt @@ -42,17 +45,14 @@ func (t *andlabsT) AddComboboxName(title string) { } func newCombobox(a *toolkit.Action) { - w := a.Widget - parentW := a.Where - log(debugToolkit, "newCombobox()", w.Name) + log(debugToolkit, "newCombobox()", a.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "newCombobox() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "newCombobox() toolkit struct == nil. name=", a.Name) listMap(debugToolkit) return } - newt := t.newCombobox(w) + newt := t.newCombobox(a) place(a, t, newt) - mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go index 5cfaaa5..5e1b0fb 100644 --- a/toolkit/andlabs/common.go +++ b/toolkit/andlabs/common.go @@ -4,7 +4,7 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func (t *andlabsT) commonChange(tw *toolkit.Widget) { +func (t *andlabsT) commonChange(tw *toolkit.Widget, wId int) { 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") @@ -15,23 +15,21 @@ func (t *andlabsT) commonChange(tw *toolkit.Widget) { return } tw.Custom() - log(debugChange, "commonChange() END Widget.Custom()", t.tw.Name, t.tw.Type) -} -func dump(p *toolkit.Widget, c *toolkit.Widget, b bool) { - log(b, "Parent:") - pt := mapToolkits[p] - if (pt == nil) { - log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) + if (andlabs[wId] == nil) { + log(debugError, "commonChange() ERROR: wId map == nil", wId) return } - pt.Dump(b) + sendToChan(wId) + + log(debugChange, "commonChange() END Widget.Custom()", t.tw.Name, t.tw.Type) +} - log(b, "Child:") - ct := mapToolkits[c] - if (ct == nil) { - log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) +func sendToChan(i int) { + if (callback == nil) { + log(debugError, "commonChange() SHOULD SEND int back here, but callback == nil", i) return } - ct.Dump(b) + log(debugError, "commonChange() Running callback() i =", i) + callback(i) } diff --git a/toolkit/andlabs/debug.go b/toolkit/andlabs/debug.go index 7d69485..a581657 100644 --- a/toolkit/andlabs/debug.go +++ b/toolkit/andlabs/debug.go @@ -90,6 +90,7 @@ func widgetDump(b bool, w *toolkit.Widget) { return } + /* log(b, "widget.Name =", w.Name) log(b, "widget.Type =", w.Type) log(b, "widget.Custom =", w.Custom) @@ -99,6 +100,7 @@ func widgetDump(b bool, w *toolkit.Widget) { log(b, "widget.Height =", w.Height) log(b, "widget.X =", w.X) log(b, "widget.Y =", w.Y) + */ } /* diff --git a/toolkit/andlabs/delete.go b/toolkit/andlabs/delete.go index d335324..2d2e04a 100644 --- a/toolkit/andlabs/delete.go +++ b/toolkit/andlabs/delete.go @@ -6,21 +6,21 @@ import "git.wit.org/wit/gui/toolkit" // delete the child widget from the parent // p = parent, c = child -func destroy(p *toolkit.Widget, c *toolkit.Widget) { - log(true, "delete()", c.Name, c.Type) +func destroy(pId int, cId int) { + log(true, "delete()", pId, cId) - pt := mapToolkits[p] - ct := mapToolkits[c] + pt := andlabs[pId] + ct := andlabs[cId] if (ct == nil) { - log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", c.Name, c.Type) + log(true, "delete FAILED (ct = mapToolkit[c] == nil) for c", pId, cId) // this pukes out a whole universe of shit // listMap() return } - switch ct.tw.Type { + switch ct.Type { case toolkit.Button: - log(true, "Should delete Button here:", c.Name) + log(true, "Should delete Button here:", ct.Name) log(true, "Parent:") pt.Dump(true) log(true, "Child:") @@ -38,16 +38,15 @@ func destroy(p *toolkit.Widget, c *toolkit.Widget) { } case toolkit.Window: - log(true, "Should delete Window here:", c.Name) + log(true, "Should delete Window here:", ct.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.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:") ct.Dump(true) - log(true, "Fuckit, let's destroy a button", c.Name, c.Type) + log(true, "Fuckit, let's destroy a button") if (ct.uiButton != nil) { pt.uiBox.Delete(4) ct.uiButton.Destroy() diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go index eac1324..d020ed8 100644 --- a/toolkit/andlabs/dropdown.go +++ b/toolkit/andlabs/dropdown.go @@ -6,11 +6,14 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT { +func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT { var newt andlabsT - log(debugToolkit, "gui.Toolbox.newDropdown() START", w.Name) + w := a.Widget + log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Name) newt.tw = w + newt.Type = w.Type + newt.wId = a.WidgetId s := ui.NewCombobox() newt.uiCombobox = s newt.uiControl = s @@ -26,7 +29,7 @@ func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT { newt.text = "error" } newt.tw.S = newt.val[i] - newt.commonChange(newt.tw) + newt.commonChange(newt.tw, a.WidgetId) }) return &newt @@ -53,9 +56,9 @@ func (t *andlabsT) SetDropdown(i int) { } func AddDropdownName(a *toolkit.Action) { - log(debugToolkit, "gui.andlabs.AddDropdownName()", a.Widget.Name, "add:", a.S) + log(debugToolkit, "gui.andlabs.AddDropdownName()", a.WidgetId, "add:", a.S) - t := mapToolkits[a.Widget] + t := andlabs[a.WidgetId] if (t == nil) { log(debugToolkit, "go.andlabs.AddDropdownName() toolkit struct == nil. name=", a.Widget.Name, a.S) listMap(debugToolkit) @@ -64,31 +67,30 @@ func AddDropdownName(a *toolkit.Action) { t.AddDropdownName(a.S) } -func SetDropdownName(w *toolkit.Widget, s string) { - log(debugChange, "gui.andlabs.SetDropdown()", w.Name, ",", s) +func SetDropdownName(a *toolkit.Action, s string) { + log(debugChange, "gui.andlabs.SetDropdown()", a.WidgetId, ",", s) - t := mapToolkits[w] + t := andlabs[a.WidgetId] if (t == nil) { - log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", w.Name, s) + log(debugError, "ERROR: SetDropdown() FAILED mapToolkits[w] == nil. name=", a.WidgetId, s) listMap(debugError) return } t.SetDropdown(1) + // TODO: send back to wit/gui goroutine with the chan t.tw.S = s } func newDropdown(a *toolkit.Action) { - w := a.Widget - parentW := a.Where - log(debugToolkit, "gui.andlabs.newDropdown()", w.Name) + log(debugToolkit, "gui.andlabs.newDropdown()", a.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", a.WidgetId) listMap(debugToolkit) return } - newt := t.newDropdown(w) + newt := t.newDropdown(a) place(a, t, newt) - mapWidgetsToolkits(a, newt) + // mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/grid.go b/toolkit/andlabs/grid.go index f009ab3..be05b70 100644 --- a/toolkit/andlabs/grid.go +++ b/toolkit/andlabs/grid.go @@ -14,9 +14,7 @@ import ( // ----------------------------- func newGrid(a *toolkit.Action) { var newt *andlabsT - log(debugToolkit, "newGrid()", a.Widget.Name, "to", a.Where.Type) - - t := mapToolkits[a.Where] + log(debugToolkit, "newGrid()", a.WidgetId, "to", a.ParentId) newt = new(andlabsT) @@ -24,9 +22,10 @@ func newGrid(a *toolkit.Action) { newt.uiGrid = c newt.uiControl = c newt.tw = a.Widget + newt.Type = toolkit.Grid newt.gridX = 0 newt.gridY = 0 + t := andlabs[a.ParentId] place(a, t, newt) - mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/group.go b/toolkit/andlabs/group.go index a44c5b6..0769151 100644 --- a/toolkit/andlabs/group.go +++ b/toolkit/andlabs/group.go @@ -9,17 +9,15 @@ import ( func newGroup(a *toolkit.Action) { w := a.Widget - parentW := a.Where log(debugToolkit, "NewGroup()", w.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "NewGroup() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "NewGroup() toolkit struct == nil. name=", w.Name) listMap(debugToolkit) } newt := t.rawGroup(w.Name) place(a, t, newt) - mapWidgetsToolkits(a, newt) } // make new Group here @@ -34,13 +32,5 @@ func (t *andlabsT) rawGroup(title string) *andlabsT { newt.uiGroup = g newt.uiControl = g -// hbox := ui.NewVerticalBox() -// hbox.SetPadded(padded) -// g.SetChild(hbox) - -// newt.uiBox = hbox -// newt.uiWindow = t.uiWindow -// newt.uiTab = t.uiTab - return &newt } diff --git a/toolkit/andlabs/image.go b/toolkit/andlabs/image.go index d16f711..a3d1cb6 100644 --- a/toolkit/andlabs/image.go +++ b/toolkit/andlabs/image.go @@ -10,17 +10,15 @@ import ( // make new Image here func newImage(a *toolkit.Action) { w := a.Widget - parentW := a.Where log(debugToolkit, "newImage()", w.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "newImage() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "newImage() toolkit struct == nil. name=", w.Name) listMap(debugToolkit) } newt := t.rawImage(w.Name) place(a, t, newt) - mapWidgetsToolkits(a, newt) } // make new Image using andlabs/ui diff --git a/toolkit/andlabs/label.go b/toolkit/andlabs/label.go index 144c2c1..c6bd670 100644 --- a/toolkit/andlabs/label.go +++ b/toolkit/andlabs/label.go @@ -12,7 +12,7 @@ func newLabel(a *toolkit.Action) { w := a.Widget log(debugToolkit, "NewLabel()", w.Name) - t := mapToolkits[a.Where] + t := andlabs[a.ParentId] if (t == nil) { listMap(debugError) log(debugError, "ERROR newLabel() listMap()") @@ -30,5 +30,4 @@ func newLabel(a *toolkit.Action) { newt.uiControl = c place(a, t, newt) - mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/log.go b/toolkit/andlabs/log.go index 43b90cb..77b10e2 100644 --- a/toolkit/andlabs/log.go +++ b/toolkit/andlabs/log.go @@ -1,137 +1,25 @@ -// -// version v1.2 -// -// I like things to be easy. -// -// this means all the log settings are in one place. it should allow -// things to be over-ridden externally to the library -// but still allow command line --args to pass debugging settings -// -// I also have a generic sleep() and exit() in here because it's simple -// -// Usage: -// -// log("something", foo, bar) -// var DEBUG bool = true -// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing -// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging! -// package main import ( - "os" - "runtime" - "runtime/pprof" - golog "log" - "time" - "reflect" - "github.com/davecgh/go-spew/spew" - // "net" + witlog "git.wit.org/wit/gui/log" ) -var LOGOFF bool = false // turn this off, all logging stops -var WARN bool -var INFO bool +// various debugging flags +var logNow bool = true // useful for active development +var logError bool = true +var logWarn bool = false +var logInfo bool = false +var logVerbose bool = false -type spewt struct { - a bool +func log(a ...any) { + witlog.Where = "wit/gui/andlabs" + witlog.Log(a...) } -var SPEW spewt - - -/* - sleep() # you know what this does? sleeps for 1 second. yep. dump. easy. - sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second -*/ func sleep(a ...any) { - if (a == nil) { - time.Sleep(time.Second) - return - } - - log(true, "sleep", a[0]) - - switch a[0].(type) { - case int: - time.Sleep(time.Duration(a[0].(int)) * time.Second) - case float64: - time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond) - default: - log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0])) - } + witlog.Sleep(a...) } -/* - exit() # yep. exits. I guess everything must be fine - exit(3) # I guess 3 it is then - exit("dont like apples") # ok. I'll make a note of that -*/ func exit(a ...any) { - log(true, "exit", a) - //if (a) { - // os.Exit(a) - //} - os.Exit(0) -} - -/* - I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever. - I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this - implementation is probably faster than all of those because you just set one bool to FALSE - and it all stops. - Sometimes I need to capture to stdout, sometimes stdout can't - work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread - over 8 million references in every .go file. I'm tapping out and putting - it in one place. here it is. Also, this makes having debug levels really fucking easy. - You can define whatever level of logging you want from anywhere (command line) etc. - - log() # doesn't do anything - log(stuff) # sends it to whatever log you define in a single place. here is the place -*/ - -func log(a ...any) { - if (LOGOFF) { - return - } - - if (a == nil) { - return - } - var tbool bool - if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) { - if (a[0] == false) { - return - } - a[0] = "GUI/Toolkit/Andlabs" - } - - if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) { - // a = a[1:] - a[0] = "GUI/Toolkit/Andlabs" - if (debugToolkit) { - scs := spew.ConfigState{MaxDepth: 1} - scs.Dump(a) - // spew.Dump(a) - } - return - } - - golog.Println(a...) -} - -func loggo() { - pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) - golog.Println("runtime.NumGoroutine() = ", runtime.NumGoroutine()) -} - -func logindent(depth int, format string, a ...interface{}) { - var tabs string - for i := 0; i < depth; i++ { - tabs = tabs + format - } - - // newFormat := tabs + strconv.Itoa(depth) + " " + format - newFormat := tabs + format - log(debugToolkit, newFormat, a) + witlog.Exit(a...) } diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go index c719352..1ad7a60 100644 --- a/toolkit/andlabs/main.go +++ b/toolkit/andlabs/main.go @@ -2,7 +2,7 @@ package main import ( "embed" - "git.wit.org/wit/gui/toolkit" + // "git.wit.org/wit/gui/toolkit" "github.com/andlabs/ui" // the _ means we only need this for the init() @@ -43,8 +43,10 @@ func Init() { // log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true") setDefaultBehavior(true) - mapWidgets = make(map[*andlabsT]*toolkit.Widget) - mapToolkits = make(map[*toolkit.Widget]*andlabsT) + // mapWidgets = make(map[*andlabsT]*toolkit.Widget) + // mapToolkits = make(map[*toolkit.Widget]*andlabsT) + + andlabs = make(map[int]*andlabsT) } // TODO: properly exit the plugin since Quit() doesn't do it diff --git a/toolkit/andlabs/plugin.go b/toolkit/andlabs/plugin.go index 60cdbfa..6c2dd76 100644 --- a/toolkit/andlabs/plugin.go +++ b/toolkit/andlabs/plugin.go @@ -31,43 +31,55 @@ func Action(a *toolkit.Action) { rawAction(a) } + if (callback == nil) { + if (a.Callback != nil) { + log(debugNow, "setting Callback", a.Callback) + callback = a.Callback + } + } + // f() Queue(f) } func rawAction(a *toolkit.Action) { - log(debugAction, "Action() START a.Type =", a.Type) + log(debugAction, "Action() START a.ActionType =", a.ActionType) log(debugAction, "Action() START a.S =", a.S) log(debugAction, "Action() START a.Widget =", a.Widget) - switch a.Type { + log(logInfo, "Action() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId) + switch a.WidgetType { + case toolkit.Flag: + flag(a) + return + } + + switch a.ActionType { case toolkit.Add: add(a) case toolkit.Show: a.Widget.B = true - show(a.Widget) + show(a) case toolkit.Hide: a.Widget.B = false - show(a.Widget) + show(a) case toolkit.Enable: a.Widget.B = true - enable(a.Widget) + enable(a) case toolkit.Disable: a.Widget.B = false - enable(a.Widget) + enable(a) case toolkit.Get: setText(a) case toolkit.GetText: switch a.Widget.Type { case toolkit.Textbox: - t := mapToolkits[a.Widget] + t := andlabs[a.WidgetId] a.S = t.s } case toolkit.Set: setText(a) - case toolkit.SetFlag: - flag(a) case toolkit.SetText: setText(a) case toolkit.AddText: @@ -82,15 +94,13 @@ func rawAction(a *toolkit.Action) { pad(a) case toolkit.Delete: uiDelete(a) - case toolkit.Flag: - flag(a) case toolkit.Move: - log(debugNow, "attempt to move() =", a.Type, a.Widget) + log(debugNow, "attempt to move() =", a.ActionType, a.Widget) move(a) default: - log(debugError, "Action() Unknown =", a.Type, a.Widget) + log(debugError, "Action() Unknown =", a.ActionType, a.Widget) } - log(debugAction, "Action() END =", a.Type, a.Widget) + log(debugAction, "Action() END =", a.ActionType, a.Widget) } func flag(a *toolkit.Action) { @@ -122,70 +132,70 @@ func flag(a *toolkit.Action) { } func setText(a *toolkit.Action) { - w := a.Widget - if (w == nil) { - log(debugError, "setText error. w.Widget == nil") + t := andlabs[a.WidgetId] + if (t == nil) { + log(debugError, "setText error. andlabs[id] == nil", a.WidgetId) actionDump(debugError, a) return } - t := mapToolkits[w] - log(debugChange, "setText() Attempt on", w.Type, "with", a.S) + log(debugChange, "setText() Attempt on", t.Type, "with", a.S) - switch w.Type { + switch t.Type { case toolkit.Window: t.uiWindow.SetTitle(a.S) case toolkit.Tab: case toolkit.Group: t.uiGroup.SetTitle(a.S) case toolkit.Checkbox: - switch a.Type { + switch a.ActionType { case toolkit.SetText: t.uiCheckbox.SetText(a.S) case toolkit.Get: - w.B = t.uiCheckbox.Checked() + t.tw.B = t.uiCheckbox.Checked() case toolkit.Set: - t.uiCheckbox.SetChecked(a.B) - w.B = a.B + // TODO: commented out while working on chan + // t.uiCheckbox.SetChecked(a.B) + t.tw.B = a.B default: - log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name) } case toolkit.Textbox: - switch a.Type { + switch a.ActionType { case toolkit.Set: t.uiMultilineEntry.SetText(a.S) case toolkit.SetText: t.uiMultilineEntry.SetText(a.S) case toolkit.Get: - w.S = t.s + t.tw.S = t.s case toolkit.GetText: - w.S = t.s + t.tw.S = t.s default: - log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name) } case toolkit.Label: t.uiLabel.SetText(a.S) case toolkit.Button: t.uiButton.SetText(a.S) case toolkit.Slider: - switch a.Type { + switch a.ActionType { case toolkit.Get: - w.I = t.uiSlider.Value() + t.tw.I = t.uiSlider.Value() case toolkit.Set: t.uiSlider.SetValue(a.I) default: - log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name) } case toolkit.Spinner: - switch a.Type { + switch a.ActionType { case toolkit.Get: - w.I = t.uiSpinbox.Value() + t.tw.I = t.uiSpinbox.Value() case toolkit.Set: t.uiSpinbox.SetValue(a.I) default: - log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name) } case toolkit.Dropdown: - switch a.Type { + switch a.ActionType { case toolkit.AddText: AddDropdownName(a) case toolkit.Set: @@ -199,7 +209,7 @@ func setText(a *toolkit.Action) { log(debugChange, "i, s", i, s) if (a.S == s) { t.uiCombobox.SetSelected(i) - log(debugChange, "setText() Dropdown worked.", w.S) + log(debugChange, "setText() Dropdown worked.", t.tw.S) return } } @@ -213,14 +223,14 @@ func setText(a *toolkit.Action) { t.uiCombobox.SetSelected(i) } case toolkit.Get: - w.S = t.s + t.tw.S = t.s case toolkit.GetText: - w.S = t.s + t.tw.S = t.s default: - log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name) } case toolkit.Combobox: - switch a.Type { + switch a.ActionType { case toolkit.AddText: t.AddComboboxName(a.S) case toolkit.Set: @@ -230,13 +240,13 @@ func setText(a *toolkit.Action) { t.uiEditableCombobox.SetText(a.S) t.s = a.S case toolkit.Get: - w.S = t.s + t.tw.S = t.s case toolkit.GetText: - w.S = t.s + t.tw.S = t.s default: - log(debugError, "setText() unknown", a.Type, "on checkbox", w.Name) + log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.tw.Name) } default: - log(debugError, "plugin Send() Don't know how to setText on", w.Type, "yet", a.Type) + log(debugError, "plugin Send() Don't know how to setText on", t.tw.Type, "yet", a.ActionType) } } diff --git a/toolkit/andlabs/slider.go b/toolkit/andlabs/slider.go index 181b258..5a16bff 100644 --- a/toolkit/andlabs/slider.go +++ b/toolkit/andlabs/slider.go @@ -7,19 +7,21 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT { - // make new node here - log(debugToolkit, w.Name, w.Type, w.X, w.Y) +func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT { var newt andlabsT + w := a.Widget + // log(debugToolkit, w.Name, w.Type, w.X, w.Y) - s := ui.NewSlider(w.X, w.Y) + s := ui.NewSlider(a.X, a.Y) newt.uiSlider = s newt.uiControl = s newt.tw = w + newt.Type = toolkit.Slider + newt.wId = a.WidgetId s.OnChanged(func(spin *ui.Slider) { newt.tw.I = newt.uiSlider.Value() - newt.commonChange(newt.tw) + newt.commonChange(newt.tw, a.WidgetId) }) return &newt @@ -28,17 +30,15 @@ func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT { func newSlider(a *toolkit.Action) { var newt *andlabsT w := a.Widget - parentW := a.Where log(debugToolkit, "newSlider()", w.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugError, "newSlider() ERROR toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugError, "newSlider() ERROR toolkit struct == nil. name=", w.Name) return } - w.X = a.X - w.Y = a.Y - newt = t.newSlider(w) + // w.X = a.X + // w.Y = a.Y + newt = t.newSlider(a) place(a, t, newt) - mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/spinner.go b/toolkit/andlabs/spinner.go index 6a47472..58e0934 100644 --- a/toolkit/andlabs/spinner.go +++ b/toolkit/andlabs/spinner.go @@ -7,19 +7,21 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { - // make new node here - log(debugToolkit, "newSpinner()", w.X, w.Y) +func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT { var newt andlabsT + w := a.Widget + // log(debugToolkit, "newSpinner()", w.X, w.Y) - s := ui.NewSpinbox(w.X, w.Y) + s := ui.NewSpinbox(a.X, a.Y) newt.uiSpinbox = s newt.uiControl = s newt.tw = w + newt.wId = a.WidgetId + newt.Type = toolkit.Spinner s.OnChanged(func(s *ui.Spinbox) { newt.tw.I = newt.uiSpinbox.Value() - newt.commonChange(newt.tw) + newt.commonChange(newt.tw, a.WidgetId) }) return &newt @@ -28,16 +30,12 @@ func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { func newSpinner(a *toolkit.Action) { var newt *andlabsT w := a.Widget - parentW := a.Where - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugError, "NewSpinner() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugError, "NewSpinner() toolkit struct == nil. name=", w.Name) return } - w.X = a.X - w.Y = a.Y - newt = t.newSpinner(w) + newt = t.newSpinner(a) place(a, t, newt) - mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go index 9b053af..1fb9a79 100644 --- a/toolkit/andlabs/structs.go +++ b/toolkit/andlabs/structs.go @@ -5,14 +5,19 @@ import "git.wit.org/wit/gui/toolkit" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +var andlabs map[int]*andlabsT +var callback func(int) + // stores the raw toolkit internals type andlabsT struct { - id string + wId int // widget ID + Type toolkit.WidgetType Name string // Type toolkit.WidgetType Width int Height int + tw *toolkit.Widget parent *andlabsT diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go index b0920ac..0753338 100644 --- a/toolkit/andlabs/tab.go +++ b/toolkit/andlabs/tab.go @@ -19,36 +19,43 @@ import ( once there is one. If you send a Window here, it will replace any existing tabs rather than adding a new one */ -func (t *andlabsT) newTab(name string) *andlabsT { +func (t *andlabsT) newTab(a *toolkit.Action) { // var w *ui.Window var newt *andlabsT - log(debugToolkit, "gui.toolkit.AddTab()") - - if (t.uiWindow == nil) { - log(debugToolkit, "gui.Toolkit.UiWindow == nil. I can't add a toolbar without window") - return nil - } + log(debugToolkit, "newTab() START", a.WidgetId, a.ParentId) if (t.uiTab == nil) { + if (t.uiWindow == nil) { + log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", a.WidgetId, a.ParentId) + return + } // this means you have to make a new tab - log(debugToolkit, "gui.toolkit.NewTab() GOOD. This should be the first tab:", name) - newt = rawTab(t.uiWindow, name) + log(debugToolkit, "newTab() GOOD. This should be the first tab:", a.WidgetId, a.ParentId) + newt = rawTab(t.uiWindow, a.Text) t.uiTab = newt.uiTab } else { // this means you have to append a tab - log(debugToolkit, "gui.toolkit.NewTab() GOOD. This should be an additional tab:", name) - newt = t.appendTab(name) + log(debugToolkit, "newTab() GOOD. This should be an additional tab:", a.WidgetId, a.ParentId) + newt = t.appendTab(a.Text) } - newt.Name = name + // add the structure to the array + if (andlabs[a.WidgetId] == nil) { + log(logInfo, "newTab() MAPPED", a.WidgetId, a.ParentId) + andlabs[a.WidgetId] = newt + newt.Type = a.Widget.Type + } else { + log(debugError, "newTab() DO WHAT?", a.WidgetId, a.ParentId) + log(debugError, "THIS IS BAD") + } + + newt.Name = a.Name log(debugToolkit, "t:") t.Dump(debugToolkit) log(debugToolkit, "newt:") newt.Dump(debugToolkit) - - return newt } // This sets _all_ the tabs to Margin = true @@ -64,29 +71,21 @@ func tabSetMargined(tab *ui.Tab, b bool) { func rawTab(w *ui.Window, name string) *andlabsT { var newt andlabsT - log(debugToolkit, "gui.toolkit.NewTab() ADD", name) + log(debugToolkit, "rawTab() START", name) if (w == nil) { - log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window") - log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window") - log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window") + log(debugError, "UiWindow == nil. I can't add a tab without a window") + log(debugError, "UiWindow == nil. I can't add a tab without a window") + log(debugError, "UiWindow == nil. I can't add a tab without a window") sleep(1) return nil } - log(debugToolkit, "gui.toolkit.AddTab() START name =", name) - tab := ui.NewTab() - w.SetMargined(margin) - hbox := ui.NewHorizontalBox() // this makes everything go along the horizon - hbox.SetPadded(padded) - tab.Append(name, hbox) - tabSetMargined(tab, margin) // TODO: run this in the right place(?) + tab := ui.NewTab() w.SetChild(tab) - - newt.uiWindow = w newt.uiTab = tab newt.uiControl = tab - newt.uiBox = hbox + log(debugToolkit, "rawTab() END", name) return &newt } @@ -120,20 +119,14 @@ func (t *andlabsT) appendTab(name string) *andlabsT { } func newTab(a *toolkit.Action) { - parentW := a.Where - w := a.Widget - var newt *andlabsT - log(debugToolkit, "gui.andlabs.NewTab()", w.Name) + // w := a.Widget + log(debugToolkit, "newTab()", a.ParentId) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "go.andlabs.NewTab() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "newTab() parent toolkit == nil. new tab can not be made =", a.ParentId) + log(debugToolkit, "look for a window? check for an existing tab?") return } - newt = t.newTab(w.Name) - mapWidgetsToolkits(a, newt) -} - -func doTab(a *toolkit.Action) { - newTab(a) + t.newTab(a) } diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go index cff61f2..ef39d33 100644 --- a/toolkit/andlabs/textbox.go +++ b/toolkit/andlabs/textbox.go @@ -17,6 +17,7 @@ func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT { newt.Name = w.Name newt.tw = w + newt.Type = toolkit.Textbox c.OnChanged(func(spin *ui.MultilineEntry) { t.s = spin.Text() @@ -29,16 +30,14 @@ func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT { func newTextbox(a *toolkit.Action) { w := a.Widget - parentW := a.Where log(debugToolkit, "newCombobox()", w.Name) - t := mapToolkits[parentW] + t := andlabs[a.ParentId] if (t == nil) { - log(debugToolkit, "newCombobox() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "newCombobox() toolkit struct == nil. name=", w.Name) listMap(debugToolkit) return } newt := t.newTextbox(w) place(a, t, newt) - mapWidgetsToolkits(a, newt) } diff --git a/toolkit/andlabs/widget.go b/toolkit/andlabs/widget.go index e4a2bb7..45c584a 100644 --- a/toolkit/andlabs/widget.go +++ b/toolkit/andlabs/widget.go @@ -1,69 +1,24 @@ package main import ( - "git.wit.org/wit/gui/toolkit" + // "git.wit.org/wit/gui/toolkit" ) // This is a map between the widgets in wit/gui and the internal structures of gocui -var mapWidgets map[*andlabsT]*toolkit.Widget -var mapToolkits map[*toolkit.Widget]*andlabsT +// var mapWidgets map[*andlabsT]*toolkit.Widget +// var mapToolkits map[*toolkit.Widget]*andlabsT // This lists out the known mappings // deprecate and use instead the GUI interface func listMap(b bool) { log(b, "listMap() disabled HERE. output too big") return - for t, w := range mapWidgets { - log(b, "andlabs =", t.Name, "widget =", w.Name) - } log(b, "listMap() HERE mapToolkits()") - for w, t := range mapToolkits { - log(b, "andlabs =", t, "widget =", w.Name) + for i, t := range andlabs { + log(b, "andlabs =", t, "widgetId =", i) t.Dump(b) } log(b, "listMap() HERE mapWidgets()") log(b, "listMap() HERE FIXME. output too big") } - -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 - mapWidgets[t] = w - return - } - - if (mapToolkits[w] != nil) { - tw := mapToolkits[w] - if (tw == nil) { - // logic corruption somewhere? Have you been deleting things recently? - log(true, "mapToolkits[w] is set, but mapWidgets[t] is nil") - panic("WTF mapWidgets[t] == nil") - } - log(debugToolkit, "mapToolkits[w] is", tw) - if (tw == nil) { - log(debugError, "BAD map? mapWidgets[w] tw == nil") - } else { - log(debugError, "BAD map? mapWidgets[w] is", tw) - tw.Dump(debugError) - } - } - - if (mapWidgets[t] != nil) { - wt := mapWidgets[t] - if (mapToolkits[w] == nil) { - // logic corruption somewhere? Have you been deleting things recently? - log(true, "mapWidgets[t] is set, but mapToolkits[w] is nil") - panic("WTF mapToolkits[w] == nil") - } - if (wt == nil) { - log(debugError, "BAD map? mapWidgets[t] wt == nil") - } else { - log(debugError, "BAD map? mapWidgets[t] is", wt) - widgetDump(debugError, wt) - } - } - log(debugToolkit, "map of widget worked", w.Type, ",", w.Name) -} diff --git a/toolkit/andlabs/window.go b/toolkit/andlabs/window.go index 9181d5f..2fee729 100644 --- a/toolkit/andlabs/window.go +++ b/toolkit/andlabs/window.go @@ -19,7 +19,7 @@ func newWindow(a *toolkit.Action) { w := a.Widget var newt *andlabsT - log(debugToolkit, "toolkit NewWindow", w.Name, w.Width, w.Height) + // log(debugToolkit, "toolkit NewWindow", w.Name, w.Width, w.Height) if (w == nil) { log(debugToolkit, "wit/gui plugin error. widget == nil") @@ -27,13 +27,15 @@ func newWindow(a *toolkit.Action) { } newt = new(andlabsT) newt.tw = w + newt.Type = toolkit.Window + newt.wId = a.WidgetId // menubar bool is if the OS defined border on the window should be used - win := ui.NewWindow(w.Name, w.Width, w.Height, menubar) + win := ui.NewWindow(w.Name, a.Width, a.Height, menubar) win.SetBorderless(canvas) win.SetMargined(margin) win.OnClosing(func(*ui.Window) bool { - newt.commonChange(newt.tw) + newt.commonChange(newt.tw, a.WidgetId) return true }) win.Show() @@ -42,16 +44,17 @@ func newWindow(a *toolkit.Action) { // newt.UiWindowBad = win // deprecate this as soon as possible newt.Name = w.Name - mapWidgetsToolkits(a, newt) + andlabs[a.WidgetId] = newt return } func (t *andlabsT) SetWindowTitle(title string) { log(debugToolkit, "toolkit NewWindow", t.Name, "title", title) win := t.uiWindow - if (win != nil) { - win.SetTitle(title) + if (win == nil) { + log(debugError, "Error: no window", t.wId) } else { + win.SetTitle(title) log(debugToolkit, "Setting the window title", title) } } |
