gocui/eventMouseClick.go

141 lines
3.5 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/widget"
)
func (w *guiWidget) doWidgetClick() {
switch w.WidgetType {
/*
case widget.Root:
// THIS IS THE BEGINING OF THE LAYOUT
log.Log(GOCUI, "doWidgetClick()", w.String())
wRoot := me.treeRoot.TK.(*guiWidget)
wRoot.redoWindows(0, 0)
case widget.Flag:
log.Log(GOCUI, "doWidgetClick() FLAG widget name =", w.String())
log.Log(GOCUI, "doWidgetClick() if this is the dropdown menu, handle it here?")
*/
case widget.Window:
log.Log(GOCUI, "doWidgetClick() START on window", w.String())
// if the user clicked on the current window, do nothing
/* Ignore this for now and redraw the window anyway
if me.currentWindow == w {
if !w.active {
return
}
}
*/
// if there is a current window, hide it
if me.currentWindow != nil {
me.currentWindow.setColor(&colorWindow)
me.currentWindow.hideWidgets()
me.currentWindow.isCurrent = false
}
// now set this window as the current window
me.currentWindow = w
me.currentWindow.isCurrent = true
// draw the current window
log.Log(GOCUI, "doWidgetClick() set currentWindow to", w.String())
w.setColor(&colorActiveW)
w.DrawAt(3, 2)
w.placeWidgets(3, 2) // compute the sizes & places for each widget
w.active = false
w.showWidgets()
/*
hideFake()
showDebug = true
*/
case widget.Group:
if w.active {
w.active = false
w.placeWidgets(w.startW, w.startH)
w.showWidgets()
} else {
w.active = true
for _, child := range w.children {
child.hideWidgets()
}
}
case widget.Checkbox:
if w.node.State.Checked {
log.Log(WARN, "checkbox is being set to false")
w.node.State.Checked = false
w.setCheckbox()
} else {
log.Log(WARN, "checkbox is being set to true")
w.node.State.Checked = true
w.setCheckbox()
}
me.myTree.SendUserEvent(w.node)
case widget.Grid:
newR := w.realGocuiSize()
// w,h := n.logicalSize()
// w := newR.w1 - newR.w0
// h := newR.h1 - newR.h0
w.placeGrid(newR.w0, newR.h0)
w.showWidgets()
case widget.Box:
// w.showWidgetPlacement(logNow, "drawTree()")
if w.node.State.Direction == widget.Horizontal {
log.Log(GOCUI, "BOX IS HORIZONTAL", w.String())
} else {
log.Log(GOCUI, "BOX IS VERTICAL", w.String())
}
w.placeWidgets(w.startW, w.startH)
w.toggleTree()
case widget.Button:
// doUserEvent(n)
me.myTree.SendFromUser(w.node)
case widget.Combobox:
log.Log(GOCUI, "do the combobox here")
w.showDropdown()
me.dropdownW = w
case widget.Dropdown:
log.Log(GOCUI, "do the dropdown here")
w.showDropdown()
me.dropdownW = w
default:
}
}
// sends the mouse click to a widget underneath
func click(g *gocui.Gui, v *gocui.View) error {
mouseW, mouseH := me.baseGui.MousePosition()
w := mouseW
h := mouseH
for _, tk := range findByXY(w, h) {
log.Log(GOCUI, fmt.Sprintf("findByXY() click() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h))
2025-01-31 12:36:46 -06:00
if tk.WidgetType == widget.Stdout {
// don't send clicks to the stdout debugging window
continue
}
tk.doWidgetClick()
return nil
}
log.Log(GOCUI, "click() nothing was at:", v.Name(), mouseW, mouseH)
return nil
/*
// not sure what SetCurrentView() does right now. it was here before
// SetCurrentView dies if it's sent an non-existent view
if _, err := g.SetCurrentView(v.Name()); err != nil {
log.Log(GOCUI, "click() END v.Name =", v.Name(), "err =", err)
// return err // return causes gocui.MainLoop() to exit. Do we ever want that to happen here?
return nil
}
*/
return nil
}