gocui: more size calculations

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-06 00:13:28 -05:00
parent 0d36740a86
commit 6b7d1fb30b
4 changed files with 52 additions and 24 deletions

View File

@ -18,17 +18,20 @@ func (w *cuiWidget) doWidgetClick() {
case toolkit.Flag:
me.rootNode.redoColor(true)
case toolkit.Window:
me.rootNode.hideWidgets()
w.drawBox()
w.toggleTree()
w.showWidgets()
case toolkit.Tab:
me.rootNode.hideWidgets()
w.drawBox()
w.toggleTree()
w.showWidgets()
case toolkit.Group:
w.drawBox()
w.toggleTree()
case toolkit.Grid:
me.rootNode.hideWidgets()
w.drawGrid()
w.toggleTree()
w.showWidgets()
case toolkit.Box:
// w.showWidgetPlacement(logNow, "drawTree()")
if (w.horizontal) {
@ -139,9 +142,9 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
f(me.rootNode)
var t string
for _, widget := range widgets {
log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name)
// log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name)
t += widget.cuiName + " " + widget.name + "\n"
// widget.showWidgetPlacement(logNow, "drawTree()")
widget.showWidgetPlacement(logNow, "ctrlDown() FOUND")
}
t = strings.TrimSpace(t)
if (me.ctrlDown == nil) {
@ -153,10 +156,11 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
if (found == nil) {
found = me.rootNode
}
me.ctrlDown.gocuiSize.startW = found.gocuiSize.startW
me.ctrlDown.gocuiSize.startH = found.gocuiSize.startH
me.ctrlDown.gocuiSize.width = found.gocuiSize.startW
me.ctrlDown.gocuiSize.height = found.gocuiSize.startH
me.ctrlDown.gocuiSize.startW = found.startW
me.ctrlDown.gocuiSize.startH = found.startH
me.ctrlDown.gocuiSize.width = found.realWidth
me.ctrlDown.gocuiSize.height = found.realHeight
me.ctrlDown.setWH()
if (me.ctrlDown.v == nil) {
me.ctrlDown.text = found.text

View File

@ -11,12 +11,20 @@ import (
func Init() {
log(logInfo, "Init() of awesome-gocui")
me.defaultWidth = 10
me.defaultHeight = 2
me.defaultHeight = 2 // this means by default one line of text in a button
me.defaultBehavior = true
me.horizontalPadding = 20
me.groupPadding = 2
me.buttonPadding = 2
me.horizontalPadding = 20
me.groupPadding = 4
me.buttonPadding = 3
// the raw beginning of each window (or tab)
me.rawW = 7
me.rawH = 3
me.padW = 3
me.padH = 3
}
func Exit() {

View File

@ -31,7 +31,14 @@ type config struct {
defaultBehavior bool
defaultWidth int
defaultHeight int
nextW int // where the next window or tab flag should go
// nextW int // where the next window or tab flag should go
padW int
padH int
// where the raw corner is
rawW int
rawH int
bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
canvas bool // if set to true, the windows are a raw canvas

View File

@ -42,7 +42,11 @@ func (w *cuiWidget) showFake() {
}
func (w *cuiWidget) showWidgets() {
if (w.isFake) {
// don't display by default
} else {
w.drawView()
}
for _, child := range w.children {
child.showWidgets()
}
@ -57,21 +61,26 @@ func (w *cuiWidget) setTabWH() {
w.gocuiSize.startW = me.rootNode.startW
w.gocuiSize.startH = me.rootNode.startH
w.startW = w.gocuiSize.startW + 2
w.startH = w.gocuiSize.startH + 3
w.startW = me.rawW
w.startH = me.rawH
for _, child := range me.rootNode.children {
if (child.isFake) {
continue
}
if (w == child) {
w.setWH()
w.showWidgetPlacement(logNow, "setTABWH:")
var f func (widget *cuiWidget)
// find buttons that are below where the mouse button click
f = func(widget *cuiWidget) {
if (widget == w) {
return
}
w.gocuiSize.startW += child.realWidth
if ((widget.widgetType == toolkit.Window) || (widget.widgetType == toolkit.Tab)) {
w.gocuiSize.startW += widget.gocuiSize.width + me.padW
}
for _, child := range widget.children {
f(child)
}
}
f(me.rootNode)
w.setWH()
w.showWidgetPlacement(logNow, "setTabWH:")
}