2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
"go.wit.com/log"
|
2024-01-28 02:20:31 -06:00
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 04:10:08 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// set isCurrent = false everywhere
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) unsetCurrent() {
|
2024-01-18 00:08:37 -06:00
|
|
|
w.isCurrent = false
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.node.WidgetType == widget.Tab {
|
2024-01-18 00:08:37 -06:00
|
|
|
// n.tk.color = &colorTab
|
|
|
|
// n.setColor()
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range w.children {
|
2024-01-28 11:07:51 -06:00
|
|
|
child.unsetCurrent()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// when adding a new widget, this will update the display
|
|
|
|
// of the current widgets if that widget is supposed
|
|
|
|
// to be in current display
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) updateCurrent() {
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "updateCurrent()", w.String())
|
2024-01-28 11:07:51 -06:00
|
|
|
if w.WidgetType == widget.Tab {
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.IsCurrent() {
|
2024-01-18 00:08:37 -06:00
|
|
|
// n.tk.color = &colorActiveT
|
2024-01-28 11:07:51 -06:00
|
|
|
w.setColor(&colorActiveT)
|
2024-01-28 02:20:31 -06:00
|
|
|
w.hideView()
|
|
|
|
w.showView()
|
2024-01-28 11:07:51 -06:00
|
|
|
w.setCurrentTab()
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
|
|
|
// n.tk.color = &colorTab
|
|
|
|
// n.setColor()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
if w.WidgetType == widget.Window {
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.IsCurrent() {
|
2024-01-18 00:08:37 -06:00
|
|
|
// setCurrentWindow(n)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
if w.WidgetType == widget.Root {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
w.parent.updateCurrent()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// shows the widgets in a window
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) setCurrentWindow() {
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.IsCurrent() {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
if w.WidgetType != widget.Window {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
var rootTK *guiWidget
|
|
|
|
rootTK = me.treeRoot.TK.(*guiWidget)
|
2024-01-28 11:07:51 -06:00
|
|
|
rootTK.unsetCurrent()
|
2024-01-18 00:08:37 -06:00
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.hasTabs {
|
2024-01-18 00:08:37 -06:00
|
|
|
// set isCurrent = true on the first tab
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range w.children {
|
|
|
|
child.isCurrent = true
|
2024-01-18 00:08:37 -06:00
|
|
|
break
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
w.isCurrent = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// shows the widgets in a tab
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) setCurrentTab() {
|
|
|
|
var p, rootTK *guiWidget
|
|
|
|
if w.WidgetType != widget.Tab {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
rootTK = me.treeRoot.TK.(*guiWidget)
|
2024-01-28 11:07:51 -06:00
|
|
|
rootTK.unsetCurrent()
|
2024-01-18 00:08:37 -06:00
|
|
|
w.isCurrent = true
|
2024-01-28 11:07:51 -06:00
|
|
|
p = w.parent
|
2024-01-18 00:08:37 -06:00
|
|
|
p.isCurrent = true
|
2024-01-28 11:07:51 -06:00
|
|
|
log.Log(NOW, "setCurrent()", w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) doWidgetClick() {
|
|
|
|
switch w.WidgetType {
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Root:
|
|
|
|
// THIS IS THE BEGINING OF THE LAYOUT
|
2024-01-28 11:07:51 -06:00
|
|
|
log.Log(NOW, "doWidgetClick()", w.String())
|
2024-01-29 23:01:39 -06:00
|
|
|
wRoot := me.treeRoot.TK.(*guiWidget)
|
|
|
|
wRoot.redoWindows(0, 0)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Flag:
|
2024-01-28 11:07:51 -06:00
|
|
|
log.Log(NOW, "doWidgetClick() FLAG widget name =", w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?")
|
|
|
|
case widget.Window:
|
2024-01-28 11:44:36 -06:00
|
|
|
log.Log(NOW, "doWidgetClick() START on window", w.String())
|
2024-01-29 23:23:04 -06:00
|
|
|
if me.currentWindow == w.node {
|
2024-01-30 03:17:15 -06:00
|
|
|
if !w.active {
|
2024-01-29 23:23:04 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2024-01-29 23:10:15 -06:00
|
|
|
if me.currentWindow != nil {
|
|
|
|
var curw *guiWidget
|
|
|
|
curw = me.currentWindow.TK.(*guiWidget)
|
|
|
|
curw.unsetCurrent()
|
|
|
|
curw.setColor(&colorWindow)
|
|
|
|
curw.hideWidgets()
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
me.currentWindow = w.node
|
2024-01-28 02:20:31 -06:00
|
|
|
|
2024-01-28 11:44:36 -06:00
|
|
|
log.Log(NOW, "doWidgetClick() set currentWindow to", w.String())
|
2024-01-28 11:07:51 -06:00
|
|
|
w.setColor(&colorActiveW)
|
2024-01-29 23:23:04 -06:00
|
|
|
|
|
|
|
w.active = false
|
2024-02-01 10:06:09 -06:00
|
|
|
// w.dumpTree("before")
|
2024-01-29 23:23:04 -06:00
|
|
|
w.placeWidgets(3, 2)
|
|
|
|
w.showWidgets()
|
|
|
|
|
2024-01-29 23:39:33 -06:00
|
|
|
hideFake()
|
2024-01-29 23:23:04 -06:00
|
|
|
showDebug = true
|
|
|
|
|
2024-02-01 10:06:09 -06:00
|
|
|
// w.dumpTree("after")
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Group:
|
|
|
|
// n.placeWidgets(p.tk.startH, newH)
|
2024-02-01 10:06:09 -06:00
|
|
|
// w.dumpTree("click start")
|
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 20:15:59 -06:00
|
|
|
for _, child := range w.children {
|
|
|
|
log.Log(INFO, "START W,H", startW, startH)
|
|
|
|
child.placeWidgets(startW, startH)
|
|
|
|
child.showWidgets()
|
|
|
|
}
|
2024-01-28 14:03:06 -06:00
|
|
|
*/
|
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-01-28 02:20:31 -06:00
|
|
|
if w.direction == widget.Horizontal {
|
2024-01-28 11:07:51 -06:00
|
|
|
log.Log(NOW, "BOX IS HORIZONTAL", w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-01-28 11:07:51 -06:00
|
|
|
log.Log(NOW, "BOX IS VERTICAL", w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
w.placeWidgets(me.RawW, me.RawH)
|
|
|
|
w.toggleTree()
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Button:
|
2024-01-28 02:20:31 -06:00
|
|
|
// doUserEvent(n)
|
2024-01-28 11:07:51 -06:00
|
|
|
me.myTree.SendUserEvent(w.node)
|
2024-02-01 20:12:26 -06:00
|
|
|
case widget.Combobox:
|
|
|
|
log.Log(NOW, "do the combobox here")
|
2024-02-01 19:14:37 -06:00
|
|
|
var ddItems string
|
|
|
|
for i, s := range w.vals {
|
|
|
|
log.Log(NOW, "ddItem:", w.String(), i, s)
|
|
|
|
ddItems += s + "\n"
|
|
|
|
}
|
2024-01-18 00:08:37 -06:00
|
|
|
if me.ddview == nil {
|
2024-02-01 20:12:26 -06:00
|
|
|
me.ddview = makeDropdownView(ddItems)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-02-01 20:12:26 -06:00
|
|
|
showDropdownItems(ddItems)
|
|
|
|
me.ddNode = w.node
|
|
|
|
case widget.Dropdown:
|
|
|
|
log.Log(NOW, "do the dropdown here")
|
|
|
|
var ddItems string
|
|
|
|
for i, s := range w.vals {
|
|
|
|
log.Log(NOW, "ddItem:", w.String(), i, s)
|
|
|
|
ddItems += s + "\n"
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-02-01 21:47:31 -06:00
|
|
|
/*
|
2024-02-01 20:12:26 -06:00
|
|
|
if me.ddview == nil {
|
|
|
|
me.ddview = makeDropdownView(ddItems)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-02-01 21:47:31 -06:00
|
|
|
*/
|
2024-02-01 20:12:26 -06:00
|
|
|
showDropdownItems(ddItems)
|
|
|
|
me.ddNode = w.node
|
|
|
|
/*
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = me.ddview.TK.(*guiWidget)
|
|
|
|
log.Log(NOW, "doWidgetClick() visible =", tk.Visible())
|
|
|
|
if tk.Visible() {
|
|
|
|
tk.SetVisible(false)
|
|
|
|
me.baseGui.DeleteView("ddview")
|
|
|
|
tk.v = nil
|
|
|
|
} else {
|
|
|
|
me.ddNode = w.node
|
|
|
|
log.Log(NOW, "new dns list should be set to:", ddItems)
|
|
|
|
tk.labelN = ddItems
|
|
|
|
tk.SetText(ddItems)
|
|
|
|
tk.SetVisible(true)
|
|
|
|
fmt.Fprint(tk.v, ddItems)
|
|
|
|
}
|
|
|
|
for i, s := range tk.vals {
|
|
|
|
log.Log(NOW, "AddText()", tk.String(), i, s)
|
|
|
|
}
|
|
|
|
*/
|
2024-01-18 00:08:37 -06:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var toggle bool = true
|
|
|
|
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) toggleTree() {
|
2024-01-18 00:08:37 -06:00
|
|
|
if toggle {
|
2024-01-28 11:07:51 -06:00
|
|
|
w.drawTree(toggle)
|
2024-01-18 00:08:37 -06:00
|
|
|
toggle = false
|
|
|
|
} else {
|
2024-01-28 02:20:31 -06:00
|
|
|
w.hideWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
toggle = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// display the widgets in the binary tree
|
2024-01-28 11:07:51 -06:00
|
|
|
func (w *guiWidget) drawTree(draw bool) {
|
2024-01-18 00:08:37 -06:00
|
|
|
if w == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 13:14:43 -06:00
|
|
|
w.showWidgetPlacement("drawTree()")
|
2024-01-18 00:08:37 -06:00
|
|
|
if draw {
|
|
|
|
// w.textResize()
|
2024-01-28 02:20:31 -06:00
|
|
|
w.showView()
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-01-28 02:20:31 -06:00
|
|
|
w.deleteView()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range w.children {
|
2024-01-28 11:07:51 -06:00
|
|
|
child.drawTree(draw)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func click(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
// var l string
|
|
|
|
// var err error
|
|
|
|
|
|
|
|
log.Log(INFO, "click() START", v.Name())
|
|
|
|
// n := me.rootNode.findWidgetName(v.Name())
|
|
|
|
n := findUnderMouse()
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
2024-01-28 11:07:51 -06:00
|
|
|
if w != nil {
|
|
|
|
log.Log(NOW, "click() Found widget =", w.node.WidgetId, w.String(), ",", w.labelN)
|
|
|
|
if w.String() == "DropBox" {
|
2024-01-18 00:08:37 -06:00
|
|
|
log.Log(NOW, "click() this is the dropdown menu. set a flag here what did I click? where is the mouse?")
|
|
|
|
log.Log(NOW, "click() set a global dropdown clicked flag=true here")
|
|
|
|
me.ddClicked = true
|
|
|
|
}
|
2024-01-28 11:07:51 -06:00
|
|
|
w.doWidgetClick()
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
|
|
|
log.Log(NOW, "click() could not find node name =", v.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := g.SetCurrentView(v.Name()); err != nil {
|
|
|
|
log.Log(NOW, "click() END err =", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Log(NOW, "click() END")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func findUnderMouse() *tree.Node {
|
|
|
|
var found *tree.Node
|
|
|
|
var widgets []*tree.Node
|
|
|
|
var f func(n *tree.Node)
|
2024-01-18 00:08:37 -06:00
|
|
|
w, h := me.baseGui.MousePosition()
|
|
|
|
|
2024-02-01 20:12:26 -06:00
|
|
|
ddTK := me.ddview.TK.(*guiWidget)
|
|
|
|
// if the dropdown view is visable, close it
|
|
|
|
if ddTK.Visible() {
|
|
|
|
ddTK.dropdownClicked(w, h)
|
|
|
|
return me.ddview
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
// find buttons that are below where the mouse button click
|
2024-01-28 02:20:31 -06:00
|
|
|
f = func(n *tree.Node) {
|
|
|
|
var widget *guiWidget
|
|
|
|
widget = n.TK.(*guiWidget)
|
2024-02-01 20:12:26 -06:00
|
|
|
|
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) {
|
|
|
|
widgets = append(widgets, n)
|
|
|
|
found = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
for _, child := range widget.children {
|
|
|
|
f(child.node)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
f(me.treeRoot)
|
2024-01-18 00:08:37 -06:00
|
|
|
// widgets has everything that matches
|
|
|
|
// TODO: pop up menu with a list of them
|
|
|
|
for _, n := range widgets {
|
|
|
|
//log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name)
|
2024-01-28 11:44:36 -06:00
|
|
|
widget := n.TK.(*guiWidget)
|
2024-01-28 13:14:43 -06:00
|
|
|
widget.showWidgetPlacement("findUnderMouse() FOUND")
|
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-01-28 02:20:31 -06:00
|
|
|
var found *tree.Node
|
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-01-28 02:20:31 -06:00
|
|
|
found = me.treeRoot
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 03:33:08 -06:00
|
|
|
tk.labelN = found.String()
|
2024-01-28 11:07:51 -06:00
|
|
|
foundtk := found.TK.(*guiWidget)
|
|
|
|
newR := foundtk.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
|
|
|
|
if tk.Visible() {
|
|
|
|
// me.ctrlDown.hideView()
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-01-28 02:20:31 -06:00
|
|
|
// me.ctrlDown.showView()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 13:14:43 -06:00
|
|
|
// me.ctrlDown.showWidgetPlacement("ctrlDown:")
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
}
|