diff --git a/README-goreadme.md b/README-goreadme.md index c5ead2a..a21069d 100644 --- a/README-goreadme.md +++ b/README-goreadme.md @@ -134,6 +134,10 @@ Creates a window helpful for debugging this package TODO: add logic to just load the 1st 'most common' gui toolkit and allow the 'go-arg' command line args to override the defaults +### func [LoadPlugin](/main.go#L176) + +`func LoadPlugin(name string) bool` + ### func [LoadToolkit](/plugin.go#L68) `func LoadToolkit(name string) *aplug` @@ -203,6 +207,10 @@ var Config GuiConfig The Node is a binary tree. This is how all GUI elements are stored simply the name and the size of whatever GUI element exists +#### func [New](/common.go#L12) + +`func New() *Node` + #### func [NewWindow](/window.go#L13) `func NewWindow() *Node` @@ -255,10 +263,6 @@ You get a window `func Start() *Node` -#### func [StartS](/main.go#L181) - -`func StartS(name string) *Node` - ### type [Symbol](/plugin.go#L16) `type Symbol any` diff --git a/button.go b/button.go index cd9ef49..d4f1b7a 100644 --- a/button.go +++ b/button.go @@ -3,7 +3,7 @@ package gui import "git.wit.org/wit/gui/toolkit" func (n *Node) NewButton(name string, custom func()) *Node { - newNode := n.New(name, toolkit.Button, custom) + newNode := n.newNode(name, toolkit.Button, custom) var a toolkit.Action a.Name = name diff --git a/checkbox.go b/checkbox.go index 8ece750..2ab3f44 100644 --- a/checkbox.go +++ b/checkbox.go @@ -7,7 +7,7 @@ func (n *Node) Checked() bool { } func (n *Node) NewCheckbox(name string) *Node { - newNode := n.New(name, toolkit.Checkbox, nil) + newNode := n.newNode(name, toolkit.Checkbox, nil) var a toolkit.Action a.ActionType = toolkit.Add diff --git a/cmds/buttonplugin/main.go b/cmds/buttonplugin/main.go index 64500bb..acbc812 100644 --- a/cmds/buttonplugin/main.go +++ b/cmds/buttonplugin/main.go @@ -71,12 +71,12 @@ func buttonWindow() { g.NewButton("Load 'gocui'", func () { // this set the xterm and mate-terminal window title. maybe works generally? fmt.Println("\033]0;" + title + "blah \007") - gui.StartS("gocui") + gui.LoadPlugin("gocui") gui.Redraw("gocui") }) g.NewButton("Load 'andlabs'", func () { - gui.StartS("andlabs") + gui.LoadPlugin("andlabs") }) g.NewButton("NewButton(more)", func () { diff --git a/common.go b/common.go index 367b785..b3bb973 100644 --- a/common.go +++ b/common.go @@ -9,28 +9,44 @@ import ( // functions for handling text related GUI elements -func (n *Node) Show() { +func New() *Node { + if (Config.rootNode == nil) { + log(logError, "New() ERROR: rootNode is nil") + } + + // 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 + // Keep things simple. Do the default expected thing whenever possible + return startS("gocui") +} + +func (n *Node) Show() *Node { var a toolkit.Action a.ActionType = toolkit.Show newaction(&a, n, nil) + return n } -func (n *Node) Hide() { +func (n *Node) Hide() *Node { var a toolkit.Action a.ActionType = toolkit.Hide newaction(&a, n, nil) + return n } -func (n *Node) Enable() { +func (n *Node) Enable() *Node { var a toolkit.Action a.ActionType = toolkit.Enable newaction(&a, n, nil) + return n } -func (n *Node) Disable() { +func (n *Node) Disable() *Node { var a toolkit.Action a.ActionType = toolkit.Disable newaction(&a, n, nil) + return n } func (n *Node) Add(str string) { @@ -186,7 +202,7 @@ func (n *Node) Unpad() *Node { // is this better? // yes, this is better. it allows Internationalization very easily // me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard() -// myFunnyWindow = myGui.New().Window("Hello").Standard().SetText("Hola") +// myFunnyWindow = myGui.NewWindow("Hello").Standard().SetText("Hola") func (n *Node) New2() *Node { log(debugNow, "New2() Start") diff --git a/debugWidget.go b/debugWidget.go index cd712f4..8d06333 100644 --- a/debugWidget.go +++ b/debugWidget.go @@ -303,13 +303,7 @@ func (n *Node) debugAddWidgetButton() { a.AddText(name + " foo") a.AddText(name + " bar") case "Label": - newNode := activeWidget.New(name, toolkit.Label, nil) - - var a toolkit.Action - a.ActionType = toolkit.Add - newaction(&a, newNode, activeWidget) - // return newNode - // activeWidget.NewLabel(name) + activeWidget.NewLabel(name) case "Textbox": activeWidget.NewTextbox(name) case "Slider": diff --git a/debugWindow.go b/debugWindow.go index 0677b92..d0135b5 100644 --- a/debugWindow.go +++ b/debugWindow.go @@ -94,7 +94,7 @@ func (n *Node) DebugTab(title string) *Node { }) g2.NewButton("load plugin 'gocui'", func () { - StartS("gocui") + startS("gocui") }) g2.NewButton("Redraw(gocui)", func () { diff --git a/dropdown.go b/dropdown.go index 5a4e366..b7a2695 100644 --- a/dropdown.go +++ b/dropdown.go @@ -20,7 +20,7 @@ func (n *Node) SetDropdownName(name string) { } func (n *Node) NewDropdown(name string) *Node { - newNode := n.New(name, toolkit.Dropdown, nil) + newNode := n.newNode(name, toolkit.Dropdown, nil) var a toolkit.Action a.ActionType = toolkit.Add @@ -33,7 +33,7 @@ func (n *Node) NewDropdown(name string) *Node { } func (n *Node) NewCombobox(name string) *Node { - newNode := n.New(name, toolkit.Combobox, nil) + newNode := n.newNode(name, toolkit.Combobox, nil) var a toolkit.Action a.ActionType = toolkit.Add diff --git a/grid.go b/grid.go index 18eb7d8..da9321e 100644 --- a/grid.go +++ b/grid.go @@ -17,7 +17,7 @@ import ( // ----------------------------- func (n *Node) NewGrid(name string, w int, h int) *Node { - newNode := n.New(name, toolkit.Grid, func() { + newNode := n.newNode(name, toolkit.Grid, func() { log(debugChange, "click() NewGrid not defined =", name) }) @@ -39,7 +39,7 @@ func (n *Node) NewGrid(name string, w int, h int) *Node { } func (n *Node) NewBox(name string, b bool) *Node { - newNode := n.New(name, toolkit.Box, nil) + newNode := n.newNode(name, toolkit.Box, nil) newNode.B = b var a toolkit.Action diff --git a/group.go b/group.go index 3901c12..a695ef3 100644 --- a/group.go +++ b/group.go @@ -9,7 +9,7 @@ import ( // pre-canned andlabs/ui gtk,macos,windows thing func (n *Node) NewGroup(name string) *Node { var newNode *Node - newNode = n.New(name, toolkit.Group, nil) + newNode = n.newNode(name, toolkit.Group, nil) var a toolkit.Action a.ActionType = toolkit.Add diff --git a/image.go b/image.go index 2943142..e159168 100644 --- a/image.go +++ b/image.go @@ -6,7 +6,7 @@ import ( func (n *Node) NewImage(name string) *Node { var newNode *Node - newNode = n.New(name, toolkit.Image, nil) + newNode = n.newNode(name, toolkit.Image, nil) var a toolkit.Action a.ActionType = toolkit.Add diff --git a/label.go b/label.go index 8dd60b9..a7548e4 100644 --- a/label.go +++ b/label.go @@ -5,7 +5,7 @@ import ( ) func (n *Node) NewLabel(text string) *Node { - newNode := n.New(text, toolkit.Label, nil) + newNode := n.newNode(text, toolkit.Label, nil) var a toolkit.Action a.ActionType = toolkit.Add diff --git a/main.go b/main.go index d385401..5a2407e 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ func init() { Config.rootNode.WidgetType = toolkit.Root // used to pass debugging flags to the toolkit plugins - Config.flag = Config.rootNode.New("flag", 0, nil) + Config.flag = Config.rootNode.newNode("flag", 0, nil) Config.flag.WidgetType = toolkit.Flag Config.guiChan = make(chan toolkit.Action) @@ -173,12 +173,12 @@ func (n *Node) doUserEvent(a toolkit.Action) { } } -func (n *Node) LoadPlugin(name string) bool { - StartS(name) +func LoadPlugin(name string) bool { + startS(name) return true } -func StartS(name string) *Node { +func startS(name string) *Node { log(logInfo, "Start() Main(f) for name =", name) aplug := LoadToolkit(name) if (aplug == nil) { diff --git a/node.go b/node.go index 30ebf02..1454858 100644 --- a/node.go +++ b/node.go @@ -5,7 +5,7 @@ import "git.wit.org/wit/gui/toolkit" /* generic function to create a new node on the binary tree */ -func (n *Node) New(title string, t toolkit.WidgetType, custom func()) *Node { +func (n *Node) newNode(title string, t toolkit.WidgetType, custom func()) *Node { var newN *Node newN = addNode(title) diff --git a/slider.go b/slider.go index 129930d..c222d7b 100644 --- a/slider.go +++ b/slider.go @@ -5,7 +5,7 @@ import ( ) func (n *Node) NewSlider(name string, x int, y int) *Node { - newNode := n.New(name, toolkit.Slider, func() { + newNode := n.newNode(name, toolkit.Slider, func() { log(debugGui, "even newer clicker() name in NewSlider name =", name) }) diff --git a/spinner.go b/spinner.go index 4b0b3aa..9789759 100644 --- a/spinner.go +++ b/spinner.go @@ -5,7 +5,7 @@ import ( ) func (n *Node) NewSpinner(name string, x int, y int) *Node { - newNode := n.New(name, toolkit.Spinner, func() { + newNode := n.newNode(name, toolkit.Spinner, func() { log(debugChange, "default NewSpinner() change", name) }) diff --git a/tab.go b/tab.go index 49632ee..41013bd 100644 --- a/tab.go +++ b/tab.go @@ -8,7 +8,7 @@ import ( // the 'tab' as a child func (n *Node) NewTab(text string) *Node { - newNode := n.New(text, toolkit.Tab, nil) + newNode := n.newNode(text, toolkit.Tab, nil) var a toolkit.Action a.ActionType = toolkit.Add diff --git a/textbox.go b/textbox.go index f8208b9..63b14b0 100644 --- a/textbox.go +++ b/textbox.go @@ -5,7 +5,7 @@ import ( ) func (n *Node) NewTextbox(name string) *Node { - newNode := n.New(name, toolkit.Textbox, func() { + newNode := n.newNode(name, toolkit.Textbox, func() { log(debugGui, "NewTextbox changed =", name) }) diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go index 2a1b677..e6f3305 100644 --- a/toolkit/andlabs/add.go +++ b/toolkit/andlabs/add.go @@ -47,7 +47,10 @@ func add(a *toolkit.Action) { doWindow(a) return case toolkit.Tab: - newTab(a) + log(debugError, "add() CAME AT THIS FROM add() =", a.Name) + log(debugError, "add() CAME AT THIS FROM add() =", a.Name) + log(debugError, "add() CAME AT THIS FROM add() =", a.Name) + newTab(*a) return case toolkit.Label: newLabel(a) diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go index a8c8b39..c107038 100644 --- a/toolkit/andlabs/main.go +++ b/toolkit/andlabs/main.go @@ -26,20 +26,15 @@ func catchActionChannel() { if (a.WidgetType == toolkit.Window) { log(logNow, "makeCallback() WINDOW START") go ui.Main( func() { - log(logNow, "ui.Main() WINDOW START") - rawAction(&a) + log(logNow, "ui.Main() WINDOW START DOING NOTHING") + newWindow(&a) log(logNow, "ui.Main() WINDOW END") }) sleep(.5) log(logNow, "makeCallback() WINDOW END") } else { log(logNow, "makeCallback() STUFF") - rawAction(&a) - /* - Queue( func() { - rawAction(&a) - }) - */ + rawAction(a) log(logNow, "makeCallback() STUFF END") } // sleep(.1) diff --git a/toolkit/andlabs/plugin.go b/toolkit/andlabs/plugin.go index f7577d1..f319add 100644 --- a/toolkit/andlabs/plugin.go +++ b/toolkit/andlabs/plugin.go @@ -22,7 +22,8 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { log(debugPlugin, "Send() goodbye. not used anymore") } -func Action(a *toolkit.Action) { + +func oldAction(a *toolkit.Action) { log(logNow, "Action() START") if (a == nil) { log(debugPlugin, "Action = nil") @@ -40,34 +41,35 @@ func Action(a *toolkit.Action) { log(logNow, "Action() END") } -func rawAction(a *toolkit.Action) { + +func rawAction(a toolkit.Action) { log(debugAction, "rawAction() START a.ActionType =", a.ActionType) log(debugAction, "rawAction() START a.S =", a.S) log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId) switch a.WidgetType { case toolkit.Flag: - flag(a) + flag(&a) return } switch a.ActionType { case toolkit.Add: - add(a) + add(&a) case toolkit.Show: a.B = true - show(a) + show(&a) case toolkit.Hide: a.B = false - show(a) + show(&a) case toolkit.Enable: a.B = true - enable(a) + enable(&a) case toolkit.Disable: a.B = false - enable(a) + enable(&a) case toolkit.Get: - setText(a) + setText(&a) case toolkit.GetText: switch a.WidgetType { case toolkit.Textbox: @@ -75,24 +77,24 @@ func rawAction(a *toolkit.Action) { a.S = t.s } case toolkit.Set: - setText(a) + setText(&a) case toolkit.SetText: - setText(a) + setText(&a) case toolkit.AddText: - setText(a) + setText(&a) case toolkit.Margin: - pad(a) + pad(&a) case toolkit.Unmargin: - pad(a) + pad(&a) case toolkit.Pad: - pad(a) + pad(&a) case toolkit.Unpad: - pad(a) + pad(&a) case toolkit.Delete: - uiDelete(a) + uiDelete(&a) case toolkit.Move: log(debugNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType) - move(a) + move(&a) default: log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType) } diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go index a9a3e38..6936df6 100644 --- a/toolkit/andlabs/tab.go +++ b/toolkit/andlabs/tab.go @@ -19,7 +19,7 @@ import ( once there is one. If you send a Window here, it will replace any existing tabs rather than adding a new one */ -func (t *andlabsT) newTab(a *toolkit.Action) { +func (t *andlabsT) newTab(a toolkit.Action) { // var w *ui.Window var newt *andlabsT @@ -118,7 +118,7 @@ func (t *andlabsT) appendTab(name string) *andlabsT { return &newT } -func newTab(a *toolkit.Action) { +func newTab(a toolkit.Action) { // w := a.Widget log(debugToolkit, "newTab()", a.ParentId) diff --git a/toolkit/andlabs/window.go b/toolkit/andlabs/window.go index cfa419f..9e2e950 100644 --- a/toolkit/andlabs/window.go +++ b/toolkit/andlabs/window.go @@ -30,12 +30,12 @@ func newWindow(a *toolkit.Action) { newt.doUserEvent() return true }) - win.Show() newt.uiWindow = win newt.uiControl = win newt.Name = a.Name andlabs[a.WidgetId] = newt + win.Show() return } diff --git a/window.go b/window.go index 95cb92c..dbdca01 100644 --- a/window.go +++ b/window.go @@ -32,7 +32,7 @@ func NewWindow() *Node { } } // Windows are created off of the master node of the Binary Tree - newNode = Config.rootNode.New(Config.Title, toolkit.Window, custom) + newNode = Config.rootNode.newNode(Config.Title, toolkit.Window, custom) log(logInfo, "NewWindow()", Config.Title) @@ -53,7 +53,7 @@ func (n *Node) NewWindow2(title string) *Node { var newNode *Node // Windows are created off of the master node of the Binary Tree - newNode = n.New(Config.Title, toolkit.Window, StandardExit) + newNode = n.newNode(Config.Title, toolkit.Window, StandardExit) log(logInfo, "NewWindow()", Config.Title)