gocui: simple grid working

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-03 17:49:37 -05:00
parent b0ae0810c4
commit 40ad372361
3 changed files with 27 additions and 24 deletions

View File

@ -63,7 +63,9 @@ func buttonWindow() {
g1.NewButton("hello2", func () { g1.NewButton("hello2", func () {
log.Println("world2") log.Println("world2")
}) })
more2 = g1.NewGroup("more2") more2 = g1.NewGrid("gridnuts", 3, 3)
more2.NewLabel("more2")
g.NewButton("this app is useful for plugin debuggin", func () { g.NewButton("this app is useful for plugin debuggin", func () {
}) })

View File

@ -23,9 +23,9 @@ func (w *cuiWidget) doWidgetClick() {
case toolkit.Tab: case toolkit.Tab:
w.redoBox(true) w.redoBox(true)
w.toggleTree() w.toggleTree()
case toolkit.Grid:
// w.toggleTree() w.redoBox(true)
// me.rootNode.redoColor(true) w.toggleTree()
case toolkit.Box: case toolkit.Box:
// w.showWidgetPlacement(logNow, "drawTree()") // w.showWidgetPlacement(logNow, "drawTree()")
if (w.horizontal) { if (w.horizontal) {
@ -125,8 +125,8 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
// find buttons that are below where the mouse button click // find buttons that are below where the mouse button click
f = func(widget *cuiWidget) { f = func(widget *cuiWidget) {
// if ((widget.logicalSize.w0 < w) && (w < widget.logicalSize.w1)) { // if ((widget.logicalSize.w0 < w) && (w < widget.logicalSize.w1)) {
if ((widget.realSize.w0 < w) && (w < widget.realSize.w1) && if ((widget.realSize.w0 <= w) && (w <= widget.realSize.w1) &&
(widget.realSize.h0 < h) && (h < widget.realSize.h1)) { (widget.realSize.h0 <= h) && (h <= widget.realSize.h1)) {
widgets = append(widgets, widget) widgets = append(widgets, widget)
found = widget found = widget
} }
@ -137,8 +137,8 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
} }
f(me.rootNode) f(me.rootNode)
var t string var t string
for i, widget := range widgets { for _, widget := range widgets {
log(logNow, "ctrlDown() FOUND widget", i, widget.name) log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name)
t += widget.cuiName + " " + widget.name + "\n" t += widget.cuiName + " " + widget.name + "\n"
// widget.showWidgetPlacement(logNow, "drawTree()") // widget.showWidgetPlacement(logNow, "drawTree()")
} }

View File

@ -73,30 +73,31 @@ func (w *cuiWidget) redoBox(draw bool) {
child.redoBox(draw) child.redoBox(draw)
} }
case toolkit.Grid: case toolkit.Grid:
log("redoBox GRID", p.nextW, p.nextH, p.name)
log("redoBox GRID", p.nextW, p.nextH, p.name)
log("redoBox GRID", w.nextW, w.nextH, w.name, w.text)
// hmm // hmm
w.logicalSize.w0 = p.nextW
w.logicalSize.h0 = p.nextH
w.logicalSize.w1 = p.nextW
w.logicalSize.h1 = p.nextH
w.nextW = p.nextW w.nextW = p.nextW
w.nextH = p.nextH w.nextH = p.nextH
var wCount, hCount int var wCount int = 0
var b bool = true var hCount int = 0
for _, child := range w.children { for _, child := range w.children {
child.redoBox(draw) // increment for the next child
if (b) {
wCount += 1
b = false
} else {
wCount = 0
w.nextH += 1
b = true
}
w.nextW = p.nextW + wCount * 20 w.nextW = p.nextW + wCount * 20
w.nextH = p.nextH + hCount * 4 w.nextH = p.nextH + hCount * 4
log(logInfo, "redoBox(GRID) (w,h count)", wCount, hCount, "(X,Y)", w.x, w.y, w.name) child.redoBox(draw)
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
}
} }
w.showWidgetPlacement(logNow, "grid:") w.showWidgetPlacement(logNow, "grid:")
case toolkit.Box: case toolkit.Box: