diff --git a/dropdown.go b/dropdown.go index 0279041..e8cc6d9 100644 --- a/dropdown.go +++ b/dropdown.go @@ -155,22 +155,22 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string { return "" } -var dtoggle bool +var dtoggle bool // temporarily tracking show & hide +var doffset int = 5 // how many spaces over the dropdown menu should be from the mouse -func dropdownUnclicked(mouseX, mouseH int) { +func dropdownUnclicked(mouseW, mouseH int) { var d *guiWidget - // log.Log(GOCUI, "dropdownUnclicked() mouseup: got inside me.dropdown handler? wxh =", mouseX, mouseH) + // log.Log(GOCUI, "dropdownUnclicked() mouseup: got inside me.dropdown handler? wxh =", mouseW, mouseH) if me.dropdownV == nil { - log.Log(GOCUI, "mouseUp() dropdownV = nil. you don't have a fake dropdown window to make visible", mouseX, mouseH) + log.Log(GOCUI, "mouseUp() dropdownV = nil. you don't have a fake dropdown window to make visible", mouseW, mouseH) return } - // 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) + // log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked at apparently (w=%d h=%d)", mouseW, mouseH)) + // log.Log(GOCUI, "dropdownUnclicked() find out what the string is here", mouseW, 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) { + for i, w := range findByXY(mouseW, mouseH) { log.Log(GOCUI, "dropdownUnclicked()", i, w.WidgetType) if w.WidgetType == widget.Dropdown { d = w @@ -178,7 +178,7 @@ func dropdownUnclicked(mouseX, mouseH int) { } } if d == nil { - log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked() there was no dropdown widget at (w=%d h=%d)", mouseX, mouseH)) + log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked() there was no dropdown widget at (w=%d h=%d)", mouseW, mouseH)) return } log.Log(GOCUI, "dropdownUnclicked()", d.node.Strings(), "end. now try to enable me.dropdownV") @@ -191,8 +191,9 @@ func dropdownUnclicked(mouseX, mouseH int) { tk.SetText("goodbye") } else { log.Log(GOCUI, "dropdownUnclicked() set visible=true") - tk.Show() + tk.MoveToOffset(mouseW+doffset, mouseH) tk.SetText(dtext) + tk.Show() dtoggle = true } } 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 diff --git a/place.go b/place.go index 278315f..ca0737f 100644 --- a/place.go +++ b/place.go @@ -8,6 +8,29 @@ import ( "go.wit.com/widget" ) +/* + gocui defines the offset like this: + + width -> increases to the right + ---------------------------------- hieght + | H = 1 | increases + | | | + | W = 1 W = 18 | | + | | v + | H = 5 | downwards + ------------------------------------- +*/ + +// moves the gocui view to the W and H offset on the screen +func (tk *guiWidget) MoveToOffset(W, H int) { + tk.gocuiSetWH(W, H) +} + +// returns where the corner of widget starts (upper left) +func (tk *guiWidget) Position() (int, int) { + return tk.gocuiSize.w0, tk.gocuiSize.h0 +} + func (w *guiWidget) placeBox(startW int, startH int) { if w.WidgetType != widget.Box { return @@ -215,29 +238,6 @@ func textSize(n *tree.Node) (int, int) { return width, height } -// moves the gocui view the W and H offset on the screen -/* - 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 -func (tk *guiWidget) MoveToOffset(W, H int) { - tk.gocuiSetWH(W, H) -} - -// returns where the corner of widget starts (upper left) -func (tk *guiWidget) Position() (int, int) { - return tk.gocuiSize.w0, tk.gocuiSize.h0 -} - func (tk *guiWidget) gocuiSetWH(sizeW, sizeH int) { w := len(widget.GetString(tk.value)) lines := strings.Split(widget.GetString(tk.value), "\n")