2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-02 11:07:56 -06:00
|
|
|
"errors"
|
|
|
|
|
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-02-01 10:06:09 -06:00
|
|
|
// w.dumpTree("click end")
|
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:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "click() START gocui name:", v.Name())
|
2024-02-02 11:07:56 -06:00
|
|
|
w := findUnderMouse()
|
2024-02-02 15:12:25 -06:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-02-02 11:07:56 -06:00
|
|
|
if w == nil {
|
|
|
|
log.Error(errors.New("click() could not find widget for view =" + v.Name()))
|
|
|
|
} else {
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "click() Found widget =", w.node.WidgetId, w.String(), ",", w.labelN)
|
2024-01-28 11:07:51 -06:00
|
|
|
w.doWidgetClick()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-02-02 14:49:17 -06:00
|
|
|
rootTK := me.treeRoot.TK.(*guiWidget)
|
|
|
|
realTK := rootTK.findWidgetByView(v)
|
|
|
|
if realTK == nil {
|
|
|
|
log.Error(errors.New("toolkit click() out of reality with gocui. v.Name() not in binary tree " + v.Name()))
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "click() END FAILURE ON gocui v.Name =", v.Name())
|
2024-02-02 14:49:17 -06:00
|
|
|
// return nil // otherwise gocui exits
|
|
|
|
}
|
|
|
|
|
|
|
|
// double check the widget view really still exists
|
|
|
|
nameTK := rootTK.findWidgetByName(v.Name())
|
|
|
|
if nameTK == nil {
|
|
|
|
log.Error(errors.New("toolkit click() out of reality with gocui. v.Name() not in binary tree " + v.Name()))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if nameTK.v == nil {
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "click() maybe this widget has had it's view distroyed?", nameTK.cuiName, nameTK.WidgetType)
|
|
|
|
log.Log(GOCUI, "yep. it's gone now")
|
2024-02-02 14:49:17 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetCurrentView dies if it's sent an non-existent view
|
2024-01-18 00:08:37 -06:00
|
|
|
if _, err := g.SetCurrentView(v.Name()); err != nil {
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "click() END v.Name =", v.Name(), "err =", err)
|
2024-02-02 14:49:17 -06:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2024-02-09 03:45:03 -06:00
|
|
|
log.Log(GOCUI, "click() END gocui name:", v.Name())
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-02 11:07:56 -06:00
|
|
|
func findUnderMouse() *guiWidget {
|
|
|
|
var widgets []*guiWidget
|
|
|
|
var f func(w *guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
w, h := me.baseGui.MousePosition()
|
|
|
|
|
|
|
|
// find buttons that are below where the mouse button click
|
2024-02-02 11:07:56 -06:00
|
|
|
f = func(widget *guiWidget) {
|
2024-01-18 00:08:37 -06:00
|
|
|
// ignore widgets that are not visible
|
2024-01-28 10:38:47 -06:00
|
|
|
if widget.Visible() {
|
2024-01-18 00:08:37 -06:00
|
|
|
if (widget.gocuiSize.w0 <= w) && (w <= widget.gocuiSize.w1) &&
|
|
|
|
(widget.gocuiSize.h0 <= h) && (h <= widget.gocuiSize.h1) {
|
2024-02-02 11:07:56 -06:00
|
|
|
widgets = append(widgets, widget)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range widget.children {
|
2024-02-02 11:07:56 -06:00
|
|
|
f(child)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
2024-02-02 11:07:56 -06:00
|
|
|
rootW := me.treeRoot.TK.(*guiWidget)
|
|
|
|
f(rootW)
|
|
|
|
|
|
|
|
var found *guiWidget
|
2024-01-18 00:08:37 -06:00
|
|
|
// widgets has everything that matches
|
2024-02-02 11:07:56 -06:00
|
|
|
for _, w := range widgets {
|
|
|
|
// prioritize window buttons. This means if some code covers
|
|
|
|
// up the window widgets, then it will ignore everything else
|
|
|
|
// and allow the user (hopefully) to redraw or switch windows
|
|
|
|
// TODO: display the window widgets on top
|
|
|
|
if w.WidgetType == widget.Window {
|
|
|
|
return w
|
|
|
|
}
|
2024-02-09 03:45:03 -06:00
|
|
|
// w.showWidgetPlacement("findUnderMouse() FOUND")
|
2024-02-02 11:07:56 -06:00
|
|
|
found = w
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the widget under the mouse click
|
|
|
|
func ctrlDown(g *gocui.Gui, v *gocui.View) error {
|
2024-02-02 11:07:56 -06:00
|
|
|
var found *guiWidget
|
2024-01-18 00:08:37 -06:00
|
|
|
// var widgets []*node
|
|
|
|
// var f func (n *node)
|
|
|
|
found = findUnderMouse()
|
|
|
|
if me.ctrlDown == nil {
|
|
|
|
setupCtrlDownWidget()
|
2024-01-28 02:20:31 -06:00
|
|
|
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = me.ctrlDown.TK.(*guiWidget)
|
2024-01-28 03:33:08 -06:00
|
|
|
tk.labelN = found.String()
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.cuiName = "ctrlDown"
|
2024-01-18 00:08:37 -06:00
|
|
|
// me.ctrlDown.parent = me.rootNode
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
var tk *guiWidget
|
|
|
|
tk = me.ctrlDown.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
if found == nil {
|
2024-02-02 11:07:56 -06:00
|
|
|
found = me.treeRoot.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 03:33:08 -06:00
|
|
|
tk.labelN = found.String()
|
2024-02-02 11:07:56 -06:00
|
|
|
newR := found.realGocuiSize()
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.gocuiSize.w0 = newR.w0
|
|
|
|
tk.gocuiSize.h0 = newR.h0
|
|
|
|
tk.gocuiSize.w1 = newR.w1
|
|
|
|
tk.gocuiSize.h1 = newR.h1
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
}
|