debian/andlabs/action.go

261 lines
6.0 KiB
Go
Raw Normal View History

2024-01-01 16:11:54 -06:00
package main
import (
"strconv"
"github.com/andlabs/ui"
"go.wit.com/log"
"go.wit.com/gui/widget"
2024-01-01 16:11:54 -06:00
)
func (n *node) show(b bool) {
if n.tk == nil {
return
}
if n.tk.uiControl == nil {
return
}
if (b) {
n.tk.uiControl.Show()
} else {
n.tk.uiControl.Hide()
}
}
func (n *node) enable(b bool) {
if n == nil {
panic("WHAT? enable was passed nil. How does this even happen?")
}
if n.tk == nil {
return
}
if n.tk.uiControl == nil {
return
}
if (b) {
n.tk.uiControl.Enable()
} else {
n.tk.uiControl.Disable()
}
}
func (n *node) pad(at widget.ActionType) {
log.Log(INFO, "pad() on WidgetId =", n.WidgetId)
2024-01-01 16:11:54 -06:00
t := n.tk
if (t == nil) {
log.Log(ERROR, "pad() toolkit struct == nil. for", n.WidgetId)
2024-01-01 16:11:54 -06:00
return
}
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
t.uiGroup.SetMargined(true)
case widget.Unmargin:
2024-01-01 16:11:54 -06:00
t.uiGroup.SetMargined(false)
case widget.Pad:
2024-01-01 16:11:54 -06:00
t.uiGroup.SetMargined(true)
case widget.Unpad:
2024-01-01 16:11:54 -06:00
t.uiGroup.SetMargined(false)
}
case widget.Tab:
2024-01-01 16:11:54 -06:00
switch at {
case widget.Margin:
2024-01-01 16:11:54 -06:00
tabSetMargined(t.uiTab, true)
case widget.Unmargin:
2024-01-01 16:11:54 -06:00
tabSetMargined(t.uiTab, false)
case widget.Pad:
2024-01-01 16:11:54 -06:00
tabSetMargined(t.uiTab, true)
case widget.Unpad:
2024-01-01 16:11:54 -06:00
tabSetMargined(t.uiTab, false)
}
case widget.Window:
2024-01-01 16:11:54 -06:00
switch at {
case widget.Margin:
2024-01-01 16:11:54 -06:00
t.uiWindow.SetMargined(true)
case widget.Unmargin:
2024-01-01 16:11:54 -06:00
t.uiWindow.SetMargined(false)
case widget.Pad:
2024-01-01 16:11:54 -06:00
t.uiWindow.SetBorderless(false)
case widget.Unpad:
2024-01-01 16:11:54 -06:00
t.uiWindow.SetBorderless(true)
}
case widget.Grid:
2024-01-01 16:11:54 -06:00
switch at {
case widget.Margin:
2024-01-01 16:11:54 -06:00
t.uiGrid.SetPadded(true)
case widget.Unmargin:
2024-01-01 16:11:54 -06:00
t.uiGrid.SetPadded(false)
case widget.Pad:
2024-01-01 16:11:54 -06:00
t.uiGrid.SetPadded(true)
case widget.Unpad:
2024-01-01 16:11:54 -06:00
t.uiGrid.SetPadded(false)
}
case widget.Box:
2024-01-01 16:11:54 -06:00
switch at {
case widget.Margin:
2024-01-01 16:11:54 -06:00
t.uiBox.SetPadded(true)
case widget.Unmargin:
2024-01-01 16:11:54 -06:00
t.uiBox.SetPadded(false)
case widget.Pad:
2024-01-01 16:11:54 -06:00
t.uiBox.SetPadded(true)
case widget.Unpad:
2024-01-01 16:11:54 -06:00
t.uiBox.SetPadded(false)
}
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
stretchy = true
if (p.tk.uiBox != nil) {
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
}
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.progname)
log.Log(NOW, "is there a tParent parent? =", p.parent)
2024-01-01 16:11:54 -06:00
if (p.tk.boxC < 1) {
log.Log(NOW, "Can not delete from Box. already empty. tWidget.boxC =", p.tk.boxC)
2024-01-01 16:11:54 -06:00
return
}
p.tk.uiBox.Delete(0)
p.tk.boxC -= 1
// 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 rawAction(a *widget.Action) {
log.Log(INFO, "rawAction() START a.ActionType =", a.ActionType, "a.Value", a.Value)
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, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
2024-01-01 16:11:54 -06:00
switch a.WidgetType {
case widget.Flag:
log.Log(ERROR, "rawAction() RE-IMPLEMENT LOG FLAGS")
2024-01-01 16:11:54 -06:00
return
}
n := me.rootNode.findWidgetId(a.WidgetId)
if (a.ActionType == widget.Add) {
2024-01-01 16:11:54 -06:00
ui.QueueMain(func() {
add(a)
})
// TODO: remove this artificial delay
// sleep(.001)
return
}
if (a.ActionType == widget.Dump) {
log.Log(NOW, "rawAction() Dump =", a.ActionType, a.WidgetType, n.progname)
2024-01-01 16:11:54 -06:00
me.rootNode.listChildren(true)
return
}
if (n == nil) {
me.rootNode.listChildren(true)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
log.Log(NOW, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId)
2024-01-01 16:11:54 -06:00
return
panic("findWidgetId found nil for id = " + strconv.Itoa(a.WidgetId))
}
switch a.ActionType {
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)
case widget.GetText:
2024-01-01 16:11:54 -06:00
switch a.WidgetType {
case widget.Textbox:
a.Value = n.value
2024-01-01 16:11:54 -06:00
}
case widget.Set:
2024-01-01 16:11:54 -06:00
n.setText(a)
case widget.SetText:
2024-01-01 16:11:54 -06:00
n.setText(a)
case widget.AddText:
n.addText(a)
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(NOW, "rawAction() 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, "rawAction() Unknown =", a.ActionType, a.WidgetType)
2024-01-01 16:11:54 -06:00
}
log.Log(INFO, "rawAction() END =", a.ActionType, a.WidgetType)
2024-01-01 16:11:54 -06:00
}