From 29d6cadbb391b3844a3bfcea910df03d06d5b443 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 2 Feb 2024 15:12:25 -0600 Subject: [PATCH] dropdown's work Signed-off-by: Jeff Carr --- click.go | 21 ++++++++++++--------- dropdown.go | 31 +++++++------------------------ 2 files changed, 19 insertions(+), 33 deletions(-) diff --git a/click.go b/click.go index 59d33b3..c1e91a3 100644 --- a/click.go +++ b/click.go @@ -183,9 +183,11 @@ func (w *guiWidget) doWidgetClick() { case widget.Combobox: log.Log(NOW, "do the combobox here") w.showDropdown() + me.dropdownW = w case widget.Dropdown: log.Log(NOW, "do the dropdown here") w.showDropdown() + me.dropdownW = w default: } } @@ -221,12 +223,19 @@ func (w *guiWidget) drawTree(draw bool) { } func click(g *gocui.Gui, v *gocui.View) error { - // var l string - // var err error + mouseW, mouseH := me.baseGui.MousePosition() log.Log(NOW, "click() START gocui name:", v.Name()) - // n := me.rootNode.findWidgetName(v.Name()) w := findUnderMouse() + + // if the dropdown view is visable, process it no matter what + if me.dropdownV.Visible() { + me.dropdownV.dropdownClicked(mouseW, mouseH) + } + if w == me.dropdownV { + return nil + } + if w == nil { log.Error(errors.New("click() could not find widget for view =" + v.Name())) } else { @@ -270,12 +279,6 @@ func findUnderMouse() *guiWidget { var f func(w *guiWidget) w, h := me.baseGui.MousePosition() - // if the dropdown view is visable, close it - if me.dropdownV.Visible() { - me.dropdownV.dropdownClicked(w, h) - return me.dropdownV - } - // find buttons that are below where the mouse button click f = func(widget *guiWidget) { // ignore widgets that are not visible diff --git a/dropdown.go b/dropdown.go index b9d6266..6abe67e 100644 --- a/dropdown.go +++ b/dropdown.go @@ -131,6 +131,13 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string { items := strings.Split(w.labelN, "\n") if len(items) >= itemNumber-1 { log.Log(NOW, "dropdownClicked() found", items[itemNumber-1]) + if items[itemNumber-1] != "" { + if me.dropdownW != nil { + log.Log(NOW, "dropdownClicked() send event for", me.dropdownW.cuiName, me.dropdownW.WidgetType) + me.dropdownW.SetText(items[itemNumber-1]) + me.myTree.SendUserEvent(me.dropdownW.node) + } + } return items[itemNumber-1] } return "" @@ -141,28 +148,4 @@ func dropdownUnclicked(mouseX, mouseH int) { log.Log(NOW, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", mouseX, mouseH) log.Log(NOW, "mouseUp() ddview is the thing that was clicked", mouseX, mouseH) log.Log(NOW, "mouseUp() find out what the string is here", mouseX, mouseH, tk.gocuiSize.h1) - - var newZone string = "" - if me.dropdownW == nil { - return - } - // try to compute the line item clicked here - /* - var ddtk *guiWidget - ddtk = me.ddview.TK.(*guiWidget) - value := mouseH - tk.gocuiSize.h0 - 1 - log.Log(NOW, "mouseUp() me.ddview.tk.gocuiSize.h1 =", tk.gocuiSize.h1) - log.Log(NOW, "mouseUp() me.ddNode.vals =", ddtk.vals) - valsLen := len(ddtk.vals) - log.Log(NOW, "mouseUp() value =", value, "valsLen =", valsLen) - log.Log(NOW, "mouseUp() me.ddNode.vals =", ddtk.vals) - if (value >= 0) && (value < valsLen) { - newZone = ddtk.vals[value] - log.Log(NOW, "mouseUp() value =", value, "newZone =", newZone) - } - */ - // send the event the user selected something from the dropdown - hideDDview() - me.dropdownW.SetText(newZone) - me.myTree.SendUserEvent(me.dropdownW.node) }