2024-01-17 23:54:19 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-05 12:06:17 -06:00
|
|
|
"go.wit.com/dev/andlabs/ui"
|
2024-01-17 23:54:19 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 04:27:19 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-17 23:54:19 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// this will check to make sure that the node
|
|
|
|
// is valid for making a New TK andlabs widget
|
|
|
|
// Basically, it makes sure there is a parent ID
|
|
|
|
// and that there already a widget created
|
|
|
|
func notNew(n *tree.Node) bool {
|
|
|
|
if n == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "notNew() n = nil")
|
2024-01-17 23:54:19 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if n.TK != nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "notNew() n.TK = nil", n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if n.Parent == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "notNew() n.Parent = nil", n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if n.Parent.TK == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
if n.Parent.WidgetId == 0 {
|
|
|
|
// this is normal if the widget type is a window
|
|
|
|
if n.WidgetType == widget.Window {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Log(ERROR, "notNew() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
|
|
|
|
log.Log(ERROR, "notNew() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
// this means you can add a new widgets
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-01-19 12:18:11 -06:00
|
|
|
func tkbad(n *tree.Node) bool {
|
|
|
|
if n == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "tkbad() n = nil")
|
2024-01-19 12:18:11 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
if n.TK == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "tkbad() n.TK = nil", n.WidgetId, n.GetProgName())
|
2024-01-19 12:18:11 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// this makes sure widget and it's parent exists
|
2024-01-17 23:54:19 -06:00
|
|
|
func ready(n *tree.Node) bool {
|
|
|
|
if n == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "ready() n = nil")
|
2024-01-17 23:54:19 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if n.TK == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "ready() n.TK = nil", n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if n.Parent == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "ready() n.Parent = nil", n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if n.Parent.TK == nil {
|
2024-01-21 11:30:12 -06:00
|
|
|
if n.Parent.WidgetId == 0 {
|
|
|
|
// this is normal if the widget type is a window
|
|
|
|
if n.WidgetType == widget.Window {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Log(ERROR, "ready() n.Parent.TK = nil", n.WidgetId, n.GetProgName())
|
|
|
|
log.Log(ERROR, "ready() n.Parent.TK = nil", n.Parent.WidgetId, n.Parent.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-01-27 10:03:01 -06:00
|
|
|
func hide(n *tree.Node) {
|
|
|
|
show(n, false)
|
|
|
|
n.State.Hidden = true
|
|
|
|
}
|
|
|
|
|
2024-01-17 23:54:19 -06:00
|
|
|
func show(n *tree.Node, b bool) {
|
2024-01-19 12:18:11 -06:00
|
|
|
if tkbad(n) {
|
|
|
|
return
|
|
|
|
}
|
2024-01-17 23:54:19 -06:00
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
|
|
|
// tk = getTK(n)
|
|
|
|
|
|
|
|
if tk == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tk.uiControl == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if b {
|
|
|
|
tk.uiControl.Show()
|
|
|
|
} else {
|
|
|
|
tk.uiControl.Hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func enable(n *tree.Node, b bool) {
|
2024-01-27 10:03:01 -06:00
|
|
|
if !ready(n) {
|
2024-01-17 23:54:19 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-27 10:03:01 -06:00
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
2024-01-17 23:54:19 -06:00
|
|
|
if tk.uiControl == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if b {
|
|
|
|
tk.uiControl.Enable()
|
|
|
|
} else {
|
|
|
|
tk.uiControl.Disable()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-19 02:52:57 -06:00
|
|
|
func pad(n *tree.Node, b bool) {
|
2024-01-19 12:18:11 -06:00
|
|
|
if tkbad(n) {
|
|
|
|
return
|
|
|
|
}
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "pad() on WidgetId =", n.WidgetId)
|
2024-01-17 23:54:19 -06:00
|
|
|
|
2024-01-19 02:52:57 -06:00
|
|
|
t := n.TK.(*guiWidget)
|
2024-01-17 23:54:19 -06:00
|
|
|
if t == nil {
|
|
|
|
log.Log(ERROR, "pad() toolkit struct == nil. for", n.WidgetId)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch n.WidgetType {
|
|
|
|
case widget.Window:
|
|
|
|
t.uiWindow.SetMargined(b)
|
|
|
|
t.uiWindow.SetBorderless(b)
|
|
|
|
case widget.Tab:
|
|
|
|
tabSetMargined(t.uiTab, b)
|
|
|
|
case widget.Group:
|
|
|
|
t.uiGroup.SetMargined(b)
|
|
|
|
case widget.Grid:
|
|
|
|
t.uiGrid.SetPadded(b)
|
|
|
|
case widget.Box:
|
|
|
|
t.uiBox.SetPadded(b)
|
|
|
|
default:
|
2024-01-19 02:52:57 -06:00
|
|
|
log.Log(ERROR, "TODO: implement pad() for", n.WidgetType, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-18 21:20:32 -06:00
|
|
|
func widgetDelete(n *tree.Node) {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "widgetDelete()", n.WidgetId, n.WidgetType)
|
2024-01-18 21:20:32 -06:00
|
|
|
var tk *guiWidget
|
|
|
|
tk = n.TK.(*guiWidget)
|
2024-01-17 23:54:19 -06:00
|
|
|
|
|
|
|
if n.WidgetType == widget.Window {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "DESTROY uiWindow here")
|
|
|
|
log.Log(ANDLABS, "DESTROY NEED TO REMOVE n from parent.Children")
|
2024-01-19 12:18:11 -06:00
|
|
|
if tk.uiWindow != nil {
|
|
|
|
tk.uiWindow.Destroy()
|
|
|
|
tk.uiWindow = nil
|
|
|
|
}
|
2024-01-18 21:20:32 -06:00
|
|
|
n.DeleteNode()
|
2024-01-21 11:30:12 -06:00
|
|
|
} else {
|
|
|
|
log.Log(ANDLABS, "DESTROY can't destroy TODO:", n.WidgetId, n.WidgetType)
|
2024-01-17 23:54:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-05 12:06:17 -06:00
|
|
|
func SetTitle(n *tree.Node, s string) {
|
|
|
|
SetText(n, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetLabel(n *tree.Node, s string) {
|
|
|
|
SetText(n, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetText(n *tree.Node, s string) {
|
|
|
|
if n == nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "Tree Error: Add() sent n == nil")
|
2024-02-05 12:06:17 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n.TK == nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "Tree sent an action on a widget we didn't seem to have.")
|
2024-02-05 12:06:17 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
setText(n, s)
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "SetText() (new)", n.WidgetType, n.String(), s)
|
2024-02-05 12:06:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func AddText(n *tree.Node, s string) {
|
|
|
|
if n == nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "Tree Error: Add() sent n == nil")
|
2024-02-05 12:06:17 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n.TK == nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "Tree sent an action on a widget we didn't seem to have.")
|
2024-02-05 12:06:17 -06:00
|
|
|
return
|
|
|
|
}
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "AddText()", n.WidgetType, n.String())
|
2024-02-05 12:06:17 -06:00
|
|
|
// w := n.TK.(*guiWidget)
|
|
|
|
// w.AddText(s)
|
|
|
|
addText(n, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAction(n *tree.Node, atype widget.ActionType) {
|
|
|
|
log.Log(INFO, "newaction() START", atype)
|
|
|
|
if n == nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "Tree Error: Add() sent n == nil")
|
2024-02-05 12:06:17 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n.TK == nil {
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(WARN, "Tree sent an action on a widget we didn't seem to have.")
|
2024-02-05 12:06:17 -06:00
|
|
|
// do this init here again? Probably something
|
|
|
|
// went wrong and we should reset the our while gocui.View tree
|
|
|
|
n.TK = initWidget(n)
|
|
|
|
}
|
|
|
|
// w := n.TK.(*guiWidget)
|
|
|
|
switch atype {
|
|
|
|
case widget.Show:
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "Show() HERE. a.Hidden() was =", n.Hidden())
|
2024-02-05 12:06:17 -06:00
|
|
|
show(n, true)
|
|
|
|
case widget.Hide:
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "Hide() HERE. a.State.Hidden was =", n.Hidden())
|
2024-02-05 12:06:17 -06:00
|
|
|
hide(n)
|
|
|
|
case widget.Move:
|
2024-02-07 07:31:28 -06:00
|
|
|
log.Log(ANDLABS, "attempt to move() =", atype, n.WidgetType, n.ProgName())
|
2024-02-05 12:06:17 -06:00
|
|
|
case widget.ToolkitClose:
|
|
|
|
log.Log(NOW, "attempting to Quit andlabs.ui")
|
|
|
|
// standardClose()
|
|
|
|
ui.Quit()
|
|
|
|
case widget.Enable:
|
|
|
|
enable(n, true)
|
|
|
|
case widget.Disable:
|
|
|
|
enable(n, false)
|
|
|
|
case widget.Delete:
|
|
|
|
widgetDelete(n)
|
|
|
|
default:
|
|
|
|
log.Log(ERROR, "newaction() UNHANDLED Action Type =", atype, "WidgetType =", n.WidgetType, "Name =", n.ProgName())
|
|
|
|
}
|
|
|
|
log.Log(INFO, "newaction() END", atype, n.String())
|
|
|
|
}
|