summaryrefslogtreecommitdiff
path: root/widgetCommon.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-25 07:27:37 -0500
committerJeff Carr <[email protected]>2025-03-25 13:17:00 -0500
commit1552eedc185e85b46498898e68867afaef308301 (patch)
tree8fc5cdfbc77cde184842197b2cde5cce8d85d34b /widgetCommon.go
parent4523eda0fa2372d97fb5db800b79b53c218ef627 (diff)
save the output window state
Diffstat (limited to 'widgetCommon.go')
-rw-r--r--widgetCommon.go126
1 files changed, 126 insertions, 0 deletions
diff --git a/widgetCommon.go b/widgetCommon.go
new file mode 100644
index 0000000..15d269c
--- /dev/null
+++ b/widgetCommon.go
@@ -0,0 +1,126 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "strconv"
+ "strings"
+
+ "go.wit.com/log"
+ "go.wit.com/toolkits/tree"
+ "go.wit.com/widget"
+)
+
+func initWidget(n *tree.Node) *guiWidget {
+ var w *guiWidget
+ w = new(guiWidget)
+
+ w.node = n
+ w.cuiName = strconv.Itoa(w.WidgetId()) + " TK"
+ // w.WidgetType() = n.WidgetType
+ w.labelN = n.State.Label
+ if w.labelN == "" {
+ // remove this debugging hack once things are stable and fixed
+ w.labelN = n.GetProgName()
+ }
+ w.frame = true
+ w.enable = n.State.Enable
+
+ if n.WidgetType == widget.Root {
+ log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
+ }
+
+ if n.WidgetType == widget.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
+ }
+
+ p := n.Parent
+ if p == nil {
+ log.Log(ERROR, "parent == nil", w.String(), n.WidgetId, w.WidgetType())
+ return w
+ }
+ if p.TK == nil {
+ if n.WidgetId == 0 {
+ // this is a normal init condition
+ } else {
+ log.Log(ERROR, "parent.TK == nil", w.String(), n.WidgetId, w.WidgetType())
+ }
+ return w
+ }
+
+ // set the parent and append to parent children
+ var ptk *guiWidget
+ ptk = p.TK.(*guiWidget)
+ w.parent = ptk
+ ptk.children = append(ptk.children, w)
+ return w
+}
+
+func setupCtrlDownWidget() {
+ a := new(widget.Action)
+ a.ProgName = "ctrlDown"
+ a.WidgetType = widget.Dialog
+ a.WidgetId = -1
+ a.ParentId = 0
+ // n := addNode(a)
+ n := me.myTree.AddNode(a)
+
+ me.ctrlDown = n
+}
+
+func (w *guiWidget) deleteView() {
+ // make sure the view isn't really there
+ // log.Log(GOCUI, "deleteView()", w.cuiName, w.WidgetType(), w.WidgetId())
+ me.baseGui.DeleteView(w.cuiName)
+ w.v = nil
+}
+
+func (tk *guiWidget) String() string {
+ // deprecate this?
+ curval := strings.TrimSpace(tk.labelN)
+ if curval != "" {
+ return curval
+ }
+ curval = strings.TrimSpace(tk.GetLabel())
+ if curval != "" {
+ return curval
+ }
+ curval = tk.GetText()
+ if curval != "" {
+ return curval
+ }
+ curval = tk.node.String()
+ if curval != "" {
+ return curval
+ }
+ curval = strings.TrimSpace(tk.node.ProgName())
+ if curval != "" {
+ return curval
+ }
+ return ""
+}
+
+func (tk *guiWidget) Visible() bool {
+ if tk == nil {
+ return false
+ }
+ if tk.v == nil {
+ return false
+ }
+ tk.v.Visible = true
+ return true
+}
+
+func (tk *guiWidget) Hide() {
+ tk.deleteView()
+}
+
+func (tk *guiWidget) SetVisible(b bool) {
+ if b {
+ tk.Show()
+ } else {
+ tk.Hide()
+ }
+}