diff options
| author | Jeff Carr <[email protected]> | 2023-04-03 10:26:47 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-04-03 10:26:47 -0500 |
| commit | 4b6207743b90968d6b822032a4355e43b6ce6da9 (patch) | |
| tree | 2cb9f13d5e95f14e165f8e41e8484320b7454177 /toolkit/gocui/common.go | |
| parent | 0320ebe4bb49ea80761d77af80fa208157ffdb89 (diff) | |
gocui: working towards correct layout
make a gocui widget binary tree
more debugging cleanups
sample button app displays in gocui
geometry logic closer to correct
improvements in gocui layout
continued attempts to clean up tabs
dump binary tree
moving towards proper chan callback()
deprecate Widget.Name
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/gocui/common.go')
| -rw-r--r-- | toolkit/gocui/common.go | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/toolkit/gocui/common.go b/toolkit/gocui/common.go new file mode 100644 index 0000000..2fe82cb --- /dev/null +++ b/toolkit/gocui/common.go @@ -0,0 +1,100 @@ +package main + +import ( + "strconv" + "git.wit.org/wit/gui/toolkit" +// "github.com/awesome-gocui/gocui" +) + +func setupWidget(a *toolkit.Action) *cuiWidget { + var w *cuiWidget + w = new(cuiWidget) + + w.name = a.Name + w.text = a.Text + w.b = a.B + w.i = a.I + w.s = a.S + w.x = a.X + w.y = a.Y + w.width = a.Width + w.height = a.Height + + w.widgetType = a.WidgetType + w.id = a.WidgetId + // set the name used by gocui to the id + w.cuiName = strconv.Itoa(w.id) + + w.parent = findWidget(a.ParentId, me.rootNode) + log(logInfo, "setupWidget() w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId) + if (w.id == 0) { + me.rootNode = w + // this is the rootNode + return w + } + if (w.parent == nil) { + log(logError, "setupWidget() ERROR: PARENT = NIL w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId) + // just use the rootNode (hopefully it's not nil) + w.parent = me.rootNode + // return w + } + if (w.parent == nil) { + log(logError, "setupWidget() ERROR: PARENT = NIL w.id =", w.id, "w.parent", w.parent, "ParentId =", a.ParentId) + me.rootNode = w + return w + } + // add this widget as a child for the parent + w.parent.Append(w) + + if (a.WidgetType == toolkit.Box) { + if (a.B) { + w.horizontal = true + } else { + w.horizontal = false + } + } + + // w.showWidgetPlacement(logNow) + return w +} + +func setupCtrlDownWidget() { + var w *cuiWidget + w = new(cuiWidget) + + w.name = "ctrlDown" + + w.widgetType = toolkit.Flag + w.id = -1 + me.ctrlDown = w + // me.rootNode.Append(w) +} + +func (n *cuiWidget) Append(child *cuiWidget) { + n.children = append(n.children, child) + // child.parent = n +} + +// find widget by number +func findWidget(i int, w *cuiWidget) (*cuiWidget) { + if (w == nil) { + log(logVerbose, "findWidget() Trying to find i =", i, "currently checking against w.id = nil") + return nil + } + log(logVerbose, "findWidget() Trying to find i =", i, "currently checking against w.id =", w.id) + + if (w.id == i) { + log(logInfo, "findWidget() FOUND w.id ==", i, w.widgetType, w.name) + return w + } + + for _, child := range w.children { + newW := findWidget(i, child) + log(logVerbose, "findWidget() Trying to find i =", i, "currently checking against child.id =", child.id) + if (newW != nil) { + return newW + } + } + return nil +} + |
