summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-07 00:08:44 -0600
committerJeff Carr <[email protected]>2025-02-07 00:08:44 -0600
commite96cb4375c9f4ffc45389a9df8c59116710532a4 (patch)
tree954880939a74b27681ce47dc8647241f4fb1907c
parentc2f8cac4a9f9737eee5983ca7ce81fde8c102715 (diff)
code cleanups
-rw-r--r--dropdown.go83
-rw-r--r--eventBindings.go3
-rw-r--r--treeDraw.go37
3 files changed, 32 insertions, 91 deletions
diff --git a/dropdown.go b/dropdown.go
index f14e54b..4828736 100644
--- a/dropdown.go
+++ b/dropdown.go
@@ -12,50 +12,18 @@ import (
"go.wit.com/widget"
)
-// dropdowns don't exist so this is an attempt to pretend they exist
-// by having a fake window view in gocui that appears with the dropdown
-// items. by detecting where the user clicks, we should be
-// able to set the text of the button to that value (and
-// rezise it.
-
-// the thing is this is so damned complicated because it
-// is very hard to debug this. thanks to the floating on
-// screen debugging output I might be able to figure it
-// it out now. maybe. notsure.
+// simulates a dropdown menu in gocui
/*
-func makeDropdownView(ddItems string) *guiWidget {
- newNode := addDropdown()
- tk := newNode.TK.(*guiWidget)
- tk.labelN = ddItems
- tk.SetText(ddItems)
- tk.gocuiSize.w0 = 100
- tk.gocuiSize.w1 = 120
- tk.gocuiSize.h0 = 15
- tk.gocuiSize.h1 = 18
- tk.v, _ = me.baseGui.SetView("ddview",
- tk.gocuiSize.w0,
- tk.gocuiSize.h0,
- tk.gocuiSize.w1,
- tk.gocuiSize.h1, 0)
- if tk.v == nil {
- return tk
- }
- tk.v.Wrap = true
- tk.v.Frame = true
- tk.v.Clear()
- fmt.Fprint(tk.v, ddItems)
- tk.Show()
+func addInternalTK(wId int) *guiWidget {
+ n := addDropdownNew(wId)
+ tk := n.TK.(*guiWidget)
+ tk.internal = true
return tk
}
*/
-func addDropdownTK(wId int) *guiWidget {
- n := addDropdownNew(wId)
- return n.TK.(*guiWidget)
-}
-
-func addDropdownNew(wId int) *tree.Node {
+func addInternalTK(wId int) *guiWidget {
n := new(tree.Node)
n.WidgetType = widget.Flag
n.WidgetId = wId
@@ -64,14 +32,11 @@ func addDropdownNew(wId int) *tree.Node {
// store the internal toolkit information
tk := new(guiWidget)
tk.frame = true
- tk.labelN = "DropBox text"
tk.node = n
if tk.node.Parent == nil {
tk.node.Parent = me.treeRoot
}
- // copy the data from the action message
- tk.node.State.Label = "DropBox"
// set the name used by gocui to the id
tk.cuiName = fmt.Sprintf("%d DR", wId)
@@ -81,39 +46,44 @@ func addDropdownNew(wId int) *tree.Node {
// add this new widget on the binary tree
tk.parent = me.treeRoot.TK.(*guiWidget)
if tk.parent == nil {
- panic("addDropdown() didn't get treeRoot guiWidget")
+ panic("addInternalNode() didn't get treeRoot guiWidget")
} else {
tk.parent.children = append(tk.parent.children, tk)
}
n.TK = tk
- return n
+ tk.internal = true
+ return tk
}
func (tk *guiWidget) showDropdown() {
+ if me.dropdown.tk == nil {
+ // should only happen once
+ me.dropdown.tk = addInternalTK(me.dropdown.wId)
+ me.dropdown.tk.dumpWidget("init() dropdown")
+ }
+ if me.dropdown.tk == nil {
+ log.Log(GOCUI, "showDropdown() Is Broken!")
+ return
+ }
+
// todo: fix this after switching to protobuf
me.dropdown.items = []string{} // zero out whatever was there before
for i, s := range tk.node.Strings() {
log.Log(GOCUI, "showDropdown()", tk.String(), i, s)
me.dropdown.items = append(me.dropdown.items, s)
}
-
log.Log(GOCUI, "new dropdown items should be set to:", me.dropdown.items)
- if me.dropdown.tk == nil {
- me.dropdown.tk = addDropdownTK(me.dropdown.wId)
- }
- if me.dropdown.tk == nil {
- log.Log(GOCUI, "showDropdown() IS BROKEN")
- return
- }
startW, startH := tk.Position()
log.Log(GOCUI, "showDropdown() SHOWING AT W,H=", startW, startH)
+ me.dropdown.tk.Hide()
me.dropdown.tk.MoveToOffset(startW+3, startH+2)
me.dropdown.tk.labelN = strings.Join(me.dropdown.items, "\n")
me.dropdown.tk.Show()
me.dropdown.active = true
me.dropdown.callerTK = tk
+ me.dropdown.tk.dumpWidget("showDropdown()")
}
// if there is a drop down view active, treat it like a dialog box and close it
@@ -163,20 +133,21 @@ func dropdownUnclicked(w, h int) {
}
func (tk *guiWidget) showTextbox() {
- // todo: fix this after switching to protobuf
-
if me.textbox.tk == nil {
- me.textbox.tk = addDropdownTK(me.textbox.wId)
+ // should only happen once
+ me.textbox.tk = addInternalTK(me.textbox.wId)
+ me.dropdown.tk.dumpWidget("init() textbox")
}
if me.textbox.tk == nil {
- log.Log(GOCUI, "showDropdown() IS BROKEN")
+ log.Log(GOCUI, "showTextbox() Is Broken")
return
}
startW, startH := tk.Position()
- log.Log(GOCUI, "showDropdown() SHOWING AT W,H=", startW, startH)
+ // log.Log(GOCUI, "showTextbox() SHOWING AT W,H=", startW, startH)
me.textbox.tk.MoveToOffset(startW+3, startH+2)
me.textbox.tk.labelN = "holy cow"
me.textbox.tk.Show()
me.textbox.active = true
me.textbox.callerTK = tk
+ me.textbox.tk.dumpWidget("showTextbox()")
}
diff --git a/eventBindings.go b/eventBindings.go
index 98e0b1a..16ef0cf 100644
--- a/eventBindings.go
+++ b/eventBindings.go
@@ -10,7 +10,6 @@ import (
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
- "go.wit.com/toolkits/tree"
)
// register how the 'gocui' will work as a GO toolkit plugin
@@ -92,9 +91,11 @@ func (tk *guiWidget) makeTK(ddItems []string) {
tk.Show()
}
+/*
func addDropdown() *tree.Node {
return addDropdownNew(-222)
}
+*/
// use this to test code ideas // put whatever you want here and hit '2' to activate it
func theNotsure(g *gocui.Gui, v *gocui.View) error {
diff --git a/treeDraw.go b/treeDraw.go
index ec63df5..34486e6 100644
--- a/treeDraw.go
+++ b/treeDraw.go
@@ -133,47 +133,16 @@ func (w *guiWidget) drawTree(draw bool) {
}
func (w *guiWidget) Show() {
- // don't display fake widgets
if w.isFake {
+ // don't display fake widgets
return
}
- // deprecate this
- // if this isn't in the binary tree
- // it's some internal widget so always display those
- /*
- if w.node == nil {
- w.drawView()
- return
- }
- */
-
if w.Hidden() {
+ // recursively checks if the parent is hidden
+ // never show hidden widgets
return
}
- // deprecate this
- // always show window titles
- if w.node.WidgetType == widget.Window {
- w.drawView()
- return
- }
-
- /*
- // if the widget is not in the current displayed windo
- if !w.IsCurrent() {
- // log.Log(GOCUI, "Show() w.IsCurrent == false. NOT drawing", w.cuiName, w.String())
- return
- }
- */
-
- // this comes from the application developer
- // finally, check if the widget State is hidden or not
- if w.Hidden() {
- // log.Log(GOCUI, "Show() w.node.Hidden() = false. not drawing", w.cuiName, w.String())
- // don't display hidden widgets
- return
- }
- // log.Log(GOCUI, "Show() doing w.drawView()", w.cuiName, w.String())
w.drawView()
}