debian/nocui/action.go

155 lines
3.6 KiB
Go
Raw Permalink Normal View History

2024-01-01 16:11:54 -06:00
package main
import (
"go.wit.com/log"
"go.wit.com/gui/widget"
2024-01-01 16:11:54 -06:00
)
func (n *node) show(b bool) {
}
func (n *node) enable(b bool) {
}
func (n *node) pad(at widget.ActionType) {
2024-01-01 16:11:54 -06:00
switch n.WidgetType {
case widget.Group:
2024-01-01 16:11:54 -06:00
switch at {
case widget.Margin:
2024-01-01 16:11:54 -06:00
// SetMargined(true)
case widget.Unmargin:
2024-01-01 16:11:54 -06:00
// SetMargined(false)
case widget.Pad:
2024-01-01 16:11:54 -06:00
// SetMargined(true)
case widget.Unpad:
2024-01-01 16:11:54 -06:00
// SetMargined(false)
}
case widget.Tab:
case widget.Window:
case widget.Grid:
case widget.Box:
case widget.Textbox:
log.Log(ERROR, "TODO: implement ActionType =", at)
2024-01-01 16:11:54 -06:00
default:
log.Log(ERROR, "TODO: implement pad() for", at)
2024-01-01 16:11:54 -06:00
}
}
func (n *node) move(newParent *node) {
p := n.parent
switch p.WidgetType {
case widget.Group:
case widget.Tab:
2024-01-01 16:11:54 -06:00
// tabSetMargined(tParent.uiTab, true)
case widget.Window:
2024-01-01 16:11:54 -06:00
// t.uiWindow.SetBorderless(false)
case widget.Grid:
2024-01-01 16:11:54 -06:00
// t.uiGrid.SetPadded(true)
case widget.Box:
log.Log(INFO, "TODO: move() where =", p.ParentId)
log.Log(INFO, "TODO: move() for widget =", n.WidgetId)
2024-01-01 16:11:54 -06:00
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)
2024-01-01 16:11:54 -06:00
}
}
func (n *node) Delete() {
p := n.parent
log.Log(NOW, "uiDelete()", n.WidgetId, "to", p.WidgetId)
2024-01-01 16:11:54 -06:00
switch p.WidgetType {
case widget.Group:
2024-01-01 16:11:54 -06:00
// tParent.uiGroup.SetMargined(true)
case widget.Tab:
2024-01-01 16:11:54 -06:00
// tabSetMargined(tParent.uiTab, true)
case widget.Window:
2024-01-01 16:11:54 -06:00
// t.uiWindow.SetBorderless(false)
case widget.Grid:
2024-01-01 16:11:54 -06:00
// t.uiGrid.SetPadded(true)
case widget.Box:
log.Log(NOW, "tWidget.boxC =", p.Name)
log.Log(NOW, "is there a tParent parent? =", p.parent)
2024-01-01 16:11:54 -06:00
// 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)
2024-01-01 16:11:54 -06:00
}
}
func doAction(a *widget.Action) {
log.Log(INFO, "doAction() START a.ActionType =", a.ActionType)
log.Log(INFO, "doAction() START a.S =", a.S)
2024-01-01 16:11:54 -06:00
if (a.ActionType == widget.InitToolkit) {
2024-01-01 16:11:54 -06:00
// 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.Log(INFO, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
2024-01-01 16:11:54 -06:00
switch a.WidgetType {
case widget.Root:
2024-01-01 16:11:54 -06:00
me.rootNode = addNode(a)
log.Log(INFO, "doAction() found rootNode")
2024-01-01 16:11:54 -06:00
return
case widget.Flag:
2024-01-01 16:11:54 -06:00
// flag(&a)
return
}
n := me.rootNode.findWidgetId(a.WidgetId)
switch a.ActionType {
case widget.Add:
2024-01-01 16:11:54 -06:00
addNode(a)
case widget.Show:
2024-01-01 16:11:54 -06:00
n.show(true)
case widget.Hide:
2024-01-01 16:11:54 -06:00
n.show(false)
case widget.Enable:
2024-01-01 16:11:54 -06:00
n.enable(true)
case widget.Disable:
2024-01-01 16:11:54 -06:00
n.enable(false)
case widget.Get:
2024-01-01 16:11:54 -06:00
// n.setText(a.S)
case widget.GetText:
2024-01-01 16:11:54 -06:00
switch a.WidgetType {
case widget.Textbox:
2024-01-01 16:11:54 -06:00
a.S = n.S
}
case widget.Set:
2024-01-01 16:11:54 -06:00
// n.setText(a.S)
case widget.SetText:
2024-01-01 16:11:54 -06:00
// n.setText(a.S)
case widget.AddText:
2024-01-01 16:11:54 -06:00
// n.setText(a.S)
case widget.Margin:
n.pad(widget.Unmargin)
case widget.Unmargin:
n.pad(widget.Margin)
case widget.Pad:
n.pad(widget.Pad)
case widget.Unpad:
n.pad(widget.Unpad)
case widget.Delete:
2024-01-01 16:11:54 -06:00
n.Delete()
case widget.Move:
log.Log(INFO, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
2024-01-01 16:11:54 -06:00
newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
log.Log(ERROR, "doAction() Unknown =", a.ActionType, a.WidgetType)
2024-01-01 16:11:54 -06:00
}
log.Log(INFO, "doAction() END =", a.ActionType, a.WidgetType)
2024-01-01 16:11:54 -06:00
}