summaryrefslogtreecommitdiff
path: root/nocui/action.go
diff options
context:
space:
mode:
Diffstat (limited to 'nocui/action.go')
-rw-r--r--nocui/action.go159
1 files changed, 47 insertions, 112 deletions
diff --git a/nocui/action.go b/nocui/action.go
index 892bd54..cf258c1 100644
--- a/nocui/action.go
+++ b/nocui/action.go
@@ -1,152 +1,87 @@
package main
+/*
+ a simple function to handle widget actions
+
+ You can tie this into your toolkit here.
+*/
+
import (
"go.wit.com/log"
"go.wit.com/gui/widget"
+ // "go.wit.com/gui/toolkits/tree"
)
-func (n *node) show(b bool) {
-}
-
-func (n *node) enable(b bool) {
-}
-
-func (n *node) pad(at widget.ActionType) {
- switch n.WidgetType {
- case widget.Group:
- switch at {
- case widget.Margin:
- // SetMargined(true)
- case widget.Unmargin:
- // SetMargined(false)
- case widget.Pad:
- // SetMargined(true)
- case widget.Unpad:
- // SetMargined(false)
- }
- case widget.Tab:
- case widget.Window:
- case widget.Grid:
- case widget.Box:
- case widget.Textbox:
- log.Log(ERROR, "TODO: implement ActionType =", at)
- default:
- log.Log(ERROR, "TODO: implement pad() for", at)
- }
-}
-
-func (n *node) move(newParent *node) {
- p := n.parent
-
- switch p.WidgetType {
- case widget.Group:
- case widget.Tab:
- // tabSetMargined(tParent.uiTab, true)
- case widget.Window:
- // t.uiWindow.SetBorderless(false)
- case widget.Grid:
- // t.uiGrid.SetPadded(true)
- case widget.Box:
- log.Log(INFO, "TODO: move() where =", p.ParentId)
- log.Log(INFO, "TODO: move() for widget =", n.WidgetId)
- default:
- log.Log(ERROR, "TODO: need to implement move() for type =", n.WidgetType)
- log.Log(ERROR, "TODO: need to implement move() for where =", p.ParentId)
- log.Log(ERROR, "TODO: need to implement move() for widget =", n.WidgetId)
- }
-}
-
-func (n *node) Delete() {
- p := n.parent
- log.Log(NOW, "uiDelete()", n.WidgetId, "to", p.WidgetId)
-
- switch p.WidgetType {
- case widget.Group:
- // tParent.uiGroup.SetMargined(true)
- case widget.Tab:
- // tabSetMargined(tParent.uiTab, true)
- case widget.Window:
- // t.uiWindow.SetBorderless(false)
- case widget.Grid:
- // t.uiGrid.SetPadded(true)
- case widget.Box:
- log.Log(NOW, "tWidget.boxC =", p.progname)
- log.Log(NOW, "is there a tParent parent? =", p.parent)
- // this didn't work:
- // tWidget.uiControl.Disable()
- // sleep(.8)
- // tParent.uiBox.Append(tWidget.uiControl, stretchy)
- default:
- log.Log(ERROR, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
- log.Log(ERROR, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType)
- }
-}
-
-func doAction(a *widget.Action) {
+func doAction(a widget.Action) {
log.Log(INFO, "doAction() START a.ActionType =", a.ActionType)
log.Log(INFO, "doAction() START a.ProgName =", a.ProgName)
- if (a.ActionType == widget.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()
+ if (a.ActionType == widget.ToolkitInit) {
return
}
log.Log(INFO, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case widget.Root:
- me.rootNode = addNode(a)
- log.Log(INFO, "doAction() found rootNode")
+ me.treeRoot = me.myTree.AddNode(&a)
+ log.Log(INFO, "doAction() found treeRoot")
return
- case widget.Flag:
- // flag(&a)
+ }
+
+ switch a.ActionType {
+ case widget.Add:
+ me.myTree.AddNode(&a)
return
}
- n := me.rootNode.findWidgetId(a.WidgetId)
+ n := me.treeRoot.FindWidgetId(a.WidgetId)
+ if n == nil {
+ log.Warn("FindId() n == nil", a.WidgetId, a.ActionType)
+ log.Warn("FindId() n == nil", a.WidgetId, a.ActionType)
+ log.Warn("FindId() n == nil", a.WidgetId, a.ActionType)
+ log.Warn("Aaaaa!, return")
+ return
+ }
switch a.ActionType {
- case widget.Add:
- addNode(a)
case widget.Show:
- n.show(true)
+ n.State.Visable = true
case widget.Hide:
- n.show(false)
+ n.State.Visable = false
case widget.Enable:
- n.enable(true)
+ n.State.Visable = true
case widget.Disable:
- n.enable(false)
+ n.State.Visable = false
case widget.Get:
- // n.setText(a.S)
+ log.Warn("value =", n.State.Value)
case widget.GetText:
- switch a.WidgetType {
- case widget.Textbox:
- a.Value = n.value
- }
+ log.Warn("value =", n.String())
case widget.Set:
- // n.setText(a.S)
+ n.State.Value = a.State.Value
case widget.SetText:
- // n.setText(a.S)
+ log.Warn("GOT TO SetText()", a.WidgetId)
+ log.Warn("GOT TO SetText()", a.WidgetId)
+ log.Warn("GOT TO SetText()", a.WidgetId)
+ log.Warn("GOT TO SetText()", a.WidgetId)
+ if n == nil {
+ log.Warn("HOT DIGGITY. n == nil")
+ }
+ n.State.Value = a.State.Value
case widget.AddText:
- // n.setText(a.S)
+ n.State.Strings = append(a.State.Strings, widget.GetString(a.State.Value))
case widget.Margin:
- n.pad(widget.Unmargin)
+ n.State.Pad = true
case widget.Unmargin:
- n.pad(widget.Margin)
+ n.State.Pad = false
case widget.Pad:
- n.pad(widget.Pad)
+ n.State.Pad = true
case widget.Unpad:
- n.pad(widget.Unpad)
+ n.State.Pad = false
case widget.Delete:
- n.Delete()
+ log.Warn("doAction() TODO: Delete()")
+ // n.Delete()
case widget.Move:
- log.Log(INFO, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
- newParent := me.rootNode.findWidgetId(a.ParentId)
- n.move(newParent)
+ log.Warn("doAction() TODO: Move()")
default:
log.Log(ERROR, "doAction() Unknown =", a.ActionType, a.WidgetType)
}