2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-28 02:20:31 -06:00
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
"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 02:20:31 -06:00
|
|
|
func unsetCurrent(w *guiWidget) {
|
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-18 00:08:37 -06:00
|
|
|
unsetCurrent(child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 02:20:31 -06:00
|
|
|
func updateCurrent(n *tree.Node) {
|
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
|
|
|
|
log.Log(NOW, "updateCurrent()", w.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
if n.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 02:20:31 -06:00
|
|
|
setColor(n, &colorActiveT)
|
|
|
|
w.hideView()
|
|
|
|
w.showView()
|
2024-01-18 00:08:37 -06:00
|
|
|
setCurrentTab(n)
|
|
|
|
} else {
|
|
|
|
// n.tk.color = &colorTab
|
|
|
|
// n.setColor()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if n.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
|
|
|
|
}
|
|
|
|
if n.WidgetType == widget.Root {
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
updateCurrent(n.Parent)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// shows the widgets in a window
|
2024-01-28 02:20:31 -06:00
|
|
|
func setCurrentWindow(n *tree.Node) {
|
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
if w.IsCurrent() {
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n.WidgetType != widget.Window {
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
var rootTK *guiWidget
|
|
|
|
rootTK = me.treeRoot.TK.(*guiWidget)
|
|
|
|
unsetCurrent(rootTK)
|
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 02:20:31 -06:00
|
|
|
func setCurrentTab(n *tree.Node) {
|
|
|
|
var w, p, rootTK *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
if n.WidgetType != widget.Tab {
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
rootTK = me.treeRoot.TK.(*guiWidget)
|
|
|
|
unsetCurrent(rootTK)
|
2024-01-18 00:08:37 -06:00
|
|
|
w.isCurrent = true
|
2024-01-28 02:20:31 -06:00
|
|
|
p = n.Parent.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
p.isCurrent = true
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "setCurrent()", n.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
func doWidgetClick(n *tree.Node) {
|
2024-01-18 00:08:37 -06:00
|
|
|
switch n.WidgetType {
|
|
|
|
case widget.Root:
|
|
|
|
// THIS IS THE BEGINING OF THE LAYOUT
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "doWidgetClick()", n.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
redoWindows(0, 0)
|
|
|
|
case widget.Flag:
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "doWidgetClick() FLAG widget name =", n.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:
|
|
|
|
if me.currentWindow == n {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if me.currentWindow != nil {
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = me.currentWindow.TK.(*guiWidget)
|
|
|
|
unsetCurrent(w)
|
|
|
|
setColor(me.currentWindow, &colorWindow)
|
|
|
|
w.hideWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
me.currentWindow = n
|
|
|
|
// setCurrentWindow(n) // probably delete this
|
2024-01-28 02:20:31 -06:00
|
|
|
setColor(n, &colorActiveW)
|
|
|
|
|
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
w.hideWidgets()
|
|
|
|
w.redoTabs(me.TabW, me.TabH)
|
|
|
|
for _, child := range w.children {
|
2024-01-18 00:08:37 -06:00
|
|
|
if child.currentTab == true {
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "FOUND CURRENT TAB", child.String())
|
|
|
|
setCurrentTab(child.node)
|
|
|
|
placeWidgets(child.node, me.RawW, me.RawH)
|
2024-01-18 00:08:37 -06:00
|
|
|
child.showWidgets()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FIXME: redo this
|
|
|
|
if ! n.hasTabs {
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
case widget.Tab:
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
if w.IsCurrent() {
|
2024-01-18 00:08:37 -06:00
|
|
|
return // do nothing if you reclick on the already selected tab
|
|
|
|
}
|
|
|
|
// find the window and disable the active tab
|
2024-01-28 02:20:31 -06:00
|
|
|
p := n.Parent
|
2024-01-18 00:08:37 -06:00
|
|
|
if p != nil {
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = p.TK.(*guiWidget)
|
|
|
|
w.hideWidgets()
|
|
|
|
w.redoTabs(me.TabW, me.TabH)
|
|
|
|
unsetCurrent(w)
|
|
|
|
for _, child := range w.children {
|
|
|
|
if child.node.WidgetType == widget.Tab {
|
|
|
|
setColor(child.node, &colorTab)
|
|
|
|
child.currentTab = false
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
w.currentTab = true
|
|
|
|
setColor(n, &colorActiveT)
|
2024-01-18 00:08:37 -06:00
|
|
|
setCurrentTab(n)
|
2024-01-28 02:20:31 -06:00
|
|
|
placeWidgets(n, me.RawW, me.RawH)
|
|
|
|
w.showWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Group:
|
|
|
|
// n.placeWidgets(p.tk.startH, newH)
|
2024-01-28 02:20:31 -06:00
|
|
|
toggleTree(n)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Checkbox:
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
if widget.GetBool(w.value) {
|
|
|
|
w.setCheckbox(false)
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-01-28 02:20:31 -06:00
|
|
|
w.setCheckbox(true)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
// n.doUserEvent()
|
|
|
|
me.myTree.SendUserEvent(me.treeRoot)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Grid:
|
2024-01-28 02:20:31 -06:00
|
|
|
newR := realGocuiSize(n)
|
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 02:20:31 -06:00
|
|
|
placeGrid(n, newR.w0, newR.h0)
|
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
|
|
|
w.showWidgets()
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Box:
|
2024-01-28 02:20:31 -06:00
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
// w.showWidgetPlacement(logNow, "drawTree()")
|
2024-01-28 02:20:31 -06:00
|
|
|
if w.direction == widget.Horizontal {
|
|
|
|
log.Log(NOW, "BOX IS HORIZONTAL", n.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "BOX IS VERTICAL", n.String())
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
placeWidgets(n, me.RawW, me.RawH)
|
|
|
|
toggleTree(n)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Button:
|
2024-01-28 02:20:31 -06:00
|
|
|
// doUserEvent(n)
|
|
|
|
me.myTree.SendUserEvent(n)
|
2024-01-18 00:08:37 -06:00
|
|
|
case widget.Dropdown:
|
|
|
|
log.Log(NOW, "do the dropdown here")
|
|
|
|
if me.ddview == nil {
|
|
|
|
me.ddview = addDropdown()
|
2024-01-28 02:20:31 -06:00
|
|
|
// n.TK = initWidget(n)
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = me.ddview.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
tk.gocuiSize.w0 = 20
|
|
|
|
tk.gocuiSize.w1 = 40
|
|
|
|
tk.gocuiSize.h0 = 10
|
|
|
|
tk.gocuiSize.h1 = 25
|
|
|
|
tk.v, _ = me.baseGui.SetView("ddview",
|
|
|
|
tk.gocuiSize.w0,
|
|
|
|
tk.gocuiSize.h0,
|
|
|
|
tk.gocuiSize.w1,
|
|
|
|
tk.gocuiSize.h1, 0)
|
|
|
|
if tk.v == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tk.v.Wrap = true
|
|
|
|
tk.v.Frame = true
|
|
|
|
tk.v.Clear()
|
|
|
|
fmt.Fprint(tk.v, "example.com\nwit.com")
|
2024-01-28 02:20:31 -06:00
|
|
|
SetVisible(me.ddview, true)
|
2024-01-18 00:08:37 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "doWidgetClick() visible =", Visible(me.ddview))
|
|
|
|
var tk *guiWidget
|
|
|
|
tk = me.ddview.TK.(*guiWidget)
|
|
|
|
if Visible(me.ddview) {
|
|
|
|
SetVisible(me.ddview, false)
|
2024-01-18 00:08:37 -06:00
|
|
|
me.baseGui.DeleteView("ddview")
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.v = nil
|
2024-01-18 00:08:37 -06:00
|
|
|
} else {
|
|
|
|
var dnsList string
|
2024-01-28 02:20:31 -06:00
|
|
|
for i, s := range tk.vals {
|
|
|
|
log.Log(NOW, "AddText()", n.String(), i, s)
|
2024-01-18 00:08:37 -06:00
|
|
|
dnsList += s + "\n"
|
|
|
|
}
|
|
|
|
me.ddNode = n
|
|
|
|
log.Log(NOW, "new dns list should be set to:", dnsList)
|
2024-01-28 02:20:31 -06:00
|
|
|
tk.label = dnsList
|
|
|
|
tk.SetText(dnsList)
|
|
|
|
SetVisible(me.ddview, true)
|
2024-01-18 00:08:37 -06:00
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
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 02:20:31 -06:00
|
|
|
func toggleTree(n *tree.Node) {
|
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
if toggle {
|
2024-01-28 02:20:31 -06:00
|
|
|
drawTree(n, 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 02:20:31 -06:00
|
|
|
func drawTree(n *tree.Node, draw bool) {
|
|
|
|
var w *guiWidget
|
|
|
|
w = n.TK.(*guiWidget)
|
2024-01-18 00:08:37 -06:00
|
|
|
if w == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-28 02:20:31 -06:00
|
|
|
showWidgetPlacement(n, true, "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 {
|
|
|
|
drawTree(child.node, 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-18 00:08:37 -06:00
|
|
|
if n != nil {
|
2024-01-28 02:20:31 -06:00
|
|
|
log.Log(NOW, "click() Found widget =", n.WidgetId, n.String(), ",", w.label)
|
|
|
|
if n.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 02:20:31 -06:00
|
|
|
doWidgetClick(n)
|
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()
|
|
|
|
|
|
|
|
// 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-01-18 00:08:37 -06:00
|
|
|
// ignore widgets that are not visible
|
2024-01-28 02:20:31 -06:00
|
|
|
if Visible(n) {
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if n == me.ddview {
|
|
|
|
log.Log(NOW, "findUnderMouse() found ddview")
|
2024-01-28 02:20:31 -06:00
|
|
|
if Visible(n) {
|
2024-01-18 00:08:37 -06:00
|
|
|
log.Log(NOW, "findUnderMouse() and ddview is visable. hide it here. TODO: find highlighted row")
|
|
|
|
found = n
|
|
|
|
// find the actual value here and set the dropdown widget
|
|
|
|
me.baseGui.DeleteView("ddview")
|
|
|
|
} else {
|
|
|
|
log.Log(NOW, "findUnderMouse() I was lying, actually it's not found")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 02:20:31 -06:00
|
|
|
showWidgetPlacement(n, true, "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)
|
|
|
|
tk.label = found.String()
|
|
|
|
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 02:20:31 -06:00
|
|
|
tk.label = found.String()
|
|
|
|
newR := realGocuiSize(found)
|
|
|
|
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 02:20:31 -06:00
|
|
|
// me.ctrlDown.showWidgetPlacement(true, "ctrlDown:")
|
2024-01-18 00:08:37 -06:00
|
|
|
return nil
|
|
|
|
}
|