From 1fdf786a72fd4af0c1acca45b250b5f66ef3e31b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 21 Jan 2024 14:44:47 -0600 Subject: visable state is honored. TODO: fix hide/show Signed-off-by: Jeff Carr --- action.go | 38 ++++++++++++++++++++++++++++++++------ common.go | 36 ++++-------------------------------- node.go | 3 ++- plugin.go | 4 ++-- redraw.go | 2 +- spinner.go | 2 +- window.go | 6 ++++-- 7 files changed, 46 insertions(+), 45 deletions(-) diff --git a/action.go b/action.go index a1566a8..533b32e 100644 --- a/action.go +++ b/action.go @@ -22,19 +22,30 @@ func (n *Node) SetVisable(b bool) { // returns true if the window is not visable to the user // in which case events are not sent to the toolkit +// TODO: fix this so ParentVisable() works func (n *Node) WindowVisable() bool { if n == nil { - return true + return false } if n.WidgetType == widget.Window { return n.visable } if n.parent == nil { - return true - } else { - return n.parent.WindowVisable() + return false } - return true + return n.parent.WindowVisable() +} + +// returns true if the parent is not visable to the user +// in which case events are not sent to the toolkit +func (n *Node) ParentVisable() bool { + if n == nil { + return false + } + if n.parent == nil { + return false + } + return n.parent.visable } // 2024/01/11 finally moving to type any. simplify to just 'value' @@ -52,10 +63,25 @@ func sendAction(n *Node, atype widget.ActionType) { // this checks to see if the window is show in the toolkit. If it is not, // then don't send any events. Unless it is a window widget, then send events if n.WidgetType != widget.Window { - if !n.WindowVisable() { + if n.WindowVisable() { + // lots of output. make this verbose? + log.Log(INFO, "Sending action to widget. Window is visable", n.id, n.WidgetType, n.GetProgName()) + } else { + // lots of output. make this verbose? log.Log(INFO, "Not sending action to widget. Window is not visable", n.id, n.WidgetType, n.GetProgName()) return } + // set if the widget is visable based on the parent + // this has nothing to do with show() and hide() + if n.ParentVisable() { + log.Log(NOW, "Parent is visable n =", n.id, n.WidgetType, n.GetProgName()) + n.visable = true + } else { + log.Log(NOW, "Parent is not visable n =", n.id, n.WidgetType, n.GetProgName()) + log.Log(NOW, "not sending action to toolkits") + n.visable = false + return + } } var a widget.Action diff --git a/common.go b/common.go index c897c2c..855c11c 100644 --- a/common.go +++ b/common.go @@ -226,7 +226,7 @@ func (n *Node) Margin() *Node { n.margin = true n.changed = true - log.Warn("Margin()", n.WidgetType, n.progname) + log.Log(INFO, "Margin()", n.WidgetType, n.progname) // inform the toolkits sendAction(n, widget.Margin) return n @@ -259,7 +259,7 @@ func (n *Node) Pad() *Node { n.pad = true n.changed = true - log.Warn("Pad()", n.WidgetType, n.progname) + log.Log(INFO, "Pad()", n.WidgetType, n.progname) // inform the toolkits sendAction(n, widget.Pad) return n @@ -323,7 +323,8 @@ func (n *Node) Hidden() bool { func (n *Node) Ready() bool { if n == nil { - log.Warn("Ready() got node == nil") + log.Log(NOW, "Ready() got node == nil. TODO: find code trace to here") + panic("ready got nil") // TODO: figure out if you can identify the code trace // to help find the root cause return false @@ -343,35 +344,6 @@ func TreeRoot() *Node { // // -// This should not really do anything. as per the docs, the "Standard()" way -// should be the default way -/* -func (n *Node) Standard() *Node { - log.Warn("Standard() not implemented yet") - return n -} - -func (n *Node) SetMargin() *Node { - log.Warn("DoMargin() not implemented yet") - return n -} -*/ - -/* -func (n *Node) Window(title string) *Node { - log.Warn("Window()", n) - return n.NewWindow(title) -} -*/ - -/* -func (n *Node) SetNext(w int, h int) { - n.NextW = w - n.NextH = h - log.Info("SetNext() w,h =", n.NextW, n.NextH) -} -*/ - /* // string handling examples that might be helpful for normalizeInt() isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString diff --git a/node.go b/node.go index bb26656..4b056fb 100644 --- a/node.go +++ b/node.go @@ -29,7 +29,8 @@ func (n *Node) newNode(title string, t widget.WidgetType) *Node { // set these defaults newN.expand = false - newN.visable = true + // honor the visable settings of the parent + newN.visable = n.visable newN.pad = true newN.borderless = false diff --git a/plugin.go b/plugin.go index 0d1049a..15f9814 100644 --- a/plugin.go +++ b/plugin.go @@ -222,9 +222,9 @@ func (n *Node) InitEmbed(resFS embed.FS) *Node { func (n *Node) LoadToolkitEmbed(name string, b []byte) *Node { for _, aplug := range allPlugins { - log.Info("LoadToolkitEmbed() already loaded toolkit plugin =", aplug.name) + log.Log(PLUG, "LoadToolkitEmbed() already loaded toolkit plugin =", aplug.name) if aplug.name == name { - log.Warn("LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice") + log.Log(NOW, "LoadToolkitEmbed() SKIPPING", name, "as you can't load it twice") return n } } diff --git a/redraw.go b/redraw.go index 8a5b609..f4b8214 100644 --- a/redraw.go +++ b/redraw.go @@ -21,7 +21,7 @@ func (n *Node) redraw(p *aplug) { } func (n *Node) redo(plug *aplug) { - log.Info("redo()", plug.name, n.id, n.WidgetType, n.progname) + log.Log(NOW, "redo()", plug.name, n.id, n.WidgetType, n.progname) var a *widget.Action a = new(widget.Action) diff --git a/spinner.go b/spinner.go index e10ad4d..393388f 100644 --- a/spinner.go +++ b/spinner.go @@ -10,7 +10,7 @@ func (parent *Node) NewSpinner(progname string, x int, y int) *Node { newNode.progname = progname newNode.Custom = func() { - log.Info("default NewSpinner() change", progname) + log.Log(NOW, "default NewSpinner() change", progname) } newNode.X = x diff --git a/window.go b/window.go index 705b346..f158206 100644 --- a/window.go +++ b/window.go @@ -14,11 +14,12 @@ func (parent *Node) NewWindow(title string) *Node { newNode = parent.newNode(title, widget.Window) newNode.Custom = StandardExit - log.Info("NewWindow()", title) + log.Log(INFO, "NewWindow()", title) newNode.progname = title newNode.label = title newNode.value = title newNode.margin = true + newNode.visable = true // inform the toolkits sendAction(newNode, widget.Add) @@ -32,8 +33,9 @@ func (parent *Node) RawWindow(title string) *Node { // Windows are created off of the master node of the Binary Tree newNode = parent.newNode(title, widget.Window) newNode.hidden = true + newNode.visable = false - log.Info("RawWindow()", title) + log.Log(INFO, "RawWindow()", title) return newNode } -- cgit v1.2.3