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

View File

@ -11,12 +11,20 @@ import (
func Init() { func Init() {
log(logInfo, "Init() of awesome-gocui") log(logInfo, "Init() of awesome-gocui")
me.defaultWidth = 10 me.defaultWidth = 10
me.defaultHeight = 2 me.defaultHeight = 2 // this means by default one line of text in a button
me.defaultBehavior = true me.defaultBehavior = true
me.horizontalPadding = 20 me.horizontalPadding = 20
me.groupPadding = 2 me.horizontalPadding = 20
me.buttonPadding = 2 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() { func Exit() {

View File

@ -31,7 +31,14 @@ type config struct {
defaultBehavior bool defaultBehavior bool
defaultWidth int defaultWidth int
defaultHeight 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? 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 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() { func (w *cuiWidget) showWidgets() {
if (w.isFake) {
// don't display by default
} else {
w.drawView() w.drawView()
}
for _, child := range w.children { for _, child := range w.children {
child.showWidgets() child.showWidgets()
} }
@ -57,21 +61,26 @@ func (w *cuiWidget) setTabWH() {
w.gocuiSize.startW = me.rootNode.startW w.gocuiSize.startW = me.rootNode.startW
w.gocuiSize.startH = me.rootNode.startH w.gocuiSize.startH = me.rootNode.startH
w.startW = w.gocuiSize.startW + 2 w.startW = me.rawW
w.startH = w.gocuiSize.startH + 3 w.startH = me.rawH
for _, child := range me.rootNode.children { var f func (widget *cuiWidget)
if (child.isFake) {
continue // find buttons that are below where the mouse button click
} f = func(widget *cuiWidget) {
if (w == child) { if (widget == w) {
w.setWH()
w.showWidgetPlacement(logNow, "setTABWH:")
return 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.setWH()
w.showWidgetPlacement(logNow, "setTabWH:") w.showWidgetPlacement(logNow, "setTabWH:")
} }