gocui/eventMouseClick.go

141 lines
3.7 KiB
Go

// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
import (
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/widget"
)
// this whole things was impossible to make but it got me where I am now
// the debugging is way way better now with it being visible in the Stdout window
// so now it's possible to redo all this and make it better
func (tk *guiWidget) doWidgetClick(w int, h int) {
switch tk.node.WidgetType {
case widget.Window:
// 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 = tk
me.currentWindow.isCurrent = true
tk.active = false
tk.redrawWindow(w, h)
return
case widget.Group:
if tk.active {
tk.active = false
tk.placeWidgets(tk.startW, tk.startH)
tk.showWidgets()
} else {
tk.active = true
for _, child := range tk.children {
child.hideWidgets()
}
}
case widget.Checkbox:
if tk.node.State.Checked {
log.Log(WARN, "checkbox is being set to false")
tk.node.State.Checked = false
tk.setCheckbox()
} else {
log.Log(WARN, "checkbox is being set to true")
tk.node.State.Checked = true
tk.setCheckbox()
}
me.myTree.SendUserEvent(tk.node)
case widget.Grid:
newR := tk.realGocuiSize()
// w,h := n.logicalSize()
// w := newR.w1 - newR.w0
// h := newR.h1 - newR.h0
tk.placeGrid(newR.w0, newR.h0)
tk.showWidgets()
case widget.Box:
if tk.node.State.Direction == widget.Horizontal {
log.Log(GOCUI, "BOX IS HORIZONTAL", tk.String())
} else {
log.Log(GOCUI, "BOX IS VERTICAL", tk.String())
}
tk.placeWidgets(tk.startW, tk.startH)
tk.toggleTree()
case widget.Button:
// doUserEvent(n)
me.myTree.SendFromUser(tk.node)
case widget.Combobox:
log.Log(GOCUI, "do the combobox here")
tk.showDropdown()
me.dropdownW = tk
case widget.Dropdown:
// log.Log(GOCUI, "do the dropdown here")
tk.showDropdown()
me.dropdownW = tk
case widget.Stdout:
log.Log(GOCUI, "stdout widget found!")
tk.dumpWidget("stdout click")
case widget.Flag:
// log.Log(GOCUI, "flag widget found!")
tk.dropdownClicked(w, h)
// got_ := dropdownClicked(w, h)
// log.Log(GOCUI, "flag click got", got)
default:
tk.dumpWidget("blank click()")
}
}
// 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
// Flag widgets (dropdown menus, etc) are the highest priority. ALWAYS SEND MOUSE CLICKS THERE FIRST
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Flag {
tk.doWidgetClick(w, h)
return nil
}
}
// Button widgets
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Button {
tk.doWidgetClick(w, h)
return nil
}
}
for _, tk := range findByXY(w, h) {
// will show you everything found on a mouse click. great for debugging!
// tk.dumpWidget("click()")
if tk.node.WidgetType == widget.Stdout {
// don't send clicks to the stdout debugging window
continue
}
tk.doWidgetClick(w, h)
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
}
*/
}