diff options
| author | Jeff Carr <[email protected]> | 2023-04-27 21:11:00 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-04-27 21:11:00 -0500 |
| commit | 87b62c98a6ebd9d0e48850d1710de7f39aba41c8 (patch) | |
| tree | b5961b9d4841b20ff41ae95acac4d82459ee9d3f /toolkit/nocui/action.go | |
| parent | 9e285c7affa3257a46e85acde6dc64a9c781b728 (diff) | |
nocui: a template for porting new toolkits
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/nocui/action.go')
| -rw-r--r-- | toolkit/nocui/action.go | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/toolkit/nocui/action.go b/toolkit/nocui/action.go new file mode 100644 index 0000000..7b542ca --- /dev/null +++ b/toolkit/nocui/action.go @@ -0,0 +1,152 @@ +package main + +import ( + "git.wit.org/wit/gui/toolkit" +) + +func (n *node) show(b bool) { +} + +func (n *node) enable(b bool) { +} + +func (n *node) pad(at toolkit.ActionType) { + switch n.WidgetType { + case toolkit.Group: + switch at { + case toolkit.Margin: + // SetMargined(true) + case toolkit.Unmargin: + // SetMargined(false) + case toolkit.Pad: + // SetMargined(true) + case toolkit.Unpad: + // SetMargined(false) + } + case toolkit.Tab: + case toolkit.Window: + case toolkit.Grid: + case toolkit.Box: + case toolkit.Textbox: + log(logError, "TODO: implement ActionType =", at) + default: + log(logError, "TODO: implement pad() for", at) + } +} + +func (n *node) move(newParent *node) { + p := n.parent + + switch p.WidgetType { + case toolkit.Group: + case toolkit.Tab: + // tabSetMargined(tParent.uiTab, true) + case toolkit.Window: + // t.uiWindow.SetBorderless(false) + case toolkit.Grid: + // t.uiGrid.SetPadded(true) + case toolkit.Box: + log(logInfo, "TODO: move() where =", p.ParentId) + log(logInfo, "TODO: move() for widget =", n.WidgetId) + default: + log(logError, "TODO: need to implement move() for type =", n.WidgetType) + log(logError, "TODO: need to implement move() for where =", p.ParentId) + log(logError, "TODO: need to implement move() for widget =", n.WidgetId) + } +} + +func (n *node) Delete() { + p := n.parent + log(logNow, "uiDelete()", n.WidgetId, "to", p.WidgetId) + + switch p.WidgetType { + case toolkit.Group: + // tParent.uiGroup.SetMargined(true) + case toolkit.Tab: + // tabSetMargined(tParent.uiTab, true) + case toolkit.Window: + // t.uiWindow.SetBorderless(false) + case toolkit.Grid: + // t.uiGrid.SetPadded(true) + case toolkit.Box: + log(logNow, "tWidget.boxC =", p.Name) + log(logNow, "is there a tParent parent? =", p.parent) + // this didn't work: + // tWidget.uiControl.Disable() + // sleep(.8) + // tParent.uiBox.Append(tWidget.uiControl, stretchy) + default: + log(logError, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType) + log(logError, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType) + } +} + +func action(a toolkit.Action) { + log(logNow, "rawAction() START a.ActionType =", a.ActionType) + log(logNow, "rawAction() START a.S =", a.S) + + if (a.ActionType == toolkit.InitToolkit) { + // TODO: make sure to only do this once + // go uiMain.Do(func() { + // ui.Main(demoUI) + // go catchActionChannel() + // }) + // try doing this on toolkit load in init() + return + } + + log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId) + switch a.WidgetType { + case toolkit.Flag: + // flag(&a) + return + } + + n := rootNode.findWidgetId(a.WidgetId) + + switch a.ActionType { + case toolkit.Add: + // QueueMain(func() { + // add(a) + // }) + // sleep(.1) + case toolkit.Show: + n.show(true) + case toolkit.Hide: + n.show(false) + case toolkit.Enable: + n.enable(true) + case toolkit.Disable: + n.enable(false) + case toolkit.Get: + // n.setText(a.S) + case toolkit.GetText: + switch a.WidgetType { + case toolkit.Textbox: + a.S = n.S + } + case toolkit.Set: + // n.setText(a.S) + case toolkit.SetText: + // n.setText(a.S) + case toolkit.AddText: + // n.setText(a.S) + case toolkit.Margin: + n.pad(toolkit.Unmargin) + case toolkit.Unmargin: + n.pad(toolkit.Margin) + case toolkit.Pad: + n.pad(toolkit.Pad) + case toolkit.Unpad: + n.pad(toolkit.Unpad) + case toolkit.Delete: + n.Delete() + case toolkit.Move: + log(logNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType) + newParent := rootNode.findWidgetId(a.ParentId) + n.move(newParent) + default: + log(logError, "rawAction() Unknown =", a.ActionType, a.WidgetType) + } + log(logInfo, "rawAction() END =", a.ActionType, a.WidgetType) +} |
