summaryrefslogtreecommitdiff
path: root/toolkit/andlabs
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-12-14 10:36:56 -0600
committerJeff Carr <[email protected]>2023-12-14 10:36:56 -0600
commit282119d970faed3f8a60d5105a2f26ee14681ff4 (patch)
tree1680731c899f0e147487b9ba4d50ace2f3e96eb1 /toolkit/andlabs
parent9d075afb1df62276dea06be4a188eaee8fc69420 (diff)
tabs, windows + gocui dropdown menu (almost)
dropdown menu figures out what text was clicked dropdown menu movement changes line colors dropdown menus force user to select a response accidentally committed a binary tab selection works tab and window views almost working tabs and windows almost working window widgets selection works better color handling using gocui view.Visable flag removal of old color setting code still need an artificial delay for andlabs SetText() catching more 'nil' errors fixed the stupid duplicate tab problem in andlabs figured out how andlabs had a tab/box mess works on more than one domain builds and runs again debugging double tabs in andlabs gui GO111MODULE compile notes code reorg further improvements example cloudflare app does first successful dns update add NewEntryLine() for single line entry boxes Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/andlabs')
-rw-r--r--toolkit/andlabs/action.go30
-rw-r--r--toolkit/andlabs/add.go3
-rw-r--r--toolkit/andlabs/button.go3
-rw-r--r--toolkit/andlabs/debug.go42
-rw-r--r--toolkit/andlabs/main.go5
-rw-r--r--toolkit/andlabs/setText.go16
-rw-r--r--toolkit/andlabs/structs.go3
-rw-r--r--toolkit/andlabs/tab.go29
-rw-r--r--toolkit/andlabs/textbox.go25
9 files changed, 125 insertions, 31 deletions
diff --git a/toolkit/andlabs/action.go b/toolkit/andlabs/action.go
index c792a09..16a895b 100644
--- a/toolkit/andlabs/action.go
+++ b/toolkit/andlabs/action.go
@@ -1,6 +1,7 @@
package main
import (
+ "strconv"
"github.com/andlabs/ui"
"git.wit.org/wit/gui/toolkit"
)
@@ -20,6 +21,9 @@ func (n *node) show(b bool) {
}
func (n *node) enable(b bool) {
+ if n == nil {
+ panic("WHAT? enable was passed nil. How does this even happen?")
+ }
if n.tk == nil {
return
}
@@ -193,12 +197,32 @@ func rawAction(a toolkit.Action) {
n := rootNode.findWidgetId(a.WidgetId)
- switch a.ActionType {
- case toolkit.Add:
+ if (a.ActionType == toolkit.Add) {
ui.QueueMain(func() {
add(a)
})
- sleep(.05)
+ // TODO: remove this artificial delay
+ // sleep(.001)
+ return
+ }
+
+ if (a.ActionType == toolkit.Dump) {
+ log(debugNow, "rawAction() Dump =", a.ActionType, a.WidgetType, n.Name)
+ rootNode.listChildren(true)
+ return
+ }
+
+ if (n == nil) {
+ rootNode.listChildren(true)
+ log(true, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
+ log(true, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId)
+ log(true, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
+ log(true, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId)
+ return
+ panic("findWidgetId found nil for id = " + strconv.Itoa(a.WidgetId))
+ }
+
+ switch a.ActionType {
case toolkit.Show:
n.show(true)
case toolkit.Hide:
diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go
index fcdc56b..b01dd20 100644
--- a/toolkit/andlabs/add.go
+++ b/toolkit/andlabs/add.go
@@ -134,6 +134,9 @@ func (p *node) place(n *node) bool {
log(logError, "n.tk.uiControl == nil", n.tk)
panic("n.tk.uiControl == nil")
}
+ log(logError, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.Name, n.Text, n.WidgetType)
+ log(logError, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.Name, p.Text, p.WidgetType)
+ // panic("n.tk.uiControl == nil")
p.tk.uiTab.Append(n.Text, n.tk.uiControl)
p.tk.boxC += 1
return true
diff --git a/toolkit/andlabs/button.go b/toolkit/andlabs/button.go
index a6260b5..d61c0ea 100644
--- a/toolkit/andlabs/button.go
+++ b/toolkit/andlabs/button.go
@@ -6,7 +6,7 @@ import (
)
func (p *node) newButton(n *node) {
- log(debugToolkit, "newButton()", n.Name)
+ log(debugToolkit, "newButton() START", n.Name)
t := p.tk
if (t == nil) {
@@ -27,4 +27,5 @@ func (p *node) newButton(n *node) {
n.tk = newt
p.place(n)
+ log(debugToolkit, "newButton() END", n.Name)
}
diff --git a/toolkit/andlabs/debug.go b/toolkit/andlabs/debug.go
index 7abd2d1..87e875d 100644
--- a/toolkit/andlabs/debug.go
+++ b/toolkit/andlabs/debug.go
@@ -1,6 +1,9 @@
package main
-import "git.wit.org/wit/gui/toolkit"
+import (
+ "strconv"
+ "git.wit.org/wit/gui/toolkit"
+)
var defaultBehavior bool = true
@@ -126,3 +129,40 @@ func flag(a *toolkit.Action) {
log(debugError, "Can't set unknown flag", a.S)
}
}
+
+func (n *node) dumpWidget(b bool) {
+ var info, d string
+
+ if (n == nil) {
+ log(debugError, "dumpWidget() node == nil")
+ return
+ }
+ info = n.WidgetType.String()
+
+ d = strconv.Itoa(n.WidgetId) + " " + info + " " + n.Name
+
+ var tabs string
+ for i := 0; i < listChildrenDepth; i++ {
+ tabs = tabs + defaultPadding
+ }
+ log(b, tabs + d)
+}
+
+var defaultPadding string = " "
+var listChildrenDepth int = 0
+
+func (n *node) listChildren(dump bool) {
+ if (n == nil) {
+ return
+ }
+
+ n.dumpWidget(dump)
+ if len(n.children) == 0 {
+ return
+ }
+ for _, child := range n.children {
+ listChildrenDepth += 1
+ child.listChildren(dump)
+ listChildrenDepth -= 1
+ }
+}
diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go
index f66849d..3ba3079 100644
--- a/toolkit/andlabs/main.go
+++ b/toolkit/andlabs/main.go
@@ -30,7 +30,8 @@ func catchActionChannel() {
muAction.Lock()
// TODO ui.QueueMain(f)
// TODO ui.QueueMain( func() {rawAction(a)} )
- rawAction(a)
+ ui.QueueMain( func() {rawAction(a)} )
+ // rawAction(a)
muAction.Unlock()
log(logInfo, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
}
@@ -57,7 +58,7 @@ func init() {
log(logNow, "Init() START")
log(debugToolkit, "Init()")
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
- // log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
+ // log(debugToolkit, "init() Setting defaultBehavior = true")
setDefaultBehavior(true)
// andlabs = make(map[int]*andlabsT)
diff --git a/toolkit/andlabs/setText.go b/toolkit/andlabs/setText.go
index 11de327..a3332f5 100644
--- a/toolkit/andlabs/setText.go
+++ b/toolkit/andlabs/setText.go
@@ -5,6 +5,7 @@ import (
)
func (n *node) setText(a *toolkit.Action) {
+ log(debugChange, "setText() START with a.S =", a.S)
t := n.tk
if (t == nil) {
log(debugError, "setText error. tk == nil", n.Name, n.WidgetId)
@@ -34,9 +35,19 @@ func (n *node) setText(a *toolkit.Action) {
case toolkit.Textbox:
switch a.ActionType {
case toolkit.Set:
- t.uiMultilineEntry.SetText(a.S)
+ if (t.uiEntry != nil) {
+ t.uiEntry.SetText(a.S)
+ }
+ if (t.uiMultilineEntry != nil) {
+ t.uiMultilineEntry.SetText(a.S)
+ }
case toolkit.SetText:
- t.uiMultilineEntry.SetText(a.S)
+ if (t.uiEntry != nil) {
+ t.uiEntry.SetText(a.S)
+ }
+ if (t.uiMultilineEntry != nil) {
+ t.uiMultilineEntry.SetText(a.S)
+ }
default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", n.Name)
}
@@ -113,4 +124,5 @@ func (n *node) setText(a *toolkit.Action) {
default:
log(debugError, "plugin Send() Don't know how to setText on", n.WidgetType, "yet", a.ActionType)
}
+ log(debugChange, "setText() END with a.S =", a.S)
}
diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go
index c71732d..507a50c 100644
--- a/toolkit/andlabs/structs.go
+++ b/toolkit/andlabs/structs.go
@@ -51,6 +51,9 @@ type andlabsT struct {
parent *andlabsT
children []*andlabsT
+ // used to track if a tab has a child widget yet
+ child bool
+
uiControl ui.Control
uiBox *ui.Box
diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go
index eecebfa..2f44b03 100644
--- a/toolkit/andlabs/tab.go
+++ b/toolkit/andlabs/tab.go
@@ -23,7 +23,7 @@ func (p *node) newTab(n *node) {
var newt *andlabsT
if (p.WidgetType != toolkit.Window) {
- log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
+ log(debugError, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
return
}
t := p.tk
@@ -38,7 +38,15 @@ func (p *node) newTab(n *node) {
} else {
// this means you have to append a tab
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
- newt = t.appendTab(n.Text)
+ if (n.WidgetType == toolkit.Tab) {
+ // andlabs doesn't have multiple tab widgets so make a fake one?
+ // this makes a andlabsT internal structure with the parent values
+ newt = new(andlabsT)
+ newt.uiWindow = t.uiWindow
+ newt.uiTab = t.uiTab
+ } else {
+ newt = t.appendTab(n.Text)
+ }
}
n.tk = newt
@@ -63,7 +71,7 @@ func rawTab(w *ui.Window, name string) *andlabsT {
log(debugError, "UiWindow == nil. I can't add a tab without a window")
log(debugError, "UiWindow == nil. I can't add a tab without a window")
log(debugError, "UiWindow == nil. I can't add a tab without a window")
- sleep(1)
+ // sleep(1)
return nil
}
@@ -77,13 +85,13 @@ func rawTab(w *ui.Window, name string) *andlabsT {
func (t *andlabsT) appendTab(name string) *andlabsT {
var newT andlabsT
- log(debugToolkit, "gui.toolkit.NewTab() ADD", name)
+ log(debugToolkit, "appendTab() ADD", name)
if (t.uiTab == nil) {
- log(debugToolkit, "gui.Toolkit.UiWindow == nil. I can't add a widget without a place to put it")
+ log(debugToolkit, "UiWindow == nil. I can't add a widget without a place to put it")
panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
}
- log(debugToolkit, "gui.toolkit.AddTab() START name =", name)
+ log(debugToolkit, "appendTab() START name =", name)
var hbox *ui.Box
if (defaultBehavior) {
@@ -103,12 +111,3 @@ func (t *andlabsT) appendTab(name string) *andlabsT {
newT.uiBox = hbox
return &newT
}
-
-/*
-func newTab(n *node) {
- log(logInfo, "newTab() add to parent id:", n.ParentId)
-
- p := n.parent
- p.newTab(n)
-}
-*/
diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go
index 56788d8..1745d11 100644
--- a/toolkit/andlabs/textbox.go
+++ b/toolkit/andlabs/textbox.go
@@ -8,14 +8,25 @@ import (
func (p *node) newTextbox(n *node) {
newt := new(andlabsT)
- e := ui.NewNonWrappingMultilineEntry()
- newt.uiMultilineEntry = e
- newt.uiControl = e
+ if (n.X == 1) {
+ e := ui.NewEntry()
+ newt.uiEntry = e
+ newt.uiControl = e
- e.OnChanged(func(spin *ui.MultilineEntry) {
- n.S = spin.Text()
- n.doUserEvent()
- })
+ e.OnChanged(func(spin *ui.Entry) {
+ n.S = spin.Text()
+ n.doUserEvent()
+ })
+ } else {
+ e := ui.NewNonWrappingMultilineEntry()
+ newt.uiMultilineEntry = e
+ newt.uiControl = e
+
+ e.OnChanged(func(spin *ui.MultilineEntry) {
+ n.S = spin.Text()
+ n.doUserEvent()
+ })
+ }
n.tk = newt
p.place(n)
}