diff options
Diffstat (limited to 'find.go')
| -rw-r--r-- | find.go | 32 |
1 files changed, 27 insertions, 5 deletions
@@ -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 |
