summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-12-15 17:18:48 -0600
committerJeff Carr <[email protected]>2023-12-15 17:18:48 -0600
commitdcce32583387be7fc4f6cd8c8dea62fd7dc42ecf (patch)
treeffbedb095816a92c69546041271acbef5870481c
parent282119d970faed3f8a60d5105a2f26ee14681ff4 (diff)
make a common.go for the toolkitsv0.8.7
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--examples/cloudflare/Makefile3
-rw-r--r--toolkit/andlabs/action.go8
-rw-r--r--toolkit/andlabs/add.go4
-rw-r--r--toolkit/andlabs/box.go2
-rw-r--r--toolkit/andlabs/button.go2
-rw-r--r--toolkit/andlabs/checkbox.go4
-rw-r--r--toolkit/andlabs/combobox.go4
l---------[-rw-r--r--]toolkit/andlabs/common.go85
-rw-r--r--toolkit/andlabs/debug.go2
-rw-r--r--toolkit/andlabs/demo.go2
-rw-r--r--toolkit/andlabs/dropdown.go6
-rw-r--r--toolkit/andlabs/grid.go4
-rw-r--r--toolkit/andlabs/group.go2
-rw-r--r--toolkit/andlabs/image.go2
-rw-r--r--toolkit/andlabs/label.go2
-rw-r--r--toolkit/andlabs/main.go2
-rw-r--r--toolkit/andlabs/slider.go2
-rw-r--r--toolkit/andlabs/spinner.go2
-rw-r--r--toolkit/andlabs/structs.go19
-rw-r--r--toolkit/andlabs/tab.go17
-rw-r--r--toolkit/andlabs/textbox.go2
-rw-r--r--toolkit/andlabs/widget.go29
-rw-r--r--toolkit/andlabs/window.go8
l---------[-rw-r--r--]toolkit/gocui/common.go212
-rw-r--r--toolkit/gocui/mouse.go15
-rw-r--r--toolkit/gocui/plugin.go19
-rw-r--r--toolkit/gocui/structs.go47
-rw-r--r--toolkit/gocui/tab.go4
-rw-r--r--toolkit/gocui/widget.go147
-rw-r--r--toolkit/nocui/common.go132
-rw-r--r--toolkit/nocui/event.go19
-rw-r--r--toolkit/nocui/structs.go46
-rw-r--r--toolkit/nocui/widget.go29
33 files changed, 419 insertions, 464 deletions
diff --git a/examples/cloudflare/Makefile b/examples/cloudflare/Makefile
index fd82fdc..32f3f55 100644
--- a/examples/cloudflare/Makefile
+++ b/examples/cloudflare/Makefile
@@ -19,3 +19,6 @@ log:
gocui: build
./cloudflare -gui gocui >/tmp/witgui.log.stderr 2>&1
+
+quiet:
+ ./cloudflare >/tmp/witgui.log.stderr 2>&1
diff --git a/toolkit/andlabs/action.go b/toolkit/andlabs/action.go
index 16a895b..2088917 100644
--- a/toolkit/andlabs/action.go
+++ b/toolkit/andlabs/action.go
@@ -195,7 +195,7 @@ func rawAction(a toolkit.Action) {
return
}
- n := rootNode.findWidgetId(a.WidgetId)
+ n := me.rootNode.findWidgetId(a.WidgetId)
if (a.ActionType == toolkit.Add) {
ui.QueueMain(func() {
@@ -208,12 +208,12 @@ func rawAction(a toolkit.Action) {
if (a.ActionType == toolkit.Dump) {
log(debugNow, "rawAction() Dump =", a.ActionType, a.WidgetType, n.Name)
- rootNode.listChildren(true)
+ me.rootNode.listChildren(true)
return
}
if (n == nil) {
- rootNode.listChildren(true)
+ me.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)
@@ -256,7 +256,7 @@ func rawAction(a toolkit.Action) {
n.Delete()
case toolkit.Move:
log(debugNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
- newParent := rootNode.findWidgetId(a.ParentId)
+ newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go
index b01dd20..0d1ac32 100644
--- a/toolkit/andlabs/add.go
+++ b/toolkit/andlabs/add.go
@@ -17,10 +17,10 @@ func actionDump(b bool, a *toolkit.Action) {
func add(a toolkit.Action) {
if (a.WidgetType == toolkit.Root) {
- rootNode = addWidget(&a, nil)
+ me.rootNode = addWidget(&a)
return
}
- n := addWidget(&a, nil)
+ n := addWidget(&a)
p := n.parent
switch n.WidgetType {
diff --git a/toolkit/andlabs/box.go b/toolkit/andlabs/box.go
index 8698a74..e33b7a1 100644
--- a/toolkit/andlabs/box.go
+++ b/toolkit/andlabs/box.go
@@ -9,7 +9,7 @@ import (
func (p *node) newBox(n *node) {
log(debugToolkit, "newBox()", n.Name)
- newt := new(andlabsT)
+ newt := new(guiWidget)
var box *ui.Box
log(debugToolkit, "rawBox() create", n.Name)
diff --git a/toolkit/andlabs/button.go b/toolkit/andlabs/button.go
index d61c0ea..1dbad5c 100644
--- a/toolkit/andlabs/button.go
+++ b/toolkit/andlabs/button.go
@@ -14,7 +14,7 @@ func (p *node) newButton(n *node) {
return
}
- newt := new(andlabsT)
+ newt := new(guiWidget)
b := ui.NewButton(n.Text)
newt.uiButton = b
diff --git a/toolkit/andlabs/checkbox.go b/toolkit/andlabs/checkbox.go
index 4c690c1..4c37fd6 100644
--- a/toolkit/andlabs/checkbox.go
+++ b/toolkit/andlabs/checkbox.go
@@ -6,7 +6,7 @@ import (
)
func (p *node) newCheckbox(n *node) {
- newt := new(andlabsT)
+ newt := new(guiWidget)
log(debugToolkit, "newCheckbox()", n.Name, n.WidgetType)
newt.uiCheckbox = ui.NewCheckbox(n.Text)
@@ -22,6 +22,6 @@ func (p *node) newCheckbox(n *node) {
p.place(n)
}
-func (t *andlabsT) checked() bool {
+func (t *guiWidget) checked() bool {
return t.uiCheckbox.Checked()
}
diff --git a/toolkit/andlabs/combobox.go b/toolkit/andlabs/combobox.go
index 564ff23..283a29d 100644
--- a/toolkit/andlabs/combobox.go
+++ b/toolkit/andlabs/combobox.go
@@ -6,7 +6,7 @@ import (
)
func (p *node) newCombobox(n *node) {
- newt := new(andlabsT)
+ newt := new(guiWidget)
log(debugToolkit, "newCombobox() START", n.Name)
cb := ui.NewEditableCombobox()
@@ -26,7 +26,7 @@ func (p *node) newCombobox(n *node) {
p.place(n)
}
-func (t *andlabsT) AddComboboxName(title string) {
+func (t *guiWidget) AddComboboxName(title string) {
t.uiEditableCombobox.Append(title)
if (t.val == nil) {
log(debugToolkit, "make map didn't work")
diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go
index ff157ab..35417a1 100644..120000
--- a/toolkit/andlabs/common.go
+++ b/toolkit/andlabs/common.go
@@ -1,84 +1 @@
-package main
-
-import (
- "git.wit.org/wit/gui/toolkit"
-)
-
-// searches the binary tree for a WidgetId
-func (n *node) findWidgetId(id int) *node {
- if (n == nil) {
- return nil
- }
-
- if n.WidgetId == id {
- return n
- }
-
- for _, child := range n.children {
- newN := child.findWidgetId(id)
- if (newN != nil) {
- return newN
- }
- }
- return nil
-}
-
-func addWidget(a *toolkit.Action, tk *andlabsT) *node {
- n := new(node)
- n.WidgetType = a.WidgetType
- n.WidgetId = a.WidgetId
- n.ParentId = a.ParentId
-
- // copy the data from the action message
- n.Name = a.Name
- n.Text = a.Text
- n.I = a.I
- n.S = a.S
- n.B = a.B
- n.X = a.X
- n.Y = a.Y
-
- n.W = a.W
- n.H = a.H
- n.AtW = a.AtW
- n.AtH = a.AtH
-
- // store the internal toolkit information
- n.tk = tk
-
- if (a.WidgetType == toolkit.Root) {
- log(logInfo, "addWidget() Root")
- return n
- }
-
- if (rootNode.findWidgetId(a.WidgetId) != nil) {
- log(logError, "addWidget() WidgetId already exists", a.WidgetId)
- return rootNode.findWidgetId(a.WidgetId)
- }
-
- // add this new widget on the binary tree
- n.parent = rootNode.findWidgetId(a.ParentId)
- if n.parent != nil {
- n.parent.children = append(n.parent.children, n)
- }
- return n
-}
-
-func (n *node) doUserEvent() {
- if (callback == nil) {
- log(debugError, "doUserEvent() callback == nil", n.WidgetId)
- return
- }
- var a toolkit.Action
- a.WidgetId = n.WidgetId
- a.Name = n.Name
- a.Text = n.Text
- a.S = n.S
- a.I = n.I
- a.B = n.B
- a.ActionType = toolkit.User
- log(logInfo, "doUserEvent() START: send a user event to the callback channel")
- callback <- a
- log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
- return
-}
+../nocui/common.go \ No newline at end of file
diff --git a/toolkit/andlabs/debug.go b/toolkit/andlabs/debug.go
index 87e875d..33f8c44 100644
--- a/toolkit/andlabs/debug.go
+++ b/toolkit/andlabs/debug.go
@@ -49,7 +49,7 @@ func ShowDebug () {
log(true, "debugError =", debugError)
}
-func (t *andlabsT) Dump(b bool) {
+func (t *guiWidget) Dump(b bool) {
if ! b {
return
}
diff --git a/toolkit/andlabs/demo.go b/toolkit/andlabs/demo.go
index 1b9a2b1..c3cd418 100644
--- a/toolkit/andlabs/demo.go
+++ b/toolkit/andlabs/demo.go
@@ -17,7 +17,7 @@ func BlankWindow(w *ui.Window) *ui.Box {
return hbox
}
-func (t *andlabsT) DemoNumbersPage() {
+func (t *guiWidget) DemoNumbersPage() {
var w *ui.Window
log(debugToolkit, "Starting wit/gui toolkit andlabs/ui DemoNumbersPage()")
diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go
index d98526a..e811a71 100644
--- a/toolkit/andlabs/dropdown.go
+++ b/toolkit/andlabs/dropdown.go
@@ -8,7 +8,7 @@ import (
)
func (p *node) newDropdown(n *node) {
- newt := new(andlabsT)
+ newt := new(guiWidget)
log(debugToolkit, "gui.Toolbox.newDropdown() START", n.Name)
cb := ui.NewCombobox()
@@ -34,7 +34,7 @@ func (p *node) newDropdown(n *node) {
p.place(n)
}
-func (t *andlabsT) addDropdownName(title string) {
+func (t *guiWidget) addDropdownName(title string) {
t.uiCombobox.Append(title)
if (t.val == nil) {
log(debugToolkit, "make map didn't work")
@@ -50,7 +50,7 @@ func (t *andlabsT) addDropdownName(title string) {
t.c = t.c + 1
}
-func (t *andlabsT) SetDropdown(i int) {
+func (t *guiWidget) SetDropdown(i int) {
t.uiCombobox.SetSelected(i)
}
diff --git a/toolkit/andlabs/grid.go b/toolkit/andlabs/grid.go
index 8764962..6c47d1b 100644
--- a/toolkit/andlabs/grid.go
+++ b/toolkit/andlabs/grid.go
@@ -11,10 +11,10 @@ import (
// -- (1,2) -- (2,1) -- (3,1) --
// -----------------------------
func (p *node) newGrid(n *node) {
- var newt *andlabsT
+ var newt *guiWidget
log(debugToolkit, "newGrid()", n.WidgetId, "to", n.ParentId)
- newt = new(andlabsT)
+ newt = new(guiWidget)
c := ui.NewGrid()
newt.uiGrid = c
diff --git a/toolkit/andlabs/group.go b/toolkit/andlabs/group.go
index 077aea0..b7c450e 100644
--- a/toolkit/andlabs/group.go
+++ b/toolkit/andlabs/group.go
@@ -8,7 +8,7 @@ import (
func (p *node) newGroup(n *node) {
log(debugToolkit, "NewGroup()", n.Name)
- newt := new(andlabsT)
+ newt := new(guiWidget)
log(debugToolkit, "NewGroup() create", n.Name)
diff --git a/toolkit/andlabs/image.go b/toolkit/andlabs/image.go
index a565376..bab1a9e 100644
--- a/toolkit/andlabs/image.go
+++ b/toolkit/andlabs/image.go
@@ -7,7 +7,7 @@ import (
// make new Image using andlabs/ui
func (p *node) newImage(n *node) {
- newt := new(andlabsT)
+ newt := new(guiWidget)
var img *ui.Image
log(debugToolkit, "rawImage() create", n.Name)
diff --git a/toolkit/andlabs/label.go b/toolkit/andlabs/label.go
index 0fa075e..3f06546 100644
--- a/toolkit/andlabs/label.go
+++ b/toolkit/andlabs/label.go
@@ -8,7 +8,7 @@ import (
func (p *node) newLabel(n *node) {
log(logInfo, "NewLabel()", n.Name)
- newt := new(andlabsT)
+ newt := new(guiWidget)
c := ui.NewLabel(n.Name)
newt.uiLabel = c
newt.uiControl = c
diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go
index 3ba3079..4737337 100644
--- a/toolkit/andlabs/main.go
+++ b/toolkit/andlabs/main.go
@@ -13,7 +13,7 @@ import (
var pluginChan chan toolkit.Action
// the starting point of the binary tree
-var rootNode *node
+// var rootNode *node
var uiMainUndef bool = true
var uiMain sync.Once
diff --git a/toolkit/andlabs/slider.go b/toolkit/andlabs/slider.go
index f1b4676..5098943 100644
--- a/toolkit/andlabs/slider.go
+++ b/toolkit/andlabs/slider.go
@@ -6,7 +6,7 @@ import (
)
func (p *node) newSlider(n *node) {
- newt := new(andlabsT)
+ newt := new(guiWidget)
s := ui.NewSlider(n.X, n.Y)
newt.uiSlider = s
diff --git a/toolkit/andlabs/spinner.go b/toolkit/andlabs/spinner.go
index b7d5947..bab7a29 100644
--- a/toolkit/andlabs/spinner.go
+++ b/toolkit/andlabs/spinner.go
@@ -6,7 +6,7 @@ import (
)
func (p *node) newSpinner(n *node) {
- newt := new(andlabsT)
+ newt := new(guiWidget)
s := ui.NewSpinbox(n.X, n.Y)
newt.uiSpinbox = s
diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go
index 507a50c..c5f94ee 100644
--- a/toolkit/andlabs/structs.go
+++ b/toolkit/andlabs/structs.go
@@ -1,14 +1,22 @@
package main
-import "git.wit.org/wit/gui/toolkit"
+// import "git.wit.org/wit/gui/toolkit"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
// var andlabs map[int]*andlabsT
// var callback func(int) bool
-var callback chan toolkit.Action
+// var callback chan toolkit.Action
+// It's probably a terrible idea to call this 'me'
+var me config
+
+type config struct {
+ rootNode *node // the base of the binary tree. it should have id == 0
+}
+
+/*
type node struct {
parent *node
children []*node
@@ -41,15 +49,16 @@ type node struct {
// the internal plugin toolkit structure
tk *andlabsT
}
+*/
// stores the raw toolkit internals
-type andlabsT struct {
+type guiWidget struct {
Width int
Height int
// tw *toolkit.Widget
- parent *andlabsT
- children []*andlabsT
+ parent *guiWidget
+ children []*guiWidget
// used to track if a tab has a child widget yet
child bool
diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go
index 2f44b03..aa851d1 100644
--- a/toolkit/andlabs/tab.go
+++ b/toolkit/andlabs/tab.go
@@ -20,8 +20,11 @@ import (
any existing tabs rather than adding a new one
*/
func (p *node) newTab(n *node) {
- var newt *andlabsT
+ var newt *guiWidget
+ if (p == nil) {
+ log(debugError, "newTab() p == nil. how the fuck does this happen?", n.WidgetId, n.ParentId)
+ }
if (p.WidgetType != toolkit.Window) {
log(debugError, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
return
@@ -40,8 +43,8 @@ func (p *node) newTab(n *node) {
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
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)
+ // this makes a guiWidget internal structure with the parent values
+ newt = new(guiWidget)
newt.uiWindow = t.uiWindow
newt.uiTab = t.uiTab
} else {
@@ -63,8 +66,8 @@ func tabSetMargined(tab *ui.Tab, b bool) {
}
}
-func rawTab(w *ui.Window, name string) *andlabsT {
- var newt andlabsT
+func rawTab(w *ui.Window, name string) *guiWidget {
+ var newt guiWidget
log(debugToolkit, "rawTab() START", name)
if (w == nil) {
@@ -83,8 +86,8 @@ func rawTab(w *ui.Window, name string) *andlabsT {
return &newt
}
-func (t *andlabsT) appendTab(name string) *andlabsT {
- var newT andlabsT
+func (t *guiWidget) appendTab(name string) *guiWidget {
+ var newT guiWidget
log(debugToolkit, "appendTab() ADD", name)
if (t.uiTab == nil) {
diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go
index 1745d11..7cb5d63 100644
--- a/toolkit/andlabs/textbox.go
+++ b/toolkit/andlabs/textbox.go
@@ -6,7 +6,7 @@ import (
)
func (p *node) newTextbox(n *node) {
- newt := new(andlabsT)
+ newt := new(guiWidget)
if (n.X == 1) {
e := ui.NewEntry()
diff --git a/toolkit/andlabs/widget.go b/toolkit/andlabs/widget.go
new file mode 100644
index 0000000..9155530
--- /dev/null
+++ b/toolkit/andlabs/widget.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "git.wit.org/wit/gui/toolkit"
+)
+
+// this is specific to the nocui toolkit
+func initWidget(n *node) *guiWidget {
+ var w *guiWidget
+ w = new(guiWidget)
+ // Set(w, "default")
+
+ if n.WidgetType == toolkit.Root {
+ log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
+ n.WidgetId = 0
+ me.rootNode = n
+ return w
+ }
+
+ if (n.WidgetType == toolkit.Box) {
+ if (n.B) {
+ n.horizontal = true
+ } else {
+ n.horizontal = false
+ }
+ }
+
+ return w
+}
diff --git a/toolkit/andlabs/window.go b/toolkit/andlabs/window.go
index ccc523a..f51536b 100644
--- a/toolkit/andlabs/window.go
+++ b/toolkit/andlabs/window.go
@@ -5,18 +5,18 @@ import (
_ "github.com/andlabs/ui/winmanifest"
)
-func (t *andlabsT) MessageWindow(msg1 string, msg2 string) {
+func (t *guiWidget) MessageWindow(msg1 string, msg2 string) {
ui.MsgBox(t.uiWindow, msg1, msg2)
}
-func (t *andlabsT) ErrorWindow(msg1 string, msg2 string) {
+func (t *guiWidget) ErrorWindow(msg1 string, msg2 string) {
ui.MsgBoxError(t.uiWindow, msg1, msg2)
}
func newWindow(n *node) {
- var newt *andlabsT
+ var newt *guiWidget
- newt = new(andlabsT)
+ newt = new(guiWidget)
// menubar bool is if the OS defined border on the window should be used
win := ui.NewWindow(n.Name, n.X, n.Y, menubar)
diff --git a/toolkit/gocui/common.go b/toolkit/gocui/common.go
index d3de34c..35417a1 100644..120000
--- a/toolkit/gocui/common.go
+++ b/toolkit/gocui/common.go
@@ -1,211 +1 @@
-package main
-
-import (
- "strconv"
- "git.wit.org/wit/gui/toolkit"
-)
-
-func makeWidget(n *node) *cuiWidget {
- var w *cuiWidget
- w = new(cuiWidget)
- // Set(w, "default")
-
- w.frame = true
-
- // set the name used by gocui to the id
- w.cuiName = strconv.Itoa(n.WidgetId)
-
- if n.WidgetType == toolkit.Root {
- log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
- n.WidgetId = 0
- me.rootNode = n
- return w
- }
-
- if (n.WidgetType == toolkit.Box) {
- if (n.B) {
- n.horizontal = true
- } else {
- n.horizontal = false
- }
- }
-
- if (n.WidgetType == toolkit.Grid) {
- w.widths = make(map[int]int) // how tall each row in the grid is
- w.heights = make(map[int]int) // how wide each column in the grid is
- }
-
- return w
-}
-
-func setupCtrlDownWidget() {
- a := new(toolkit.Action)
- a.Name = "ctrlDown"
- a.WidgetType = toolkit.Dialog
- a.WidgetId = -1
- a.ParentId = 0
- n := addNode(a)
-
- me.ctrlDown = n
-}
-
-func (n *node) deleteView() {
- w := n.tk
- if (w.v != nil) {
- w.v.Visible = false
- return
- }
- // make sure the view isn't really there
- me.baseGui.DeleteView(w.cuiName)
- w.v = nil
-}
-
-// searches the binary tree for a WidgetId
-func (n *node) findWidgetId(id int) *node {
- if (n == nil) {
- return nil
- }
-
- if n.WidgetId == id {
- return n
- }
-
- for _, child := range n.children {
- newN := child.findWidgetId(id)
- if (newN != nil) {
- return newN
- }
- }
- return nil
-}
-
-// searches the binary tree for a WidgetId
-func (n *node) findWidgetName(name string) *node {
- if (n == nil) {
- return nil
- }
-
- if n.tk.cuiName == name {
- return n
- }
-
- for _, child := range n.children {
- newN := child.findWidgetName(name)
- if (newN != nil) {
- return newN
- }
- }
- return nil
-}
-
-func (n *node) IsCurrent() bool {
- w := n.tk
- if (n.WidgetType == toolkit.Tab) {
- return w.isCurrent
- }
- if (n.WidgetType == toolkit.Window) {
- return w.isCurrent
- }
- if (n.WidgetType == toolkit.Root) {
- return false
- }
- return n.parent.IsCurrent()
-}
-
-func (n *node) Visible() bool {
- if (n == nil) {
- return false
- }
- if (n.tk == nil) {
- return false
- }
- if (n.tk.v == nil) {
- return false
- }
- return n.tk.v.Visible
-}
-
-func (n *node) SetVisible(b bool) {
- if (n == nil) {
- return
- }
- if (n.tk == nil) {
- return
- }
- if (n.tk.v == nil) {
- return
- }
- n.tk.v.Visible = b
-}
-
-func addNode(a *toolkit.Action) *node {
- n := new(node)
- n.WidgetType = a.WidgetType
- n.WidgetId = a.WidgetId
- n.ParentId = a.ParentId
-
- // copy the data from the action message
- n.Name = a.Name
- n.Text = a.Text
- n.I = a.I
- n.S = a.S
- n.B = a.B
-
- n.X = a.X
- n.Y = a.Y
-
- n.W = a.W
- n.H = a.H
- n.AtW = a.AtW
- n.AtH = a.AtH
-
- // store the internal toolkit information
- n.tk = makeWidget(n)
-
- if (a.WidgetType == toolkit.Root) {
- log(logInfo, "addNode() Root")
- return n
- }
-
- if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
- log(logError, "addNode() WidgetId already exists", a.WidgetId)
- return me.rootNode.findWidgetId(a.WidgetId)
- }
-
- // add this new widget on the binary tree
- n.parent = me.rootNode.findWidgetId(a.ParentId)
- if n.parent != nil {
- n.parent.children = append(n.parent.children, n)
- //w := n.tk
- //w.parent = n.parent.tk
- //w.parent.children = append(w.parent.children, w)
- }
- return n
-}
-
-func addDropdown() *node {
- n := new(node)
- n.WidgetType = toolkit.Flag
- n.WidgetId = -2
- n.ParentId = 0
-
- // copy the data from the action message
- n.Name = "DropBox"
- n.Text = "DropBox text"
-
- // store the internal toolkit information
- n.tk = new(cuiWidget)
- n.tk.frame = true
-
- // set the name used by gocui to the id
- n.tk.cuiName = "-1 dropbox"
-
- n.tk.color = &colorFlag
-
- // add this new widget on the binary tree
- n.parent = me.rootNode
- if n.parent != nil {
- n.parent.children = append(n.parent.children, n)
- }
- return n
-}
+../nocui/common.go \ No newline at end of file
diff --git a/toolkit/gocui/mouse.go b/toolkit/gocui/mouse.go
index 64786ab..50c2834 100644
--- a/toolkit/gocui/mouse.go
+++ b/toolkit/gocui/mouse.go
@@ -63,9 +63,11 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
w, h := g.MousePosition()
log(true, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", w, h)
if (me.ddClicked) {
+ me.ddClicked = false
log(true, "mouseUp() ddview is the thing that was clicked", w, h)
log(true, "mouseUp() find out what the string is here", w, h, me.ddview.tk.gocuiSize.h1)
+ var newZone string = ""
if (me.ddNode != nil) {
value := h - me.ddview.tk.gocuiSize.h0 - 1
log(true, "mouseUp() me.ddview.tk.gocuiSize.h1 =", me.ddview.tk.gocuiSize.h1)
@@ -74,10 +76,19 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
log(true, "mouseUp() value =", value, "valsLen =", valsLen)
log(true, "mouseUp() me.ddNode.vals =", me.ddNode.vals)
if ((value >= 0) && (value < valsLen)) {
- str := me.ddNode.vals[value]
- log(true, "mouseUp() value =", value, "str =", str)
+ newZone = me.ddNode.vals[value]
+ log(true, "mouseUp() value =", value, "newZone =", newZone)
}
}
+ hideDDview()
+ if (newZone != "") {
+ if (me.ddNode != nil) {
+ me.ddNode.SetText(newZone)
+ me.ddNode.S = newZone
+ me.ddNode.doUserEvent()
+ }
+ }
+ return nil
}
/*
// if there is a drop down view active, treat it like a dialog box and close it
diff --git a/toolkit/gocui/plugin.go b/toolkit/gocui/plugin.go
index 6d597b4..eae811d 100644
--- a/toolkit/gocui/plugin.go
+++ b/toolkit/gocui/plugin.go
@@ -9,7 +9,7 @@ import (
func action(a *toolkit.Action) {
log(logInfo, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
n := me.rootNode.findWidgetId(a.WidgetId)
- var w *cuiWidget
+ var w *guiWidget
if (n != nil) {
w = n.tk
}
@@ -98,20 +98,3 @@ func (n *node) Set(val any) {
log(logError, "Set() unknown type =", val, v)
}
}
-
-// this passes the user event back from the plugin
-func (n *node) doUserEvent() {
- if (me.callback == nil) {
- log(logError, "doUserEvent() no callback channel was configured")
- return
- }
- var a toolkit.Action
- a.WidgetId = n.WidgetId
- a.Name = n.Name
- a.Text = n.Text
- a.B = n.B
- a.ActionType = toolkit.User
- log(logInfo, "doUserEvent() START: send a button click callback()", a.WidgetId, a.Name)
- me.callback <- a
- log(logInfo, "doUserEvent() END: sent a button click callback()", a.WidgetId, a.Name)
-}
diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go
index 05df963..c61e7ad 100644
--- a/toolkit/gocui/structs.go
+++ b/toolkit/gocui/structs.go
@@ -96,49 +96,6 @@ var (
globalMouseDown, msgMouseDown, movingMsg bool
)
-// this is the standard binary tree structure for toolkits
-type node struct {
- parent *node
- children []*node
-
- WidgetId int // widget ID
- WidgetType toolkit.WidgetType
- ParentId int // parent ID
-
- Name string
- Text string
-
- // This is how the values are passed back and forth
- // values from things like checkboxes & dropdown's
- B bool
- I int
- S string
-
- A any // switch to this or deprecate this? pros/cons?
-
- // This is used for things like a slider(0,100)
- X int
- Y int
-
- // This is for the grid size & widget position
- W int
- H int
- AtW int
- AtH int
-
- vals []string // dropdown menu items
-
- // horizontal=true means layout widgets like books on a bookshelf
- // horizontal=false means layout widgets like books in a stack
- horizontal bool `default:false`
-
- hasTabs bool // does the window have tabs?
- currentTab bool // the visible tab
-
- // the internal plugin toolkit structure
- tk *cuiWidget
-}
-
// this is the gocui way
// corner starts at in the upper left corner
type rectType struct {
@@ -153,7 +110,7 @@ func (r *rectType) Height() int {
return r.h1 - r.h0
}
-type cuiWidget struct {
+type guiWidget struct {
// the gocui package variables
v *gocui.View // this is nil if the widget is not displayed
cuiName string // what gocui uses to reference the widget
@@ -189,7 +146,7 @@ type cuiWidget struct {
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
// be called to clear the view's buffer.
-func (w *cuiWidget) Write(p []byte) (n int, err error) {
+func (w *guiWidget) Write(p []byte) (n int, err error) {
w.tainted = true
me.writeMutex.Lock()
defer me.writeMutex.Unlock()
diff --git a/toolkit/gocui/tab.go b/toolkit/gocui/tab.go
index d910552..3451e5c 100644
--- a/toolkit/gocui/tab.go
+++ b/toolkit/gocui/tab.go
@@ -7,14 +7,14 @@ import (
"git.wit.org/wit/gui/toolkit"
)
-func (w *cuiWidget) Width() int {
+func (w *guiWidget) Width() int {
if w.frame {
return w.gocuiSize.w1 - w.gocuiSize.w0
}
return w.gocuiSize.w1 - w.gocuiSize.w0 - 1
}
-func (w *cuiWidget) Height() int {
+func (w *guiWidget) Height() int {
if w.frame {
return w.gocuiSize.h1 - w.gocuiSize.h0
}
diff --git a/toolkit/gocui/widget.go b/toolkit/gocui/widget.go
new file mode 100644
index 0000000..4afe08b
--- /dev/null
+++ b/toolkit/gocui/widget.go
@@ -0,0 +1,147 @@
+package main
+
+import (
+ "strconv"
+ "git.wit.org/wit/gui/toolkit"
+)
+
+func initWidget(n *node) *guiWidget {
+ var w *guiWidget
+ w = new(guiWidget)
+ // Set(w, "default")
+
+ w.frame = true
+
+ // set the name used by gocui to the id
+ w.cuiName = strconv.Itoa(n.WidgetId)
+
+ if n.WidgetType == toolkit.Root {
+ log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
+ n.WidgetId = 0
+ me.rootNode = n
+ return w
+ }
+
+ if (n.WidgetType == toolkit.Box) {
+ if (n.B) {
+ n.horizontal = true
+ } else {
+ n.horizontal = false
+ }
+ }
+
+ if (n.WidgetType == toolkit.Grid) {
+ w.widths = make(map[int]int) // how tall each row in the grid is
+ w.heights = make(map[int]int) // how wide each column in the grid is
+ }
+
+ return w
+}
+
+func setupCtrlDownWidget() {
+ a := new(toolkit.Action)
+ a.Name = "ctrlDown"
+ a.WidgetType = toolkit.Dialog
+ a.WidgetId = -1
+ a.ParentId = 0
+ n := addNode(a)
+
+ me.ctrlDown = n
+}
+
+func (n *node) deleteView() {
+ w := n.tk
+ if (w.v != nil) {
+ w.v.Visible = false
+ return
+ }
+ // make sure the view isn't really there
+ me.baseGui.DeleteView(w.cuiName)
+ w.v = nil
+}
+
+// searches the binary tree for a WidgetId
+func (n *node) findWidgetName(name string) *node {
+ if (n == nil) {
+ return nil
+ }
+
+ if n.tk.cuiName == name {
+ return n
+ }
+
+ for _, child := range n.children {
+ newN := child.findWidgetName(name)
+ if (newN != nil) {
+ return newN
+ }
+ }
+ return nil
+}
+
+func (n *node) IsCurrent() bool {
+ w := n.tk
+ if (n.WidgetType == toolkit.Tab) {
+ return w.isCurrent
+ }
+ if (n.WidgetType == toolkit.Window) {
+ return w.isCurrent
+ }
+ if (n.WidgetType == toolkit.Root) {
+ return false
+ }
+ return n.parent.IsCurrent()
+}
+
+func (n *node) Visible() bool {
+ if (n == nil) {
+ return false
+ }
+ if (n.tk == nil) {
+ return false
+ }
+ if (n.tk.v == nil) {
+ return false
+ }
+ return n.tk.v.Visible
+}
+
+func (n *node) SetVisible(b bool) {
+ if (n == nil) {
+ return
+ }
+ if (n.tk == nil) {
+ return
+ }
+ if (n.tk.v == nil) {
+ return
+ }
+ n.tk.v.Visible = b
+}
+
+func addDropdown() *node {
+ n := new(node)
+ n.WidgetType = toolkit.Flag
+ n.WidgetId = -2
+ n.ParentId = 0
+
+ // copy the data from the action message
+ n.Name = "DropBox"
+ n.Text = "DropBox text"
+
+ // store the internal toolkit information
+ n.tk = new(guiWidget)
+ n.tk.frame = true
+
+ // set the name used by gocui to the id
+ n.tk.cuiName = "-1 dropbox"
+
+ n.tk.color = &colorFlag
+
+ // add this new widget on the binary tree
+ n.parent = me.rootNode
+ if n.parent != nil {
+ n.parent.children = append(n.parent.children, n)
+ }
+ return n
+}
diff --git a/toolkit/nocui/common.go b/toolkit/nocui/common.go
index a012138..797f86a 100644
--- a/toolkit/nocui/common.go
+++ b/toolkit/nocui/common.go
@@ -1,9 +1,68 @@
package main
+/*
+ These code should be common to all gui plugins
+
+ There are some helper functions that are probably going to be
+ the same everywhere. Mostly due to handling the binary tree structure
+ and the channel communication
+
+ For now, it's just a symlink to the 'master' version in
+ ./toolkit/nocui/common.go
+*/
+
import (
"git.wit.org/wit/gui/toolkit"
)
+// this is the channel that sends the events from the user clicking or typing
+// back to the program using this golang package
+var callback chan toolkit.Action
+
+type node struct {
+ parent *node
+ children []*node
+
+ WidgetId int // widget ID
+ WidgetType toolkit.WidgetType
+ ParentId int // parent ID
+
+ Name string
+ Text string
+
+ // This is how the values are passed back and forth
+ // values from things like checkboxes & dropdown's
+ B bool
+ I int
+ S string
+
+ A any // switch to this or deprecate this? pros/cons?
+
+ // This is used for things like a slider(0,100)
+ X int
+ Y int
+
+ // This is for the grid size & widget position
+ W int
+ H int
+ AtW int
+ AtH int
+
+ vals []string // dropdown menu items
+
+ // horizontal=true means layout widgets like books on a bookshelf
+ // horizontal=false means layout widgets like books in a stack
+ horizontal bool `default:false`
+
+ hasTabs bool // does the window have tabs?
+ currentTab bool // the visible tab
+
+ // the internal plugin toolkit structure
+ // in the gtk plugin, it has gtk things like margin & border settings
+ // in the text console one, it has text console things like colors for menus & buttons
+ tk *guiWidget
+}
+
// searches the binary tree for a WidgetId
func (n *node) findWidgetId(id int) *node {
if (n == nil) {
@@ -45,22 +104,87 @@ func addWidget(a *toolkit.Action) *node {
n.AtH = a.AtH
// store the internal toolkit information
- n.tk = new(nocuiT)
+ n.tk = new(guiWidget)
if (a.WidgetType == toolkit.Root) {
log(logInfo, "addWidget() Root")
return n
}
- if (rootNode.findWidgetId(a.WidgetId) != nil) {
+ if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
log(logError, "addWidget() WidgetId already exists", a.WidgetId)
- return rootNode.findWidgetId(a.WidgetId)
+ return me.rootNode.findWidgetId(a.WidgetId)
+ }
+
+ // add this new widget on the binary tree
+ n.parent = me.rootNode.findWidgetId(a.ParentId)
+ if n.parent != nil {
+ n.parent.children = append(n.parent.children, n)
+ }
+ return n
+}
+
+func (n *node) doUserEvent() {
+ if (callback == nil) {
+ log(logError, "doUserEvent() callback == nil", n.WidgetId)
+ return
+ }
+ var a toolkit.Action
+ a.WidgetId = n.WidgetId
+ a.Name = n.Name
+ a.Text = n.Text
+ a.S = n.S
+ a.I = n.I
+ a.B = n.B
+ a.ActionType = toolkit.User
+ log(logInfo, "doUserEvent() START: send a user event to the callback channel")
+ callback <- a
+ log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
+ return
+}
+
+func addNode(a *toolkit.Action) *node {
+ n := new(node)
+ n.WidgetType = a.WidgetType
+ n.WidgetId = a.WidgetId
+ n.ParentId = a.ParentId
+
+ // copy the data from the action message
+ n.Name = a.Name
+ n.Text = a.Text
+ n.I = a.I
+ n.S = a.S
+ n.B = a.B
+
+ n.X = a.X
+ n.Y = a.Y
+
+ n.W = a.W
+ n.H = a.H
+ n.AtW = a.AtW
+ n.AtH = a.AtH
+
+ // store the internal toolkit information
+ n.tk = initWidget(n)
+ // n.tk = new(guiWidget)
+
+ if (a.WidgetType == toolkit.Root) {
+ log(logInfo, "addNode() Root")
+ return n
+ }
+
+ if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
+ log(logError, "addNode() WidgetId already exists", a.WidgetId)
+ return me.rootNode.findWidgetId(a.WidgetId)
}
// add this new widget on the binary tree
- n.parent = rootNode.findWidgetId(a.ParentId)
+ n.parent = me.rootNode.findWidgetId(a.ParentId)
if n.parent != nil {
n.parent.children = append(n.parent.children, n)
+ //w := n.tk
+ //w.parent = n.parent.tk
+ //w.parent.children = append(w.parent.children, w)
}
return n
}
diff --git a/toolkit/nocui/event.go b/toolkit/nocui/event.go
index 73b7ff2..1075266 100644
--- a/toolkit/nocui/event.go
+++ b/toolkit/nocui/event.go
@@ -45,22 +45,3 @@ func (n *node) doWidgetClick() {
default:
}
}
-
-func (n *node) doUserEvent() {
- if (callback == nil) {
- log(logError, "doUserEvent() callback == nil", n.WidgetId)
- return
- }
- var a toolkit.Action
- a.WidgetId = n.WidgetId
- a.Name = n.Name
- a.Text = n.Text
- a.S = n.S
- a.I = n.I
- a.B = n.B
- a.ActionType = toolkit.User
- log(logInfo, "doUserEvent() START: send a user event to the callback channel")
- callback <- a
- log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
- return
-}
diff --git a/toolkit/nocui/structs.go b/toolkit/nocui/structs.go
index c3ece3b..90c2c1e 100644
--- a/toolkit/nocui/structs.go
+++ b/toolkit/nocui/structs.go
@@ -1,47 +1,19 @@
package main
-import "git.wit.org/wit/gui/toolkit"
-
-var callback chan toolkit.Action
-
-type node struct {
- parent *node
- children []*node
-
- WidgetId int // widget ID
- WidgetType toolkit.WidgetType
- ParentId int // parent ID
-
- Name string
- Text string
-
- // This is how the values are passed back and forth
- // values from things like checkboxes & dropdown's
- B bool
- I int
- S string
-
- A any // switch to this or deprecate this? pros/cons?
-
- // This is used for things like a slider(0,100)
- X int
- Y int
-
- // This is for the grid size & widget position
- W int
- H int
- AtW int
- AtH int
-
- // the internal plugin toolkit structure
- tk *nocuiT
-}
+// import "git.wit.org/wit/gui/toolkit"
// stores the raw toolkit internals
-type nocuiT struct {
+type guiWidget struct {
Width int
Height int
c int
val map[int]string
}
+
+// It's probably a terrible idea to call this 'me'
+var me config
+
+type config struct {
+ rootNode *node // the base of the binary tree. it should have id == 0
+}
diff --git a/toolkit/nocui/widget.go b/toolkit/nocui/widget.go
new file mode 100644
index 0000000..9155530
--- /dev/null
+++ b/toolkit/nocui/widget.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ "git.wit.org/wit/gui/toolkit"
+)
+
+// this is specific to the nocui toolkit
+func initWidget(n *node) *guiWidget {
+ var w *guiWidget
+ w = new(guiWidget)
+ // Set(w, "default")
+
+ if n.WidgetType == toolkit.Root {
+ log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
+ n.WidgetId = 0
+ me.rootNode = n
+ return w
+ }
+
+ if (n.WidgetType == toolkit.Box) {
+ if (n.B) {
+ n.horizontal = true
+ } else {
+ n.horizontal = false
+ }
+ }
+
+ return w
+}