From c077a3d4e1461a52d826a37eae811f3227b363d7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 9 May 2023 19:24:37 -0500 Subject: [PATCH] getting pretty clean at this point Signed-off-by: Jeff Carr --- README-goreadme.md | 4 +-- common.go | 75 ++++++++++++++++++++-------------------------- debug.go | 11 +++---- debugWidget.go | 44 +++++++++++---------------- plugin.go | 5 +++- 5 files changed, 61 insertions(+), 78 deletions(-) diff --git a/README-goreadme.md b/README-goreadme.md index e9b318c..63698b8 100644 --- a/README-goreadme.md +++ b/README-goreadme.md @@ -123,7 +123,7 @@ Creates a window helpful for debugging this package `func ExampleCatcher(f func())` -### func [Indent](/debug.go#L127) +### func [Indent](/debug.go#L124) `func Indent(b bool, a ...interface{})` @@ -135,7 +135,7 @@ Creates a window helpful for debugging this package `func SetFlag(s string, b bool)` -### func [ShowDebugValues](/debug.go#L85) +### func [ShowDebugValues](/debug.go#L82) `func ShowDebugValues()` diff --git a/common.go b/common.go index 25e25e3..f9884d0 100644 --- a/common.go +++ b/common.go @@ -10,60 +10,56 @@ import ( // functions for handling text related GUI elements func (n *Node) Show() *Node { - var a toolkit.Action - a.ActionType = toolkit.Show - newaction(&a, n, nil) + a := newAction(n, toolkit.Show) + sendAction(a) return n } func (n *Node) Hide() *Node { - var a toolkit.Action - a.ActionType = toolkit.Hide - newaction(&a, n, nil) + a := newAction(n, toolkit.Hide) + sendAction(a) return n } func (n *Node) Enable() *Node { - var a toolkit.Action - a.ActionType = toolkit.Enable - newaction(&a, n, nil) + a := newAction(n, toolkit.Enable) + sendAction(a) return n } func (n *Node) Disable() *Node { - var a toolkit.Action - a.ActionType = toolkit.Disable - newaction(&a, n, nil) + a := newAction(n, toolkit.Disable) + sendAction(a) return n } func (n *Node) Add(str string) { log(debugGui, "gui.Add() value =", str) - var a toolkit.Action - a.ActionType = toolkit.Add - a.S = str - newaction(&a, n, nil) + n.S = str + + a := newAction(n, toolkit.Add) + sendAction(a) } func (n *Node) AddText(str string) { log(debugChange, "AddText() value =", str) n.Text = str - var a toolkit.Action - a.ActionType = toolkit.AddText - a.S = str - newaction(&a, n, nil) + n.S = str + + a := newAction(n, toolkit.AddText) + sendAction(a) } -func (n *Node) SetText(text string) *Node{ +func (n *Node) SetText(text string) *Node { log(debugChange, "SetText() value =", text) n.Text = text - var a toolkit.Action - a.ActionType = toolkit.SetText - a.S = text - newaction(&a, n, nil) + n.S = text + + a := newAction(n, toolkit.SetText) + sendAction(a) return n } @@ -93,13 +89,12 @@ func (n *Node) Set(val any) { } func (n *Node) AppendText(str string) { - var a toolkit.Action - a.ActionType = toolkit.SetText tmp := n.S + str - log(debugChange, "AppendText() value =", tmp) - a.S = tmp n.Text = tmp - newaction(&a, n, nil) + n.S = tmp + + a := newAction(n, toolkit.SetText) + sendAction(a) } func (n *Node) GetText() string { @@ -152,30 +147,26 @@ func commonCallback(n *Node) { } func (n *Node) Margin() *Node { - var a toolkit.Action - a.ActionType = toolkit.Margin - newaction(&a, n, nil) + a := newAction(n, toolkit.Margin) + sendAction(a) return n } func (n *Node) Unmargin() *Node { - var a toolkit.Action - a.ActionType = toolkit.Unmargin - newaction(&a, n, nil) + a := newAction(n, toolkit.Unmargin) + sendAction(a) return n } func (n *Node) Pad() *Node { - var a toolkit.Action - a.ActionType = toolkit.Pad - newaction(&a, n, nil) + a := newAction(n, toolkit.Pad) + sendAction(a) return n } func (n *Node) Unpad() *Node { - var a toolkit.Action - a.ActionType = toolkit.Unpad - newaction(&a, n, nil) + a := newAction(n, toolkit.Unpad) + sendAction(a) return n } diff --git a/debug.go b/debug.go index 2df06cc..955a246 100644 --- a/debug.go +++ b/debug.go @@ -71,15 +71,12 @@ func SetFlag (s string, b bool) { log(debugGui, "Can't set unknown flag", s) } - var a toolkit.Action + a := new(toolkit.Action) a.ActionType = toolkit.Set a.WidgetType = toolkit.Flag a.S = s a.B = b - // a.Widget = &newNode.widget - // a.Where = &n.widget - // action(&a) - newaction(&a, nil, nil) + sendAction(a) } func ShowDebugValues() { @@ -118,10 +115,10 @@ func (n *Node) Dump() { } Indent(b, "NODE DUMP END") - var a toolkit.Action + a := new(toolkit.Action) a.ActionType = toolkit.Dump a.WidgetId = n.id - newaction(&a, activeWidget, nil) + sendAction(a) } func Indent(b bool, a ...interface{}) { diff --git a/debugWidget.go b/debugWidget.go index cb801a8..385f47a 100644 --- a/debugWidget.go +++ b/debugWidget.go @@ -115,46 +115,38 @@ func DebugWidgetWindow(w *Node) { g = bugWidget.NewGroup("change things") g.NewButton("AddText()", func () { - var a toolkit.Action - a.ActionType = toolkit.AddText - a.S = activeLabelNewName.S - newaction(&a, activeWidget, nil) + activeWidget.S = activeLabelNewName.S + a := newAction(activeWidget, toolkit.AddText) + sendAction(a) }) g.NewButton("SetText()", func () { - var a toolkit.Action - a.ActionType = toolkit.SetText - a.S = activeLabelNewName.S - newaction(&a, activeWidget, nil) + activeWidget.S = activeLabelNewName.S + a := newAction(activeWidget, toolkit.SetText) + sendAction(a) }) g.NewButton("Margin()", func () { - var a toolkit.Action - a.ActionType = toolkit.Margin - newaction(&a, activeWidget, nil) + a := newAction(activeWidget, toolkit.Margin) + sendAction(a) }) g.NewButton("Unmargin()", func () { - var a toolkit.Action - a.ActionType = toolkit.Unmargin - newaction(&a, activeWidget, nil) + a := newAction(activeWidget, toolkit.Unmargin) + sendAction(a) }) g.NewButton("Pad()", func () { - var a toolkit.Action - a.ActionType = toolkit.Pad - newaction(&a, activeWidget, nil) + a := newAction(activeWidget, toolkit.Pad) + sendAction(a) }) g.NewButton("Unpad()", func () { - var a toolkit.Action - a.ActionType = toolkit.Unpad - newaction(&a, activeWidget, nil) + a := newAction(activeWidget, toolkit.Unpad) + sendAction(a) }) g.NewButton("Move(junk)", func () { - var a toolkit.Action - a.ActionType = toolkit.Move - newaction(&a, activeWidget, activeJunk) + a := newAction(activeWidget, toolkit.Move) + sendAction(a) }) g.NewButton("Delete()", func () { - var a toolkit.Action - a.ActionType = toolkit.Delete - newaction(&a, activeWidget, activeJunk) + a := newAction(activeWidget, toolkit.Delete) + sendAction(a) }) g = bugWidget.NewGroup("not working?") diff --git a/plugin.go b/plugin.go index c9e0466..e8b4beb 100644 --- a/plugin.go +++ b/plugin.go @@ -203,6 +203,8 @@ func initToolkit(name string, filename string) *aplug { return newPlug } +// 2023/05/09 pretty clean +// 2023/04/06 Queue() is also being used and channels are being used. memcopy() only func newAction(n *Node, atype toolkit.ActionType) *toolkit.Action { var a toolkit.Action a.ActionType = atype @@ -246,7 +248,7 @@ func sendAction(a *toolkit.Action) { } } -// 2023/04/06 Queue() is also being used and channels are being used. memcopy() only +/* func newaction(a *toolkit.Action, n *Node, where *Node) { // remove this if (n != nil) { @@ -275,6 +277,7 @@ func newaction(a *toolkit.Action, n *Node, where *Node) { sleep(.02) } } +*/ func (n *Node) InitEmbed(resFS embed.FS) *Node { me.resFS = resFS