2023-04-03 10:26:47 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/awesome-gocui/gocui"
|
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
)
|
|
|
|
|
2023-04-04 06:31:30 -05:00
|
|
|
func (w *cuiWidget) gridBounds() {
|
2023-04-04 10:38:21 -05:00
|
|
|
w.showWidgetPlacement(logNow, "gridBounds:")
|
|
|
|
p := w.parent
|
|
|
|
|
|
|
|
/*
|
2023-04-04 06:31:30 -05:00
|
|
|
for a := 0; a < w.x; a++ {
|
|
|
|
for b := 0; b < w.y; b++ {
|
|
|
|
log(logNow, "gridBounds() (w,h)", a, b,
|
|
|
|
"logical(W,H)", w.logicalW[a], w.logicalH[b],
|
|
|
|
"p.next(W,H)", p.nextW, p.nextH)
|
|
|
|
}
|
|
|
|
log("\n")
|
|
|
|
}
|
2023-04-04 10:38:21 -05:00
|
|
|
*/
|
|
|
|
var wCount int = 0
|
|
|
|
var hCount int = 0
|
|
|
|
for _, child := range w.children {
|
|
|
|
// increment for the next child
|
|
|
|
w.nextW = p.nextW + wCount * 20
|
|
|
|
w.nextH = p.nextH + hCount * 2
|
|
|
|
child.redoBox(true)
|
|
|
|
|
|
|
|
// set the child's realWidth, and grid offset
|
|
|
|
child.parentH = hCount
|
|
|
|
child.parentW = wCount
|
|
|
|
if (w.logicalW[wCount] < child.realWidth) {
|
|
|
|
w.logicalW[wCount] = child.realWidth
|
|
|
|
}
|
|
|
|
if (w.logicalH[hCount] < child.realHeight) {
|
|
|
|
w.logicalH[hCount] = child.realHeight
|
|
|
|
}
|
|
|
|
log(logNow, "redoBox(GRID) (w,h count)", wCount, hCount, "(X,Y)", w.x, w.y, w.name)
|
|
|
|
child.showWidgetPlacement(logNow, "grid:")
|
|
|
|
|
|
|
|
if ((wCount + 1) < w.y) {
|
|
|
|
wCount += 1
|
|
|
|
} else {
|
|
|
|
wCount = 0
|
|
|
|
hCount += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 06:31:30 -05:00
|
|
|
|
|
|
|
for _, child := range w.children {
|
2023-04-04 10:38:21 -05:00
|
|
|
child.showWidgetPlacement(logVerbose, "gridBounds:")
|
2023-04-04 06:31:30 -05:00
|
|
|
var totalW, totalH int
|
|
|
|
for i, val := range w.logicalW {
|
|
|
|
if (i < child.parentW) {
|
2023-04-04 10:38:21 -05:00
|
|
|
log(logVerbose, "gridBounds() (w, logicalW[])", i, val)
|
2023-04-04 06:31:30 -05:00
|
|
|
totalW += w.logicalW[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i, h := range w.logicalH {
|
|
|
|
if (i < child.parentH) {
|
|
|
|
totalH += h
|
|
|
|
}
|
|
|
|
}
|
2023-04-04 10:38:21 -05:00
|
|
|
|
|
|
|
// the new corner to move the child to
|
|
|
|
realW := w.nextW + totalW
|
|
|
|
realH := w.nextH + totalH
|
|
|
|
|
|
|
|
|
|
|
|
log(logInfo, "gridBounds()", child.id, "parent (W,H) =", child.parentW, child.parentH,
|
|
|
|
"total (W,H) =", totalW, totalH,
|
|
|
|
"real (W,H) =", realW, realH)
|
|
|
|
child.moveTo(realW, realH)
|
|
|
|
child.showWidgetPlacement(logInfo, "gridBounds:")
|
|
|
|
log(logInfo)
|
2023-04-04 06:31:30 -05:00
|
|
|
}
|
2023-04-04 10:38:21 -05:00
|
|
|
w.updateLogicalSizes()
|
|
|
|
w.showWidgetPlacement(logNow, "gridBounds:")
|
2023-04-04 06:31:30 -05:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:26:47 -05:00
|
|
|
func (w *cuiWidget) doWidgetClick() {
|
|
|
|
switch w.widgetType {
|
|
|
|
case toolkit.Root:
|
|
|
|
me.rootNode.redoTabs(true)
|
|
|
|
// me.rootNode.redoFake(true)
|
|
|
|
case toolkit.Flag:
|
|
|
|
me.rootNode.redoColor(true)
|
|
|
|
case toolkit.Window:
|
|
|
|
w.redoBox(true)
|
|
|
|
w.toggleTree()
|
|
|
|
case toolkit.Tab:
|
|
|
|
w.redoBox(true)
|
|
|
|
w.toggleTree()
|
2023-04-03 17:49:37 -05:00
|
|
|
case toolkit.Grid:
|
2023-04-04 06:31:30 -05:00
|
|
|
w.gridBounds()
|
2023-04-04 10:38:21 -05:00
|
|
|
for _, child := range w.children {
|
|
|
|
child.showWidgetPlacement(logNow, "gridBounds:")
|
|
|
|
if (child.v == nil) {
|
|
|
|
child.drawView()
|
|
|
|
} else {
|
|
|
|
child.deleteView()
|
|
|
|
}
|
|
|
|
}
|
2023-04-04 06:31:30 -05:00
|
|
|
// w.toggleTree()
|
2023-04-04 10:38:21 -05:00
|
|
|
// w.redoBox(true)
|
2023-04-03 10:26:47 -05:00
|
|
|
case toolkit.Box:
|
2023-04-03 16:08:58 -05:00
|
|
|
// w.showWidgetPlacement(logNow, "drawTree()")
|
2023-04-03 10:26:47 -05:00
|
|
|
if (w.horizontal) {
|
|
|
|
log("BOX IS HORIZONTAL", w.nextW, w.nextH, w.name)
|
|
|
|
} else {
|
|
|
|
log("BOX IS VERTICAL", w.nextW, w.nextH, w.name)
|
|
|
|
}
|
2023-04-03 16:08:58 -05:00
|
|
|
w.redoBox(true)
|
|
|
|
w.toggleTree()
|
2023-04-03 10:26:47 -05:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var toggle bool = true
|
|
|
|
func (w *cuiWidget) toggleTree() {
|
|
|
|
if (toggle) {
|
|
|
|
w.drawTree(toggle)
|
|
|
|
toggle = false
|
|
|
|
} else {
|
|
|
|
w.hideWidgets()
|
|
|
|
toggle = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// display the widgets in the binary tree
|
|
|
|
func (w *cuiWidget) drawTree(draw bool) {
|
|
|
|
if (w == nil) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.showWidgetPlacement(logNow, "drawTree()")
|
|
|
|
if (draw) {
|
2023-04-04 10:38:21 -05:00
|
|
|
// w.textResize()
|
2023-04-03 10:26:47 -05:00
|
|
|
w.drawView()
|
|
|
|
} else {
|
2023-04-03 11:52:54 -05:00
|
|
|
w.deleteView()
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range w.children {
|
|
|
|
child.drawTree(draw)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func click(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
var l string
|
|
|
|
var err error
|
|
|
|
|
|
|
|
log(logNow, "click() START", v.Name())
|
|
|
|
i, err := strconv.Atoi(v.Name())
|
|
|
|
if (err != nil) {
|
|
|
|
log(logNow, "click() Can't find widget. error =", err)
|
|
|
|
} else {
|
|
|
|
log(logNow, "click() ok v.Name() =", v.Name())
|
|
|
|
w := findWidget(i, me.rootNode)
|
|
|
|
if (w == nil) {
|
|
|
|
log(logError, "click() CANT FIND VIEW in binary tree. v.Name =", v.Name())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
log(logNow, "click() Found widget =", w.id, w.name, ",", w.text)
|
|
|
|
w.doWidgetClick()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := g.SetCurrentView(v.Name()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, cy := v.Cursor()
|
|
|
|
if l, err = v.Line(cy); err != nil {
|
|
|
|
l = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
maxX, maxY := g.Size()
|
|
|
|
if v, err := g.SetView("msg", maxX/2-10, maxY/2, maxX/2+10, maxY/2+2, 0); err == nil || errors.Is(err, gocui.ErrUnknownView) {
|
|
|
|
v.Clear()
|
|
|
|
v.SelBgColor = gocui.ColorCyan
|
|
|
|
v.SelFgColor = gocui.ColorBlack
|
|
|
|
fmt.Fprintln(v, l)
|
|
|
|
}
|
|
|
|
|
|
|
|
// this seems to delete the button(?)
|
|
|
|
// g.SetViewOnBottom(v.Name())
|
|
|
|
log(logNow, "click() END")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// display the widgets in the binary tree
|
|
|
|
|
|
|
|
func ctrlDown(g *gocui.Gui, v *gocui.View) error {
|
2023-04-03 16:08:58 -05:00
|
|
|
var found *cuiWidget
|
2023-04-03 10:26:47 -05:00
|
|
|
var widgets []*cuiWidget
|
|
|
|
var f func (widget *cuiWidget)
|
|
|
|
w, h := g.MousePosition()
|
|
|
|
|
2023-04-03 16:08:58 -05:00
|
|
|
// find buttons that are below where the mouse button click
|
2023-04-03 10:26:47 -05:00
|
|
|
f = func(widget *cuiWidget) {
|
2023-04-03 16:08:58 -05:00
|
|
|
// if ((widget.logicalSize.w0 < w) && (w < widget.logicalSize.w1)) {
|
2023-04-03 17:49:37 -05:00
|
|
|
if ((widget.realSize.w0 <= w) && (w <= widget.realSize.w1) &&
|
|
|
|
(widget.realSize.h0 <= h) && (h <= widget.realSize.h1)) {
|
2023-04-03 10:26:47 -05:00
|
|
|
widgets = append(widgets, widget)
|
2023-04-03 16:08:58 -05:00
|
|
|
found = widget
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range widget.children {
|
|
|
|
f(child)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f(me.rootNode)
|
|
|
|
var t string
|
2023-04-03 17:49:37 -05:00
|
|
|
for _, widget := range widgets {
|
|
|
|
log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name)
|
2023-04-03 10:26:47 -05:00
|
|
|
t += widget.cuiName + " " + widget.name + "\n"
|
|
|
|
// widget.showWidgetPlacement(logNow, "drawTree()")
|
|
|
|
}
|
|
|
|
t = strings.TrimSpace(t)
|
|
|
|
if (me.ctrlDown == nil) {
|
|
|
|
setupCtrlDownWidget()
|
2023-04-03 16:08:58 -05:00
|
|
|
me.ctrlDown.text = "ctrlDown" // t
|
|
|
|
me.ctrlDown.cuiName = "ctrlDown"
|
|
|
|
me.ctrlDown.parent = me.rootNode
|
|
|
|
}
|
|
|
|
if (found == nil) {
|
|
|
|
found = me.rootNode
|
|
|
|
}
|
2023-04-03 16:32:01 -05:00
|
|
|
found.updateLogicalSizes()
|
2023-04-03 16:08:58 -05:00
|
|
|
me.ctrlDown.realSize.w0 = found.logicalSize.w0
|
|
|
|
me.ctrlDown.realSize.w1 = found.logicalSize.w1
|
|
|
|
me.ctrlDown.realSize.h0 = found.logicalSize.h0
|
|
|
|
me.ctrlDown.realSize.h1 = found.logicalSize.h1
|
|
|
|
|
|
|
|
if (me.ctrlDown.v == nil) {
|
|
|
|
me.ctrlDown.text = found.text
|
|
|
|
me.ctrlDown.showWidgetPlacement(logNow, "drawTree()")
|
|
|
|
me.ctrlDown.drawView()
|
|
|
|
} else {
|
|
|
|
me.ctrlDown.deleteView()
|
2023-04-03 10:26:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
v, err := g.SetView("ctrlDown", maxX/2-10, maxY/2, maxX/2+10, maxY/2+2, 0)
|
|
|
|
if (err != nil) {
|
|
|
|
log(logError, "ctrlDown() g.SetView() error:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
v.Clear()
|
|
|
|
v.SelBgColor = gocui.ColorCyan
|
|
|
|
v.SelFgColor = gocui.ColorBlack
|
|
|
|
fmt.Fprintln(v, l)
|
|
|
|
*/
|
|
|
|
|
|
|
|
log(logNow, "ctrlDown()", w, h)
|
|
|
|
return nil
|
|
|
|
}
|