summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-12-16 06:57:39 -0600
committerJeff Carr <[email protected]>2023-12-16 06:57:39 -0600
commit87ab9a958d9eb9f4db35d5c9f9ce923df3132dad (patch)
treefd3ee29d828e9e69175a6ca04fec6ae0fe60fcc0
parentdcce32583387be7fc4f6cd8c8dea62fd7dc42ecf (diff)
gocui: fixes to labels + line entriesv0.8.8.1v0.8.8
correct line hight dump non-working size rectangle code somehow works better better dropdown menu debugging minor fixes to common.go more common code Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--examples/cloudflare/main.go12
-rw-r--r--toolkit/andlabs/action.go12
-rw-r--r--toolkit/andlabs/add.go6
-rw-r--r--toolkit/andlabs/main.go23
-rw-r--r--toolkit/andlabs/structs.go35
-rw-r--r--toolkit/gocui/click.go14
-rw-r--r--toolkit/gocui/debug.go9
-rw-r--r--toolkit/gocui/help.go1
-rw-r--r--toolkit/gocui/keybindings.go14
-rw-r--r--toolkit/gocui/main.go28
-rw-r--r--toolkit/gocui/place.go16
-rw-r--r--toolkit/gocui/showStdout.go10
-rw-r--r--toolkit/gocui/structs.go6
-rw-r--r--toolkit/gocui/tab.go16
-rw-r--r--toolkit/gocui/view.go50
-rw-r--r--toolkit/nocui/action.go8
-rw-r--r--toolkit/nocui/common.go64
-rw-r--r--toolkit/nocui/main.go8
-rw-r--r--toolkit/nocui/stdin.go6
19 files changed, 136 insertions, 202 deletions
diff --git a/examples/cloudflare/main.go b/examples/cloudflare/main.go
index badf97a..4e72668 100644
--- a/examples/cloudflare/main.go
+++ b/examples/cloudflare/main.go
@@ -88,11 +88,11 @@ func makeConfigTab(window *gui.Node) {
grid := g1.NewGrid("credsGrid", 2, 4) // width = 2
grid.NewLabel("Auth Key")
- aw := grid.NewEntryLine(os.Getenv("CLOUDFLARE_AUTHKEY"))
+ aw := grid.NewEntryLine("CLOUDFLARE_AUTHKEY")
aw.SetText(os.Getenv("CLOUDFLARE_AUTHKEY"))
grid.NewLabel("Email")
- ew := grid.NewEntryLine(os.Getenv("CLOUDFLARE_EMAIL"))
+ ew := grid.NewEntryLine("CLOUDFLARE_EMAIL")
ew.SetText(os.Getenv("CLOUDFLARE_EMAIL"))
var url string = "https://api.cloudflare.com/client/v4/zones/"
@@ -144,16 +144,16 @@ func showCloudflareCredentials(box *gui.Node) {
grid := box.NewGrid("credsGrid", 2, 4) // width = 2
grid.NewLabel("Domain")
- domainWidget = grid.NewEntryLine(os.Getenv("CLOUDFLARE_DOMAIN"))
+ domainWidget = grid.NewEntryLine("CLOUDFLARE_DOMAIN")
grid.NewLabel("Zone ID")
- zoneWidget = grid.NewEntryLine(os.Getenv("CLOUDFLARE_ZONEID"))
+ zoneWidget = grid.NewEntryLine("CLOUDFLARE_ZONEID")
grid.NewLabel("Auth Key")
- authWidget = grid.NewEntryLine(os.Getenv("CLOUDFLARE_AUTHKEY"))
+ authWidget = grid.NewEntryLine("CLOUDFLARE_AUTHKEY")
grid.NewLabel("Email")
- emailWidget = grid.NewEntryLine(os.Getenv("CLOUDFLARE_EMAIL"))
+ emailWidget = grid.NewEntryLine("CLOUDFLARE_EMAIL")
var url string = "https://api.cloudflare.com/client/v4/zones/"
grid.NewLabel("Cloudflare API")
diff --git a/toolkit/andlabs/action.go b/toolkit/andlabs/action.go
index 2088917..29b797a 100644
--- a/toolkit/andlabs/action.go
+++ b/toolkit/andlabs/action.go
@@ -174,7 +174,7 @@ func (n *node) Delete() {
}
}
-func rawAction(a toolkit.Action) {
+func rawAction(a *toolkit.Action) {
log(logInfo, "rawAction() START a.ActionType =", a.ActionType)
log(logInfo, "rawAction() START a.S =", a.S)
@@ -191,7 +191,7 @@ func rawAction(a toolkit.Action) {
log(logInfo, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case toolkit.Flag:
- flag(&a)
+ flag(a)
return
}
@@ -232,18 +232,18 @@ func rawAction(a toolkit.Action) {
case toolkit.Disable:
n.enable(false)
case toolkit.Get:
- n.setText(&a)
+ n.setText(a)
case toolkit.GetText:
switch a.WidgetType {
case toolkit.Textbox:
a.S = n.S
}
case toolkit.Set:
- n.setText(&a)
+ n.setText(a)
case toolkit.SetText:
- n.setText(&a)
+ n.setText(a)
case toolkit.AddText:
- n.setText(&a)
+ n.setText(a)
case toolkit.Margin:
n.pad(toolkit.Unmargin)
case toolkit.Unmargin:
diff --git a/toolkit/andlabs/add.go b/toolkit/andlabs/add.go
index 0d1ac32..9963b79 100644
--- a/toolkit/andlabs/add.go
+++ b/toolkit/andlabs/add.go
@@ -15,12 +15,12 @@ func actionDump(b bool, a *toolkit.Action) {
log(b, "actionDump() ParentId =", a.ParentId)
}
-func add(a toolkit.Action) {
+func add(a *toolkit.Action) {
if (a.WidgetType == toolkit.Root) {
- me.rootNode = addWidget(&a)
+ me.rootNode = addNode(a)
return
}
- n := addWidget(&a)
+ n := addNode(a)
p := n.parent
switch n.WidgetType {
diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go
index 4737337..e2d34a3 100644
--- a/toolkit/andlabs/main.go
+++ b/toolkit/andlabs/main.go
@@ -9,12 +9,6 @@ import (
_ "github.com/andlabs/ui/winmanifest"
)
-// this is the channel we get requests to make widgets
-var pluginChan chan toolkit.Action
-
-// the starting point of the binary tree
-// var rootNode *node
-
var uiMainUndef bool = true
var uiMain sync.Once
var muAction sync.Mutex
@@ -30,7 +24,7 @@ func catchActionChannel() {
muAction.Lock()
// TODO ui.QueueMain(f)
// TODO ui.QueueMain( func() {rawAction(a)} )
- ui.QueueMain( func() {rawAction(a)} )
+ ui.QueueMain( func() {rawAction(&a)} )
// rawAction(a)
muAction.Unlock()
log(logInfo, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
@@ -38,21 +32,6 @@ func catchActionChannel() {
}
}
-// Other goroutines must use this to access the GUI
-//
-// You can not acess / process the GUI thread directly from
-// other goroutines. This is due to the nature of how
-// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
-//
-// this sets the channel to send user events back from the plugin
-func Callback(guiCallback chan toolkit.Action) {
- callback = guiCallback
-}
-
-func PluginChannel() chan toolkit.Action {
- return pluginChan
-}
-
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func init() {
log(logNow, "Init() START")
diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go
index c5f94ee..02b9204 100644
--- a/toolkit/andlabs/structs.go
+++ b/toolkit/andlabs/structs.go
@@ -16,41 +16,6 @@ type config struct {
rootNode *node // the base of the binary tree. it should have id == 0
}
-/*
-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 *andlabsT
-}
-*/
-
// stores the raw toolkit internals
type guiWidget struct {
Width int
diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go
index cb58bc3..7c9ab24 100644
--- a/toolkit/gocui/click.go
+++ b/toolkit/gocui/click.go
@@ -93,8 +93,8 @@ func (n *node) doWidgetClick() {
log("doWidgetClick()", n.Name)
redoWindows(0,0)
case toolkit.Flag:
- // me.rootNode.redoColor(true)
- me.rootNode.dumpTree(true)
+ log("doWidgetClick() FLAG widget name =", n.Name)
+ log("doWidgetClick() if this is the dropdown menu, handle it here?")
case toolkit.Window:
if (me.currentWindow == n) {
return
@@ -155,7 +155,13 @@ func (n *node) doWidgetClick() {
}
n.doUserEvent()
case toolkit.Grid:
- n.placeGrid(n.tk.size.w0, n.tk.size.h0)
+ newR := n.realGocuiSize()
+
+ // w,h := n.logicalSize()
+ // w := newR.w1 - newR.w0
+ // h := newR.h1 - newR.h0
+
+ n.placeGrid(newR.w0, newR.h0)
n.showWidgets()
case toolkit.Box:
// w.showWidgetPlacement(logNow, "drawTree()")
@@ -267,12 +273,14 @@ func click(g *gocui.Gui, v *gocui.View) error {
}
if _, err := g.SetCurrentView(v.Name()); err != nil {
+ log(logNow, "click() END err =", err)
return err
}
log(logVerbose, "click() END")
return nil
}
+
func findUnderMouse() *node {
var found *node
var widgets []*node
diff --git a/toolkit/gocui/debug.go b/toolkit/gocui/debug.go
index 3ea31b0..7512c1e 100644
--- a/toolkit/gocui/debug.go
+++ b/toolkit/gocui/debug.go
@@ -10,7 +10,7 @@ func (n *node) dumpTree(draw bool) {
if (w == nil) {
return
}
- n.showWidgetPlacement(logNow, "Tree:")
+ n.showWidgetPlacement(logNow, "dumpTree()")
for _, child := range n.children {
child.dumpTree(draw)
@@ -33,13 +33,12 @@ func (n *node) showWidgetPlacement(b bool, s string) {
pId = n.parent.WidgetId
}
s1 = fmt.Sprintf("(wId,pId)=(%2d,%2d) ", n.WidgetId, pId)
- s1 += fmt.Sprintf("size=(%2d,%2d)(%2d,%2d,%2d,%2d)",
- w.size.Width(), w.size.Height(),
- w.size.w0, w.size.h0, w.size.w1, w.size.h1)
if n.Visible() {
s1 += fmt.Sprintf("gocui=(%2d,%2d)(%2d,%2d,%2d,%2d)",
w.gocuiSize.Width(), w.gocuiSize.Height(),
w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1)
+ } else {
+ s1 += fmt.Sprintf(" ")
}
if (n.parent != nil) {
if (n.parent.WidgetType == toolkit.Grid) {
@@ -50,7 +49,7 @@ func (n *node) showWidgetPlacement(b bool, s string) {
}
func (n *node) dumpWidget(pad string) {
- log(true, "node:", pad, n.WidgetId, "At(", n.AtW, n.AtH, ") ,", n.WidgetType, ",", n.Name)
+ log(true, "node:", pad, n.WidgetId, "At(", n.AtW, n.AtH, ") ,", n.WidgetType, ", n.Name =", n.Name, ", n.Text =", n.Text)
}
func (n *node) listWidgets() {
diff --git a/toolkit/gocui/help.go b/toolkit/gocui/help.go
index 6113257..82d5cc5 100644
--- a/toolkit/gocui/help.go
+++ b/toolkit/gocui/help.go
@@ -19,6 +19,7 @@ var helpText []string = []string{"KEYBINDINGS",
"r: redraw widgets",
"s/h: show/hide all widgets",
"L: list all widgets",
+ "M: list all widgets positions",
"q: quit()",
"p: panic()",
"o: show Stdout",
diff --git a/toolkit/gocui/keybindings.go b/toolkit/gocui/keybindings.go
index 658d09a..38ada12 100644
--- a/toolkit/gocui/keybindings.go
+++ b/toolkit/gocui/keybindings.go
@@ -29,6 +29,9 @@ func defaultKeybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModMouseCtrl, ctrlDown); err != nil {
return err
}
+// if err := g.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click); err != nil {
+// return err
+// }
/*
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, globalDown); err != nil {
return err
@@ -45,8 +48,6 @@ func addDebugKeys(g *gocui.Gui) {
// show debugging buttons
g.SetKeybinding("", 'd', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
- log(logNow, "gocui.SetKeyBinding() dumpTree() START")
- // me.rootNode.dumpTree(true)
fakeStartWidth = me.FakeW
fakeStartHeight = me.TabH + me.FramePadH
if (showDebug) {
@@ -106,6 +107,13 @@ func addDebugKeys(g *gocui.Gui) {
return nil
})
+ // list all widgets with positions
+ g.SetKeybinding("", 'M', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ me.rootNode.dumpTree(true)
+ return nil
+ })
+
// log to output window
g.SetKeybinding("", 'o', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
@@ -136,7 +144,7 @@ func addDebugKeys(g *gocui.Gui) {
var a toolkit.Action
a.B = true
a.ActionType = toolkit.EnableDebug
- me.callback <- a
+ callback <- a
logInfo = true
logVerbose = true
} else {
diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go
index 6214fcb..04e1255 100644
--- a/toolkit/gocui/main.go
+++ b/toolkit/gocui/main.go
@@ -17,7 +17,7 @@ func init() {
// init the config struct default values
Set(&me, "default")
- me.pluginChan = make(chan toolkit.Action)
+ pluginChan = make(chan toolkit.Action)
log(logNow, "Init() start pluginChan")
go catchActionChannel()
@@ -26,15 +26,6 @@ func init() {
sleep(.1) // probably not needed, but in here for now under development
}
-// this sets the channel to send user events back from the plugin
-func Callback(guiCallback chan toolkit.Action) {
- me.callback = guiCallback
-}
-
-func PluginChannel() chan toolkit.Action {
- return me.pluginChan
-}
-
/*
recieves requests from the program to do things like:
* add new widgets
@@ -46,7 +37,7 @@ func catchActionChannel() {
for {
log(logInfo, "catchActionChannel() infinite for() loop restarted select on channel")
select {
- case a := <-me.pluginChan:
+ case a := <-pluginChan:
if (me.baseGui == nil) {
// something went wrong initializing the gocui
log(logError,"ERROR: console did not initialize")
@@ -60,22 +51,29 @@ func catchActionChannel() {
func Exit() {
// TODO: what should actually happen here?
+ log(true, "Exit() here. doing standardExit()")
standardExit()
}
func standardExit() {
+ log(true, "standardExit() doing baseGui.Close()")
me.baseGui.Close()
+ log(true, "standardExit() doing outf.Close()")
outf.Close()
- setOutput(os.Stdout)
- sendBackQuit()
- sleep(.5)
+ // log(true, "standardExit() setOutput(os.Stdout)")
+ // setOutput(os.Stdout)
+ log(true, "standardExit() send back Quit()")
+ go sendBackQuit() // don't stall here in case the
+ // induces a delay in case the callback channel is broken
+ sleep(1)
+ log(true, "standardExit() exit()")
exit()
}
func sendBackQuit() {
// send 'Quit' back to the program (?)
var a toolkit.Action
a.ActionType = toolkit.UserQuit
- me.callback <- a
+ callback <- a
}
var outf *os.File
diff --git a/toolkit/gocui/place.go b/toolkit/gocui/place.go
index d02624e..f020257 100644
--- a/toolkit/gocui/place.go
+++ b/toolkit/gocui/place.go
@@ -9,8 +9,6 @@ func (n *node) placeBox(startW int, startH int) {
if (n.WidgetType != toolkit.Box) {
return
}
- n.tk.size.w0 = startW
- n.tk.size.h0 = startH
n.showWidgetPlacement(logNow, "boxS()")
newW := startW
@@ -18,7 +16,6 @@ func (n *node) placeBox(startW int, startH int) {
for _, child := range n.children {
child.placeWidgets(newW, newH)
// n.showWidgetPlacement(logNow, "boxS()")
- // w,h := child.logicalSize()
newR := child.realGocuiSize()
w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
@@ -32,13 +29,10 @@ func (n *node) placeBox(startW int, startH int) {
newH += h
}
}
- // w,h := n.logicalSize()
- newR := n.realGocuiSize()
- w := newR.w1 - newR.w0
- h := newR.h1 - newR.h0
- n.tk.size.w1 = n.tk.size.w0 + w
- n.tk.size.h1 = n.tk.size.h0 + h
+ // just compute this every time?
+ // newR := n.realGocuiSize()
+
n.showWidgetPlacement(logNow, "boxE()")
}
@@ -75,7 +69,6 @@ func (n *node) placeWidgets(startW int, startH int) {
// now move all the children aka: run place() on them
for _, child := range n.children {
child.placeWidgets(newW, newH)
- // _,h := child.logicalSize()
newR := child.realGocuiSize()
// w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
@@ -91,8 +84,6 @@ func (n *node) placeWidgets(startW int, startH int) {
func (n *node) placeGrid(startW int, startH int) {
w := n.tk
- w.size.w0 = startW
- w.size.h0 = startH
n.showWidgetPlacement(logInfo, "grid0:")
if (n.WidgetType != toolkit.Grid) {
return
@@ -100,7 +91,6 @@ func (n *node) placeGrid(startW int, startH int) {
// first compute the max sizes of the rows and columns
for _, child := range n.children {
- // childW, childH := child.logicalSize()
newR := child.realGocuiSize()
childW := newR.w1 - newR.w0
childH := newR.h1 - newR.h0
diff --git a/toolkit/gocui/showStdout.go b/toolkit/gocui/showStdout.go
index f03dfef..34f7e7b 100644
--- a/toolkit/gocui/showStdout.go
+++ b/toolkit/gocui/showStdout.go
@@ -62,9 +62,9 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
}
v, err := g.View("msg")
if (v == nil) {
- log("this is supposed to happen. v == nil", err)
+ log("makeoutputwindow() this is supposed to happen. v == nil", err)
} else {
- log("msg != nil. WTF now? err =", err)
+ log("makeoutputwindow() msg != nil. WTF now? err =", err)
}
// help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0)
@@ -72,16 +72,16 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
v, err = g.SetView("msg", maxX-32, maxY/2, maxX/2+outputW, maxY/2+outputH, 0)
if errors.Is(err, gocui.ErrUnknownView) {
- log("this is supposed to happen?", err)
+ log("makeoutputwindow() this is supposed to happen?", err)
}
if (err != nil) {
- log("create output window failed", err)
+ log("makeoutputwindow() create output window failed", err)
return nil
}
if (v == nil) {
- log("msg == nil. WTF now? err =", err)
+ log("makeoutputwindow() msg == nil. WTF now? err =", err)
return nil
} else {
me.logStdout.tk.v = v
diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go
index c61e7ad..ff97d23 100644
--- a/toolkit/gocui/structs.go
+++ b/toolkit/gocui/structs.go
@@ -15,7 +15,7 @@ import (
"sync"
"strings"
"github.com/awesome-gocui/gocui"
- "git.wit.org/wit/gui/toolkit"
+// "git.wit.org/wit/gui/toolkit"
)
// It's probably a terrible idea to call this 'me'
@@ -40,12 +40,14 @@ type config struct {
ddClicked bool // the dropdown menu view was clicked
ddNode *node // the dropdown menu is for this widget
+ /*
// this is the channel we send user events like
// mouse clicks or keyboard events back to the program
callback chan toolkit.Action
// this is the channel we get requests to make widgets
pluginChan chan toolkit.Action
+ */
// When the widget has a frame, like a button, it adds 2 lines runes on each side
// so you need 3 char spacing in each direction to not have them overlap
@@ -117,7 +119,7 @@ type guiWidget struct {
// the logical size of the widget
// For example, 40x12 would be the center of a normal terminal
- size rectType
+ // size rectType
// the actual gocui display view of this widget
// sometimes this isn't visible like with a Box or Grid
diff --git a/toolkit/gocui/tab.go b/toolkit/gocui/tab.go
index 3451e5c..90c2d1a 100644
--- a/toolkit/gocui/tab.go
+++ b/toolkit/gocui/tab.go
@@ -36,17 +36,13 @@ func (n *node) gocuiSetWH(sizeW, sizeH int) {
}
if tk.frame {
- tk.size.w0 = sizeW
- tk.size.h0 = sizeH
- tk.gocuiSize.w0 = tk.size.w0
- tk.gocuiSize.h0 = tk.size.h0
+ tk.gocuiSize.w0 = sizeW
+ tk.gocuiSize.h0 = sizeH
tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + me.FramePadW
tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + me.FramePadH
} else {
- tk.size.w0 = sizeW - 1
- tk.size.h0 = sizeH - 1
- tk.gocuiSize.w0 = tk.size.w0
- tk.gocuiSize.h0 = tk.size.h0
+ tk.gocuiSize.w0 = sizeW - 1
+ tk.gocuiSize.h0 = sizeH - 1
tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + 1
tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + 1
}
@@ -73,8 +69,6 @@ func redoWindows(nextW int, nextH int) {
n.hasTabs = false
}
- w.size.w0 = nextW
- w.size.h0 = nextH
n.gocuiSetWH(nextW, nextH)
n.deleteView()
n.showView()
@@ -98,8 +92,6 @@ func (p *node) redoTabs(nextW int, nextH int) {
w := n.tk
w.frame = true
- w.size.w0 = nextW
- w.size.h0 = nextH
n.gocuiSetWH(nextW, nextH)
n.deleteView()
// setCurrentTab(n)
diff --git a/toolkit/gocui/view.go b/toolkit/gocui/view.go
index 3baeb66..e69bf7c 100644
--- a/toolkit/gocui/view.go
+++ b/toolkit/gocui/view.go
@@ -22,14 +22,14 @@ func splitLines(s string) []string {
func (n *node) textResize() {
w := n.tk
- var width, height int
+ var width, height int = 0, 0
for i, s := range splitLines(n.Text) {
log(logNow, "textResize() len =", len(s), i, s)
if (width < len(s)) {
width = len(s)
}
- height = i
+ height += 1
}
w.gocuiSize.w1 = w.gocuiSize.w0 + width + me.FramePadW
w.gocuiSize.h1 = w.gocuiSize.h0 + height + me.FramePadH
@@ -81,13 +81,23 @@ func (n *node) showView() {
func (n *node) recreateView() {
var err error
w := n.tk
+ log(logError, "recreateView() START", n.WidgetType, n.Name)
if (me.baseGui == nil) {
- log(logError, "showView() ERROR: me.baseGui == nil", w)
+ log(logError, "recreateView() ERROR: me.baseGui == nil", w)
return
}
+
+ // this deletes the button from gocui
me.baseGui.DeleteView(w.cuiName)
w.v = nil
+ if (n.Name == "CLOUDFLARE_EMAIL") {
+ n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
+ n.dumpWidget("jwc")
+ n.textResize()
+ n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
+ }
+
a := w.gocuiSize.w0
b := w.gocuiSize.h0
c := w.gocuiSize.w1
@@ -95,23 +105,33 @@ func (n *node) recreateView() {
w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0)
if err == nil {
- n.showWidgetPlacement(logError, "drawView()")
- log(logError, "drawView() internal plugin error err = nil")
+ n.showWidgetPlacement(logError, "recreateView()")
+ log(logError, "recreateView() internal plugin error err = nil")
return
}
if !errors.Is(err, gocui.ErrUnknownView) {
- n.showWidgetPlacement(logError, "drawView()")
- log(logError, "drawView() internal plugin error error.IS()", err)
+ n.showWidgetPlacement(logError, "recreateView()")
+ log(logError, "recreateView() internal plugin error error.IS()", err)
return
}
+ // this sets up the keybinding for the name of the window
+ // does this really need to be done? I think we probably already
+ // know everything about where all the widgets are so we could bypass
+ // the gocui package and just handle all the mouse events internally here (?)
+ // for now, the w.v.Name is a string "1", "2", "3", etc from the widgetId
+
+ // set the binding for this gocui view now that it has been created
+ // gocui handles overlaps of views so it will run on the view that is clicked on
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
+ // this actually sends the text to display to gocui
w.v.Wrap = true
w.v.Frame = w.frame
w.v.Clear()
fmt.Fprint(w.v, n.Text)
- n.showWidgetPlacement(logNow, "Window: " + n.Text)
+ // n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
+ // n.dumpWidget("jwc 2")
// if you don't do this here, it will be black & white only
if (w.color != nil) {
@@ -121,6 +141,11 @@ func (n *node) recreateView() {
w.v.SelFgColor = w.color.selFg
w.v.SelBgColor = w.color.selBg
}
+ if (n.Name == "CLOUDFLARE_EMAIL") {
+ n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
+ n.dumpTree(true)
+ }
+ log(logError, "recreateView() END")
}
func (n *node) hideWidgets() {
@@ -167,13 +192,8 @@ func (n *node) showWidgets() {
if (w.isFake) {
// don't display by default
} else {
- // if n.IsCurrent() {
- n.showWidgetPlacement(logInfo, "current:")
- n.showView()
- // } else {
- // n.showWidgetPlacement(logInfo, "not:")
- // w.drawView()
- // }
+ n.showWidgetPlacement(logInfo, "current:")
+ n.showView()
}
for _, child := range n.children {
child.showWidgets()
diff --git a/toolkit/nocui/action.go b/toolkit/nocui/action.go
index ea1a60e..2e5f20b 100644
--- a/toolkit/nocui/action.go
+++ b/toolkit/nocui/action.go
@@ -98,7 +98,7 @@ func doAction(a *toolkit.Action) {
log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case toolkit.Root:
- rootNode = addWidget(a)
+ me.rootNode = addNode(a)
log(logNow, "doAction() found rootNode")
return
case toolkit.Flag:
@@ -106,11 +106,11 @@ func doAction(a *toolkit.Action) {
return
}
- n := rootNode.findWidgetId(a.WidgetId)
+ n := me.rootNode.findWidgetId(a.WidgetId)
switch a.ActionType {
case toolkit.Add:
- addWidget(a)
+ addNode(a)
case toolkit.Show:
n.show(true)
case toolkit.Hide:
@@ -144,7 +144,7 @@ func doAction(a *toolkit.Action) {
n.Delete()
case toolkit.Move:
log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
- newParent := rootNode.findWidgetId(a.ParentId)
+ newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
log(logError, "doAction() Unknown =", a.ActionType, a.WidgetType)
diff --git a/toolkit/nocui/common.go b/toolkit/nocui/common.go
index 797f86a..786bf39 100644
--- a/toolkit/nocui/common.go
+++ b/toolkit/nocui/common.go
@@ -15,10 +15,13 @@ 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
+// this is the channel we send user events like
+// mouse clicks or keyboard events back to the program
var callback chan toolkit.Action
+// this is the channel we get requests to make widgets
+var pluginChan chan toolkit.Action
+
type node struct {
parent *node
children []*node
@@ -82,48 +85,6 @@ func (n *node) findWidgetId(id int) *node {
return nil
}
-func addWidget(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 = new(guiWidget)
-
- if (a.WidgetType == toolkit.Root) {
- log(logInfo, "addWidget() Root")
- return n
- }
-
- if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
- log(logError, "addWidget() 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)
- }
- return n
-}
-
func (n *node) doUserEvent() {
if (callback == nil) {
log(logError, "doUserEvent() callback == nil", n.WidgetId)
@@ -188,3 +149,18 @@ func addNode(a *toolkit.Action) *node {
}
return n
}
+
+// Other goroutines must use this to access the GUI
+//
+// You can not acess / process the GUI thread directly from
+// other goroutines. This is due to the nature of how
+// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
+//
+// this sets the channel to send user events back from the plugin
+func Callback(guiCallback chan toolkit.Action) {
+ callback = guiCallback
+}
+
+func PluginChannel() chan toolkit.Action {
+ return pluginChan
+}
diff --git a/toolkit/nocui/main.go b/toolkit/nocui/main.go
index a957773..942a195 100644
--- a/toolkit/nocui/main.go
+++ b/toolkit/nocui/main.go
@@ -5,12 +5,6 @@ import (
"git.wit.org/wit/gui/toolkit"
)
-// this is the channel we get requests to make widgets
-var pluginChan chan toolkit.Action
-
-// the starting point of the binary tree
-var rootNode *node
-
var muAction sync.Mutex
func catchActionChannel() {
@@ -29,6 +23,7 @@ func catchActionChannel() {
}
}
+/*
// Other goroutines must use this to access the GUI
//
// You can not acess / process the GUI thread directly from
@@ -43,6 +38,7 @@ func Callback(guiCallback chan toolkit.Action) {
func PluginChannel() chan toolkit.Action {
return pluginChan
}
+*/
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func init() {
diff --git a/toolkit/nocui/stdin.go b/toolkit/nocui/stdin.go
index 86ec664..0738d00 100644
--- a/toolkit/nocui/stdin.go
+++ b/toolkit/nocui/stdin.go
@@ -18,10 +18,10 @@ func simpleStdin() {
switch s {
case "l":
log(true, "list widgets")
- rootNode.listWidgets()
+ me.rootNode.listWidgets()
case "b":
log(true, "show buttons")
- rootNode.showButtons()
+ me.rootNode.showButtons()
case "d":
var a toolkit.Action
a.ActionType = toolkit.EnableDebug
@@ -35,7 +35,7 @@ func simpleStdin() {
default:
i, _ := strconv.Atoi(s)
log(true, "got input:", i)
- n := rootNode.findWidgetId(i)
+ n := me.rootNode.findWidgetId(i)
if (n != nil) {
n.dumpWidget("found node")
n.doUserEvent()