debian/nocui/action.go

154 lines
3.6 KiB
Go
Raw Normal View History

2024-01-01 16:11:54 -06:00
package main
import (
"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:
2024-01-01 16:11:54 -06:00
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 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:
2024-01-01 16:11:54 -06:00
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 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:
2024-01-01 16:11:54 -06:00
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 doAction(a *widget.Action) {
2024-01-01 16:11:54 -06:00
log(logNow, "doAction() START a.ActionType =", a.ActionType)
log(logNow, "doAction() START a.S =", a.S)
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(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case widget.Root:
2024-01-01 16:11:54 -06:00
me.rootNode = addNode(a)
log(logNow, "doAction() found rootNode")
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:
2024-01-01 16:11:54 -06:00
log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
log(logError, "doAction() Unknown =", a.ActionType, a.WidgetType)
}
log(logInfo, "doAction() END =", a.ActionType, a.WidgetType)
}