2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-01-31 11:01:47 -06:00
|
|
|
"fmt"
|
2024-02-02 11:07:56 -06:00
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
"go.wit.com/log"
|
2024-01-18 04:10:08 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) doWidgetClick() {
|
|
|
|
switch w.WidgetType {
|
2024-02-05 07:31:04 -06:00
|
|
|
/*
|
2024-02-05 09:04:38 -06:00
|
|
|
case widget.Root:
|
|
|
|
// THIS IS THE BEGINING OF THE LAYOUT
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "doWidgetClick()", w.String())
|
2024-02-05 09:04:38 -06:00
|
|
|
wRoot := me.treeRoot.TK.(*guiWidget)
|
|
|
|
wRoot.redoWindows(0, 0)
|
|
|
|
case widget.Flag:
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "doWidgetClick() FLAG widget name =", w.String())
|
|
|
|
log.Log(GOCUI, "doWidgetClick() if this is the dropdown menu, handle it here?")
|
2024-02-05 07:31:04 -06:00
|
|
|
*/
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Window:
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "doWidgetClick() START on window", w.String())
|
2024-02-05 01:08:12 -06:00
|
|
|
// if the user clicked on the current window, do nothing
|
|
|
|
/* Ignore this for now and redraw the window anyway
|
|
|
|
if me.currentWindow == w {
|
2024-01-30 03:17:15 -06:00
|
|
|
if !w.active {
|
2024-01-29 23:23:04 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2024-02-05 01:08:12 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
// if there is a current window, hide it
|
2024-01-29 23:10:15 -06:00
|
|
|
if me.currentWindow != nil {
|
2024-02-05 01:08:12 -06:00
|
|
|
me.currentWindow.setColor(&colorWindow)
|
|
|
|
me.currentWindow.hideWidgets()
|
|
|
|
me.currentWindow.isCurrent = false
|
2024-01-29 23:10:15 -06:00
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
|
2024-02-05 01:08:12 -06:00
|
|
|
// now set this window as the current window
|
|
|
|
me.currentWindow = w
|
2024-02-05 02:22:58 -06:00
|
|
|
me.currentWindow.isCurrent = true
|
2024-02-05 01:08:12 -06:00
|
|
|
|
|
|
|
// draw the current window
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "doWidgetClick() set currentWindow to", w.String())
|
2024-01-28 11:07:51 -06:00
|
|
|
w.setColor(&colorActiveW)
|
2024-02-05 01:08:12 -06:00
|
|
|
w.DrawAt(3, 2)
|
|
|
|
w.placeWidgets(3, 2) // compute the sizes & places for each widget
|
2024-01-29 23:23:04 -06:00
|
|
|
w.active = false
|
|
|
|
w.showWidgets()
|
2024-02-05 01:08:12 -06:00
|
|
|
/*
|
|
|
|
hideFake()
|
|
|
|
showDebug = true
|
|
|
|
*/
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Group:
|
2024-01-28 13:14:43 -06:00
|
|
|
if w.active {
|
|
|
|
w.active = false
|
2024-01-28 20:36:59 -06:00
|
|
|
w.placeWidgets(w.startW, w.startH)
|
2024-01-28 14:03:06 -06:00
|
|
|
w.showWidgets()
|
2024-01-28 13:14:43 -06:00
|
|
|
} else {
|
|
|
|
w.active = true
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.hideWidgets()
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Checkbox:
|
2024-02-01 11:59:21 -06:00
|
|
|
if w.node.State.Checked {
|
|
|
|
log.Log(WARN, "checkbox is being set to false")
|
|
|
|
w.node.State.Checked = false
|
|
|
|
w.setCheckbox()
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-02-01 11:59:21 -06:00
|
|
|
log.Log(WARN, "checkbox is being set to true")
|
|
|
|
w.node.State.Checked = true
|
|
|
|
w.setCheckbox()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-02-01 11:59:21 -06:00
|
|
|
me.myTree.SendUserEvent(w.node)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Grid:
|
2024-01-28 11:07:51 -06:00
|
|
|
newR := w.realGocuiSize()
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
// w,h := n.logicalSize()
|
|
|
|
// w := newR.w1 - newR.w0
|
|
|
|
// h := newR.h1 - newR.h0
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
w.placeGrid(newR.w0, newR.h0)
|
2024-01-28 02:20:31 -06:00
|
|
|
w.showWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Box:
|
|
|
|
// w.showWidgetPlacement(logNow, "drawTree()")
|
2024-02-05 04:19:32 -06:00
|
|
|
if w.node.State.Direction == widget.Horizontal {
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "BOX IS HORIZONTAL", w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "BOX IS VERTICAL", w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-02-05 04:19:32 -06:00
|
|
|
w.placeWidgets(w.startW, w.startH)
|
2024-01-28 11:07:51 -06:00
|
|
|
w.toggleTree()
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Button:
|
2024-01-28 02:20:31 -06:00
|
|
|
// doUserEvent(n)
|
2024-02-02 11:07:56 -06:00
|
|
|
me.myTree.SendFromUser(w.node)
|
2024-02-01 20:12:26 -06:00
|
|
|
case widget.Combobox:
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "do the combobox here")
|
2024-02-02 11:07:56 -06:00
|
|
|
w.showDropdown()
|
2024-02-02 15:12:25 -06:00
|
|
|
me.dropdownW = w
|
2024-02-01 20:12:26 -06:00
|
|
|
case widget.Dropdown:
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "do the dropdown here")
|
2024-02-02 11:07:56 -06:00
|
|
|
w.showDropdown()
|
2024-02-02 15:12:25 -06:00
|
|
|
me.dropdownW = w
|
2024-01-18 00:08:37 -06:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-31 11:01:47 -06:00
|
|
|
// sends the mouse click to a widget underneath
|
2024-01-18 00:08:37 -06:00
|
|
|
func click(g *gocui.Gui, v *gocui.View) error {
|
2024-02-02 15:12:25 -06:00
|
|
|
mouseW, mouseH := me.baseGui.MousePosition()
|
2024-01-18 00:08:37 -06:00
|
|
|
|
2025-01-31 11:01:47 -06:00
|
|
|
w := mouseW
|
|
|
|
h := mouseH
|
2024-02-02 15:12:25 -06:00
|
|
|
|
2025-01-31 11:01:47 -06:00
|
|
|
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
|
|
|
|
}
|
2025-01-31 11:01:47 -06:00
|
|
|
tk.doWidgetClick()
|
2024-02-02 15:12:25 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2025-01-31 11:01:47 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
*/
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
}
|