summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-31 09:49:27 -0600
committerJeff Carr <[email protected]>2025-01-31 13:47:45 -0600
commit1d32c5da2b184314758726ecdfbcd6dbb548c867 (patch)
tree6b1ca2b83e52a2d83a51e83df2ba4451e78662ec
parent9f38585892d08690dde1b67b9a01006af308a949 (diff)
got the strings for a dropdown widget (finally. only took me 4 years)
-rw-r--r--dropdown.go21
-rw-r--r--eventMouseClick.go81
-rw-r--r--find.go96
-rw-r--r--help.go2
4 files changed, 116 insertions, 84 deletions
diff --git a/dropdown.go b/dropdown.go
index 3674e1e..b054d8d 100644
--- a/dropdown.go
+++ b/dropdown.go
@@ -156,12 +156,29 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string {
}
func dropdownUnclicked(mouseX, mouseH int) {
- log.Log(GOCUI, "dropdownUnclicked() mouseup: got inside me.dropdown handler? wxh =", mouseX, mouseH)
+ var d *guiWidget
+
+ // log.Log(GOCUI, "dropdownUnclicked() mouseup: got inside me.dropdown handler? wxh =", mouseX, mouseH)
if me.dropdownV == nil {
- log.Log(GOCUI, "mouseUp() dropdownV = nil", mouseX, mouseH)
+ log.Log(GOCUI, "mouseUp() dropdownV = nil. you don't have a fake dropdown window to make visible", mouseX, mouseH)
return
}
tk := me.dropdownV
log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked at apparently (w=%d h=%d)", mouseX, mouseH))
log.Log(GOCUI, "dropdownUnclicked() find out what the string is here", mouseX, mouseH, tk.gocuiSize.h1)
+
+ rootW := me.treeRoot.TK.(*guiWidget)
+ // examine everything under X & Y on the screen)
+ for i, w := range findByXY(rootW, mouseX, mouseH) {
+ log.Log(GOCUI, "dropdownUnclicked()", i, w.WidgetType)
+ if w.WidgetType == widget.Dropdown {
+ d = w
+ break
+ }
+ }
+ if d == nil {
+ log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked() there was no dropdown widget at (w=%d h=%d)", mouseX, mouseH))
+ return
+ }
+ log.Log(GOCUI, "dropdownUnclicked()", d.node.Strings(), "end")
}
diff --git a/eventMouseClick.go b/eventMouseClick.go
index 919ed87..787f00f 100644
--- a/eventMouseClick.go
+++ b/eventMouseClick.go
@@ -160,84 +160,3 @@ func click(g *gocui.Gui, v *gocui.View) error {
log.Log(GOCUI, "click() END gocui name:", v.Name())
return nil
}
-
-func findUnderMouse() *guiWidget {
- var widgets []*guiWidget
- var f func(w *guiWidget)
- w, h := me.baseGui.MousePosition()
-
- // find buttons that are below where the mouse button click
- f = func(widget *guiWidget) {
- // ignore widgets that are not visible
- if widget.Visible() {
- if (widget.gocuiSize.w0 <= w) && (w <= widget.gocuiSize.w1) &&
- (widget.gocuiSize.h0 <= h) && (h <= widget.gocuiSize.h1) {
- widgets = append(widgets, widget)
- }
- }
-
- for _, child := range widget.children {
- f(child)
- }
- }
- rootW := me.treeRoot.TK.(*guiWidget)
- f(rootW)
-
- // search through all the widgets that were below the mouse click
- var found *guiWidget
- for _, w := range widgets {
- // prioritize window buttons. This means if some code covers
- // up the window widgets, then it will ignore everything else
- // and allow the user (hopefully) to redraw or switch windows
- // TODO: display the window widgets on top
- if w.WidgetType == widget.Window {
- return w
- }
- }
-
- // return anything else that is interactive
- for _, w := range widgets {
- if w.WidgetType == widget.Button {
- return w
- }
- if w.WidgetType == widget.Combobox {
- return w
- }
- if w.WidgetType == widget.Checkbox {
- return w
- }
- w.showWidgetPlacement("findUnderMouse() found something unknown")
- found = w
- }
- // maybe something else was found
- return found
-}
-
-// find the widget under the mouse click
-func ctrlDown(g *gocui.Gui, v *gocui.View) error {
- var found *guiWidget
- // var widgets []*node
- // var f func (n *node)
- found = findUnderMouse()
- if me.ctrlDown == nil {
- setupCtrlDownWidget()
-
- var tk *guiWidget
- tk = me.ctrlDown.TK.(*guiWidget)
- tk.labelN = found.String()
- tk.cuiName = "ctrlDown"
- // me.ctrlDown.parent = me.rootNode
- }
- var tk *guiWidget
- tk = me.ctrlDown.TK.(*guiWidget)
- if found == nil {
- found = me.treeRoot.TK.(*guiWidget)
- }
- tk.labelN = found.String()
- newR := found.realGocuiSize()
- tk.gocuiSize.w0 = newR.w0
- tk.gocuiSize.h0 = newR.h0
- tk.gocuiSize.w1 = newR.w1
- tk.gocuiSize.h1 = newR.h1
- return nil
-}
diff --git a/find.go b/find.go
new file mode 100644
index 0000000..508967e
--- /dev/null
+++ b/find.go
@@ -0,0 +1,96 @@
+package main
+
+import (
+ "github.com/awesome-gocui/gocui"
+ "go.wit.com/widget"
+)
+
+// returns the widget under the location on the screen
+func findByXY(widget *guiWidget, w int, h int) []*guiWidget {
+ var widgets []*guiWidget
+
+ if !widget.Visible() {
+ // ignore widgets that are not visible
+ } else {
+
+ // check the location to see if this is under (W,H)
+ // if it is, return this widget
+ if (widget.gocuiSize.w0 <= w) && (w <= widget.gocuiSize.w1) &&
+ (widget.gocuiSize.h0 <= h) && (h <= widget.gocuiSize.h1) {
+ widgets = append(widgets, widget)
+ // log.Log(GOCUI, "findByXY() found", widget.WidgetType, w, h)
+ }
+ }
+
+ // search through the children widgets in the binary tree
+ for _, child := range widget.children {
+ widgets = append(widgets, findByXY(child, w, h)...)
+ }
+
+ return widgets
+}
+
+func findUnderMouse() *guiWidget {
+ w, h := me.baseGui.MousePosition()
+
+ rootW := me.treeRoot.TK.(*guiWidget)
+ widgets := findByXY(rootW, w, h)
+
+ // search through all the widgets that were below the mouse click
+ var found *guiWidget
+ for _, w := range widgets {
+ // prioritize window buttons. This means if some code covers
+ // up the window widgets, then it will ignore everything else
+ // and allow the user (hopefully) to redraw or switch windows
+ // TODO: display the window widgets on top
+ if w.WidgetType == widget.Window {
+ return w
+ }
+ }
+
+ // return anything else that is interactive
+ for _, w := range widgets {
+ if w.WidgetType == widget.Button {
+ return w
+ }
+ if w.WidgetType == widget.Combobox {
+ return w
+ }
+ if w.WidgetType == widget.Checkbox {
+ return w
+ }
+ w.showWidgetPlacement("findUnderMouse() found something unknown")
+ found = w
+ }
+ // maybe something else was found
+ return found
+}
+
+// find the widget under the mouse click
+func ctrlDown(g *gocui.Gui, v *gocui.View) error {
+ var found *guiWidget
+ // var widgets []*node
+ // var f func (n *node)
+ found = findUnderMouse()
+ if me.ctrlDown == nil {
+ setupCtrlDownWidget()
+
+ var tk *guiWidget
+ tk = me.ctrlDown.TK.(*guiWidget)
+ tk.labelN = found.String()
+ tk.cuiName = "ctrlDown"
+ // me.ctrlDown.parent = me.rootNode
+ }
+ var tk *guiWidget
+ tk = me.ctrlDown.TK.(*guiWidget)
+ if found == nil {
+ found = me.treeRoot.TK.(*guiWidget)
+ }
+ tk.labelN = found.String()
+ newR := found.realGocuiSize()
+ tk.gocuiSize.w0 = newR.w0
+ tk.gocuiSize.h0 = newR.h0
+ tk.gocuiSize.w1 = newR.w1
+ tk.gocuiSize.h1 = newR.h1
+ return nil
+}
diff --git a/help.go b/help.go
index 832cd9a..185eb83 100644
--- a/help.go
+++ b/help.go
@@ -14,7 +14,7 @@ import (
var helpText []string = []string{"KEYBINDINGS",
"",
- "?: toggle helps",
+ "?: toggle zhelp",
"d: toggle debugging",
"r: redraw widgets",
"s/h: show/hide all widgets",