From f48b950655f57cb02bbd754ba0043a953956f888 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 19 Jan 2024 12:18:11 -0600 Subject: [PATCH] things are moving to widget.State pass borderless windows correctly destroy themselves from the binary tree checkbox state cleanups Signed-off-by: Jeff Carr --- action.go | 34 ++++++++++++++++++++++++++++++---- add.go | 24 ++++-------------------- checkbox.go | 10 ++++++++++ debug.go | 2 ++ go.mod | 12 ++++++++++++ go.sum | 10 ++++++++++ main.go | 5 +++++ place.go | 4 ++-- tab.go | 2 ++ updateui.go | 2 +- window.go | 9 +++++---- 11 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/action.go b/action.go index a059816..db83624 100644 --- a/action.go +++ b/action.go @@ -34,6 +34,19 @@ func notNew(n *tree.Node) bool { return false } +func tkbad(n *tree.Node) bool { + if n == nil { + log.Warn("ready() n = nil") + return true + } + if n.TK == nil { + log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName()) + return true + } + return false +} + +// this makes sure widget and it's parent exists func ready(n *tree.Node) bool { if n == nil { log.Warn("ready() n = nil") @@ -56,6 +69,9 @@ func ready(n *tree.Node) bool { } func show(n *tree.Node, b bool) { + if tkbad(n) { + return + } var tk *guiWidget tk = n.TK.(*guiWidget) // tk = getTK(n) @@ -93,6 +109,9 @@ func enable(n *tree.Node, b bool) { } func pad(n *tree.Node, b bool) { + if tkbad(n) { + return + } log.Warn("pad() on WidgetId =", n.WidgetId) t := n.TK.(*guiWidget) @@ -126,14 +145,16 @@ func widgetDelete(n *tree.Node) { if n.WidgetType == widget.Window { log.Warn("DESTROY uiWindow here") log.Warn("NEED TO REMOVE n from parent.Children") - tk.uiWindow.Destroy() - tk.uiWindow = nil + if tk.uiWindow != nil { + tk.uiWindow.Destroy() + tk.uiWindow = nil + } n.DeleteNode() } } func processAction(a *widget.Action) { - log.Log(INFO, "processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value) + log.Warn("processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value) if a.ActionType == widget.ToolkitInit { Init() @@ -163,7 +184,10 @@ func processAction(a *widget.Action) { } if a.ActionType == widget.Add { - add(a) + n := add(a) + show(n, n.State.Visable) + // pad(n, n.State.Pad) + // expand(n, a.State.Expand) return } @@ -195,6 +219,8 @@ func processAction(a *widget.Action) { case widget.Disable: log.Warn("andlabs got disable for", n.WidgetId, n.State.ProgName) enable(n, false) + case widget.Checked: + setChecked(n, a.State.Checked) case widget.Get: setText(n, a) case widget.GetText: diff --git a/add.go b/add.go index 8a404fb..a2866a5 100644 --- a/add.go +++ b/add.go @@ -2,16 +2,17 @@ package main import ( "go.wit.com/log" + "go.wit.com/toolkits/tree" "go.wit.com/widget" ) -func add(a *widget.Action) { +func add(a *widget.Action) *tree.Node { log.Warn("andlabs add()", a.WidgetId, a.State.ProgName) if a.WidgetType == widget.Root { if me.treeRoot == nil { me.treeRoot = me.myTree.AddNode(a) } - return + return me.treeRoot } n := me.myTree.AddNode(a) @@ -20,52 +21,35 @@ func add(a *widget.Action) { case widget.Window: log.Warn("SPEEDY Add window", n.WidgetId, n.GetProgName()) newWindow(p, n) - return case widget.Group: log.Warn("SPEEDY Add Group", n.WidgetId, n.GetProgName()) newGroup(p, n) - return case widget.Grid: newGrid(n) - return case widget.Box: newBox(n) - return - /* - case widget.Tab: - newTab(n) - return - */ case widget.Label: newLabel(p, n) - return case widget.Button: newButton(p, n) - return case widget.Checkbox: newCheckbox(p, n) - return case widget.Spinner: newSpinner(p, n) - return case widget.Slider: newSlider(p, n) - return case widget.Dropdown: newDropdown(p, n) - return case widget.Combobox: newCombobox(p, n) - return case widget.Textbox: newTextbox(p, n) - return /* case widget.Image: newImage(p, n) - return */ default: log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.State.ProgName) } + return n } diff --git a/checkbox.go b/checkbox.go index 326406e..3101507 100644 --- a/checkbox.go +++ b/checkbox.go @@ -3,6 +3,7 @@ package main import ( "go.wit.com/log" "go.wit.com/toolkits/tree" + "go.wit.com/widget" "go.wit.com/dev/andlabs/ui" _ "go.wit.com/dev/andlabs/ui/winmanifest" @@ -32,3 +33,12 @@ func newCheckbox(p *tree.Node, n *tree.Node) { func (t *guiWidget) checked() bool { return t.uiCheckbox.Checked() } + +func setChecked(n *tree.Node, b bool) { + if n.WidgetType != widget.Checkbox { + } + var tk *guiWidget + tk = n.TK.(*guiWidget) + + tk.uiCheckbox.SetChecked(b) +} diff --git a/debug.go b/debug.go index 93d61a0..d38b90d 100644 --- a/debug.go +++ b/debug.go @@ -6,12 +6,14 @@ import ( var defaultBehavior bool = true +/* var bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? var canvas bool // if set to true, the windows are a raw canvas var menubar bool // for windows var stretchy bool // expand things like buttons to the maximum size var padded bool // add space between things like buttons var margin bool // add space around the frames of windows +*/ /* var debugToolkit bool = false diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d2bf723 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module go.wit.com/toolkits/andlabs + +go 1.21.4 + +require ( + go.wit.com/dev/andlabs/ui v0.0.1 + go.wit.com/log v0.5.5 + go.wit.com/toolkits/tree v0.0.5 + go.wit.com/widget v1.1.6 +) + +require go.wit.com/dev/davecgh/spew v1.1.4 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f41db90 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +go.wit.com/dev/andlabs/ui v0.0.1 h1:SowOybLBu/qUOqp905EZikz5/iPa3GpmnCAPzNOYajM= +go.wit.com/dev/andlabs/ui v0.0.1/go.mod h1:mlKEEe05ZJURzjh1LtjzdGMHVbJm9a7BUaVpA9cHxsM= +go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek= +go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA= +go.wit.com/log v0.5.5 h1:bK3b94uVKgev4jB5wg06FnvCFBEapQICTSH2YW+CWr4= +go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo= +go.wit.com/toolkits/tree v0.0.5 h1:weWlg58OSPtEOOD40G1P5CJ5nNJIYfJ6vMuJb8sGzUE= +go.wit.com/toolkits/tree v0.0.5/go.mod h1:n4F2seonm1aYMml+YGOpCqWo0bkFwT/RH834J6f5/iE= +go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY= +go.wit.com/widget v1.1.6/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ= diff --git a/main.go b/main.go index daac06c..293848e 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ func queueMain(currentA widget.Action) { // it's easier to code it this way however // also, if it dies here, it get's caught // usually, this is where it dies + log.Warn("about to send action into the andlabs ui.QueueMain()") ui.QueueMain(func() { processAction(¤tA) }) @@ -57,6 +58,10 @@ func guiMain() { // a better way would be to spawn ui.Main on the first actual window // that is supposed to be displayed placeholderUI() + + // if nothing is working, run this instead to make + // sure you have something + // demoUI() }) } diff --git a/place.go b/place.go index 35cffb2..79eb580 100644 --- a/place.go +++ b/place.go @@ -78,7 +78,7 @@ func place(p *tree.Node, n *tree.Node) bool { if n.WidgetType == widget.Textbox { ptk.uiBox.Append(tk.uiControl, true) } else { - ptk.uiBox.Append(tk.uiControl, stretchy) + ptk.uiBox.Append(tk.uiControl, n.State.Expand) } return true case widget.Tab: @@ -104,7 +104,7 @@ func place(p *tree.Node, n *tree.Node) bool { if n.WidgetType == widget.Textbox { ptk.uiBox.Append(tk.uiControl, true) } else { - ptk.uiBox.Append(tk.uiControl, stretchy) + ptk.uiBox.Append(tk.uiControl, n.State.Expand) } ptk.boxC += 1 return true diff --git a/tab.go b/tab.go index 46aa0a1..80bb151 100644 --- a/tab.go +++ b/tab.go @@ -88,6 +88,7 @@ func rawTab(w *ui.Window, name string) *guiWidget { return &newt } +/* func (t *guiWidget) appendTab(name string) *guiWidget { var newT guiWidget log.Log(TOOLKIT, "appendTab() ADD", name) @@ -116,3 +117,4 @@ func (t *guiWidget) appendTab(name string) *guiWidget { newT.uiBox = hbox return &newT } +*/ diff --git a/updateui.go b/updateui.go index b6c3096..88ac55b 100644 --- a/updateui.go +++ b/updateui.go @@ -99,5 +99,5 @@ func demoUI() { }) // this is messed up. - // mainWindow.Show() + mainWindow.Show() } diff --git a/window.go b/window.go index c61cbdb..804c1aa 100644 --- a/window.go +++ b/window.go @@ -19,13 +19,14 @@ func newWindow(p, n *tree.Node) { var newt *guiWidget newt = new(guiWidget) - // menubar bool is if the OS defined border on the window should be used - win := ui.NewWindow(n.GetProgName(), 640, 480, menubar) - win.SetBorderless(canvas) - win.SetMargined(margin) + // bool == false is if the OS defined border on the window should be used + win := ui.NewWindow(n.GetProgName(), 640, 480, n.State.Borderless) + win.SetBorderless(n.State.Borderless) + win.SetMargined(n.State.Pad) win.OnClosing(func(*ui.Window) bool { // show(n, false) me.myTree.SendWindowCloseEvent(n) + n.DeleteNode() return true }) newt.uiWindow = win