dropdown's work

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-02 15:12:25 -06:00
parent ee0f84fd8e
commit 29d6cadbb3
2 changed files with 19 additions and 33 deletions

View File

@ -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

View File

@ -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)
}