summaryrefslogtreecommitdiff
path: root/find.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-31 10:28:08 -0600
committerJeff Carr <[email protected]>2025-01-31 13:47:45 -0600
commitc348940ca1367e9c64560812b12fbde27f7ad17e (patch)
tree90b074519e25d52d1d9689e3549d1b50363d2db8 /find.go
parent8a4afa760d1817e3f796fd2c8e6c3e5c01e59f5a (diff)
comments and code rearrangement
Diffstat (limited to 'find.go')
-rw-r--r--find.go32
1 files changed, 27 insertions, 5 deletions
diff --git a/find.go b/find.go
index 508967e..a2978a6 100644
--- a/find.go
+++ b/find.go
@@ -5,8 +5,31 @@ import (
"go.wit.com/widget"
)
-// returns the widget under the location on the screen
-func findByXY(widget *guiWidget, w int, h int) []*guiWidget {
+/*
+ gocui defines the offset like this:
+
+ width -> increases to the right
+ ---------------------------------- hieght
+ | H = 1 | increases
+ | | |
+ | W = 1 W = 18 | |
+ | | v
+ | H = 5 | downwards
+ -------------------------------------
+*/
+
+// change over to this name
+// returns all the widgets under (X,H) that are visible
+func findByXY(w int, h int) []*guiWidget {
+ rootW := me.treeRoot.TK.(*guiWidget)
+
+ // this searches the binary tree recursively (function is right below)
+ return findByXYreal(rootW, w, h)
+}
+
+// this checks a widget to see if it is under (W,H), then checks the widget's children
+// anything that matches is passed back as an array of widgets
+func findByXYreal(widget *guiWidget, w int, h int) []*guiWidget {
var widgets []*guiWidget
if !widget.Visible() {
@@ -24,7 +47,7 @@ func findByXY(widget *guiWidget, w int, h int) []*guiWidget {
// search through the children widgets in the binary tree
for _, child := range widget.children {
- widgets = append(widgets, findByXY(child, w, h)...)
+ widgets = append(widgets, findByXYreal(child, w, h)...)
}
return widgets
@@ -33,8 +56,7 @@ func findByXY(widget *guiWidget, w int, h int) []*guiWidget {
func findUnderMouse() *guiWidget {
w, h := me.baseGui.MousePosition()
- rootW := me.treeRoot.TK.(*guiWidget)
- widgets := findByXY(rootW, w, h)
+ widgets := findByXY(w, h)
// search through all the widgets that were below the mouse click
var found *guiWidget