From b15369d85df247a460f0c0c18ac9578c79ca51a3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 18 Jan 2024 21:21:50 -0600 Subject: window destroy (aka Hide) works Signed-off-by: Jeff Carr --- Makefile | 1 + action.go | 1 + common.go | 73 +++++++---------------------------------- main.go | 107 +++++++++++++++++-------------------------------------------- structs.go | 3 +- 5 files changed, 46 insertions(+), 139 deletions(-) diff --git a/Makefile b/Makefile index 30a71fd..413f145 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ endif redomod: rm -f go.* + goimports -w *.go GO111MODULE= go mod init GO111MODULE= go mod tidy diff --git a/action.go b/action.go index 77b839e..ddad70b 100644 --- a/action.go +++ b/action.go @@ -33,6 +33,7 @@ func sendAction(n *Node, atype widget.ActionType) { if n.hidden { if atype == widget.Hide { // well, unless this is a Hide action, then inform the toolkit + log.Warn("SENDING HIDDEN ACTION. IS THIS A WINDOW?", n.GetProgName(), atype) } else { log.Warn("NOT SENDING HIDDEN ACTION", n.GetProgName(), atype) // return diff --git a/common.go b/common.go index 755872a..56ad5d5 100644 --- a/common.go +++ b/common.go @@ -5,7 +5,6 @@ package gui import ( "go.wit.com/log" "go.wit.com/widget" - "regexp" ) // functions for handling text related GUI elements @@ -34,13 +33,14 @@ func (n *Node) Show() *Node { } func (n *Node) Hide() *Node { - return n if !n.Ready() { return n } - if n.Hidden() { - return n - } + /* + if n.Hidden() { + return n + } + */ if n.WidgetType == widget.Window { log.Warn("Hide on a window", n.progname) @@ -137,6 +137,7 @@ func (n *Node) Destroy() { n.enabled = false n.changed = true + log.Warn("SENDING DESTROY ON", n.WidgetType, n.id, n.GetProgName()) // inform the toolkits sendAction(n, widget.Delete) return @@ -156,33 +157,13 @@ func (n *Node) AppendText(str string) { sendAction(n, widget.SetText) } -// THESE TWO FUNCTIONS ARE TERRIBLY NAMED AND NEED TO BE FIXED -// 5 seconds worth of ideas: -// Value() ? -// Progname() Reference() ? -// 2024/01/13 the names are starting to grow on me and make it clearer to code against - +// should get the reference name used for programming and debugging /* -// get a string from the widget -func (n *Node) GetText() string { - if ! n.Ready() { return "" } - return widget.GetString(n.value) -} - -// get a string from the widget -func (n *Node) GetInt() int { - if ! n.Ready() { return -1 } - return widget.GetInt(n.value) -} - -// get a string from the widget -func (n *Node) GetBool() bool { - if ! n.Ready() { return false} - return widget.GetBool(n.value) -} +TODO: ensure these are unique and make a way to look them up +myButton = myGroup.NewButton("hit ball", nil).SetName("HIT") +myButton.GetName() should return "HIT" +n = Find("HIT") should return myButton */ - -// should get the reference name used for programming and debugging func (n *Node) SetProgName(s string) *Node { if !n.Ready() { return n @@ -198,12 +179,6 @@ func (n *Node) SetProgName(s string) *Node { return n } -/* -TODO: ensure these are unique and make a way to look them up -myButton = myGroup.NewButton("hit ball", nil).SetName("HIT") -myButton.GetName() should return "HIT" -n = Find("HIT") should return myButton -*/ func (n *Node) GetProgName() string { if !n.Ready() { return "" @@ -211,19 +186,6 @@ func (n *Node) GetProgName() string { return n.progname } -/* -func commonCallback(n *Node) { - // TODO: make all of this common code to all the widgets - // This might be common everywhere finally (2023/03/01) - if (n.Custom == nil) { - log.Log(CHANGE, "Not Running n.Custom(n) == nil") - } else { - log.Log(CHANGE, "Running n.Custom(n)") - n.Custom() - } -} -*/ - func (n *Node) Margin() *Node { if !n.Ready() { return n @@ -367,17 +329,6 @@ func (n *Node) Window(title string) *Node { } */ -/* -func (n *Node) Add(str string) { - log.Log(GUI, "gui.Add() value =", str) - - n.value = str - - // inform the toolkits - sendAction(n, widget.Add) -} -*/ - /* func (n *Node) SetNext(w int, h int) { n.NextW = w @@ -406,7 +357,6 @@ func alphaOnly(s string) bool { } return true } -*/ func normalizeInt(s string) string { // reg, err := regexp.Compile("[^a-zA-Z0-9]+") @@ -419,3 +369,4 @@ func normalizeInt(s string) string { log.Log(GUI, "normalizeInt() s =", clean) return clean } +*/ diff --git a/main.go b/main.go index 7c834ca..a3471a7 100644 --- a/main.go +++ b/main.go @@ -63,17 +63,20 @@ func watchCallback() { log.Info("guiChan() select restarted") select { case a := <-me.guiChan: + // 99.9% of events are just widget changes + n := me.rootNode.findId(a.WidgetId) + if n != nil { + log.Verbose("guiChan() FOUND widget id =", n.id, n.progname) + n.goUserEvent(a) + break + } + + // if not a widget change, something more bizare if a.ActionType == widget.UserQuit { log.Warn("guiChan() User sent Quit()") - me.rootNode.doCustom() log.Exit("wit/gui toolkit.UserQuit") break } - if a.ActionType == widget.CloseWindow { - log.Warn("guiChan() Close Window") - StandardExit() - break - } if a.ActionType == widget.ToolkitPanic { log.Warn("guiChan() Toolkit panic() in", a.ProgName) log.Warn("guiChan() unload toolkit plugin here", a.ProgName) @@ -107,88 +110,38 @@ func watchCallback() { PLUG.Set(true) me.rootNode.ListToolkits() me.rootNode.ListChildren(true) - for i, aplug := range allPlugins { - log.Warn("plug =", i, aplug.name) - if aplug.name == "andlabs" { - log.Warn("Found plug =", i, aplug.name) - //closePlugin(aplug) - allPlugins = allPlugins[1:] + /* + for i, aplug := range allPlugins { + log.Warn("plug =", i, aplug.name) + if aplug.name == "andlabs" { + log.Warn("Found plug =", i, aplug.name) + //closePlugin(aplug) + allPlugins = allPlugins[1:] + } } - } - // DebugWindow() + */ break } - - n := me.rootNode.findId(a.WidgetId) - if n == nil { - log.Warn("guiChan() UNKNOWN widget id") - log.Warn("id =", a.WidgetId, a.ProgName) - } else { - log.Verbose("guiChan() FOUND widget id =", n.id, n.progname) - n.doUserEvent(a) - } - // this maybe a good idea? - // TODO: Throttle user events somehow - // sleep(.01) // hack that throttles user events + log.Warn("guiChan() Action could not be found or handled", a.ActionType, a) } } } -func (n *Node) doCustom() { - log.Info("doUserEvent() widget =", n.id, n.progname, n.WidgetType) +// stores the value returned then +// spawns the user defined custom routine +// hopefully everything is designed smart enough +// that it doesn't matter what happens outside of here +// TODO: implement throttling someday +func (n *Node) goUserEvent(a widget.Action) { + log.Info("goUserEvent() node =", n.id, n.progname) + n.value = a.Value if n.Custom == nil { - log.Warn("Custom() = nil. SKIPPING") + log.Info("a Custom() function was not set for this widget") return } go n.Custom() } -func (n *Node) doUserEvent(a widget.Action) { - log.Info("doUserEvent() node =", n.id, n.progname) - if a.Value == nil { - log.Warn("doUserEvent() a.A == nil", n.id, n.progname) - return - } - n.value = a.Value - n.doCustom() - return - /* - switch n.WidgetType { - case widget.Checkbox: - log.Info("doUserEvent() node =", n.id, n.progname, "set to:", n.value) - n.doCustom() - case widget.Button: - log.Info("doUserEvent() node =", n.id, n.progname, "button clicked") - n.doCustom() - case widget.Combobox: - n.S = a.S - log.Info("doUserEvent() node =", n.id, n.progname, "set to:", n.S) - n.doCustom() - case widget.Dropdown: - n.S = a.S - log.Info("doUserEvent() node =", n.id, n.progname, "set to:", n.S) - n.doCustom() - case widget.Textbox: - n.S = a.S - log.Info("doUserEvent() node =", n.id, n.progname, "set to:", n.S) - n.doCustom() - case widget.Spinner: - n.I = a.I - log.Info("doUserEvent() node =", n.id, n.progname, "set to:", n.I) - n.doCustom() - case widget.Slider: - n.I = a.I - log.Info("doUserEvent() node =", n.id, n.progname, "set to:", n.I) - n.doCustom() - case widget.Window: - log.Info("doUserEvent() node =", n.id, n.progname, "window closed") - n.doCustom() - default: - log.Info("doUserEvent() type =", n.WidgetType) - } - */ -} - // There should only be one of these per application // This is due to restrictions by being cross platform // some toolkit's on some operating systems don't support more than one @@ -220,8 +173,8 @@ func (n *Node) Default() *Node { // The window is destroyed but the application does not quit func (n *Node) StandardClose() { - log.Log(GUI, "wit/gui Standard Window Close. name =", n.progname) - log.Log(GUI, "wit/gui Standard Window Close. n.Custom exit =", n.Custom) + log.Log(NOW, "wit/gui Standard Window Close. name =", n.progname) + log.Log(NOW, "wit/gui Standard Window Close. n.Custom exit =", n.Custom) } // The window is destroyed and the application exits diff --git a/structs.go b/structs.go index 2f01c66..68a47d1 100644 --- a/structs.go +++ b/structs.go @@ -2,8 +2,9 @@ package gui import ( "embed" - "go.wit.com/widget" "sync" + + "go.wit.com/widget" ) // -- cgit v1.2.3