gocui: next step hide junk

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-06 06:01:14 -05:00
parent 6b7d1fb30b
commit c29faf4f9b
4 changed files with 101 additions and 138 deletions

95
toolkit/gocui/add.go Normal file
View File

@ -0,0 +1,95 @@
package main
import (
// "github.com/awesome-gocui/gocui"
"git.wit.org/wit/gui/toolkit"
)
var fakeStartWidth int = 40
var fakeStartHeight int = 3
func (w *cuiWidget) setFake() {
if (w.isFake == false) {
return
}
t := len(w.name)
// setup fake labels for non-visable things off screen
w.realWidth = t + 2
w.realHeight = me.defaultHeight
w.gocuiSize.width = t + 2
w.gocuiSize.height = me.defaultHeight
w.gocuiSize.startW = fakeStartWidth
w.gocuiSize.startH = fakeStartHeight
fakeStartHeight += 3
if (fakeStartHeight > 24) {
fakeStartHeight = 3
fakeStartWidth += 20
}
w.setWH()
w.showWidgetPlacement(logNow, "setFake()")
}
// set the widget start width & height
func (w *cuiWidget) addWidget() {
log(logInfo, "setStartWH() w.id =", w.id, "w.name", w.name)
switch w.widgetType {
case toolkit.Root:
log(logInfo, "setStartWH() rootNode w.id =", w.id, "w.name", w.name)
w.isFake = true
w.setFake()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Flag:
w.isFake = true
w.setFake()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Window:
w.setTabWH()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Tab:
w.setTabWH()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Box:
w.isFake = true
w.setFake()
w.startW = w.parent.startW
w.startH = w.parent.startH
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Grid:
w.isFake = true
w.setFake()
w.startW = w.parent.startW
w.startH = w.parent.startH
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Group:
w.startW = w.parent.startW + 4
w.startH = w.parent.startH + 3
t := len(w.text)
w.gocuiSize.width = t + me.buttonPadding
w.gocuiSize.height = me.defaultHeight
w.gocuiSize.startW = w.startW
w.gocuiSize.startH = w.startH
w.setWH()
w.showWidgetPlacement(logNow, "StartWH:")
// w.drawView()
return
default:
w.startW = w.parent.startW
w.startH = w.parent.startH
w.setWH()
}
}

View File

@ -6,7 +6,7 @@ import (
// "github.com/awesome-gocui/gocui"
)
func setupWidget(a *toolkit.Action) *cuiWidget {
func makeWidget(a *toolkit.Action) *cuiWidget {
var w *cuiWidget
w = new(cuiWidget)

View File

@ -5,33 +5,9 @@ import (
"git.wit.org/wit/gui/toolkit"
)
var fakeStartWidth int = 40
var fakeStartHeight int = 3
func (w *cuiWidget) setFake() {
if (w.isFake == false) {
return
}
t := len(w.name)
// setup fake labels for non-visable things off screen
w.realWidth = t + 2
w.realHeight = me.defaultHeight
w.gocuiSize.width = t + 2
w.gocuiSize.height = me.defaultHeight
w.gocuiSize.startW = fakeStartWidth
w.gocuiSize.startH = fakeStartHeight
fakeStartHeight += 3
if (fakeStartHeight > 24) {
fakeStartHeight = 3
fakeStartWidth += 20
}
w.setWH()
w.showWidgetPlacement(logNow, "setFake()")
}
/*
// find the start (w,h) for child a inside a box widget
func (w *cuiWidget) getBoxWH() {
func (w *cuiWidget) setBoxWH() {
p := w.parent // the parent must be a box widget
// update parent gocuiSize
@ -63,6 +39,7 @@ func (w *cuiWidget) getBoxWH() {
}
return
}
*/
// find the start (w,h) for child a inside a Group widget
func (w *cuiWidget) getGroupWH() {
@ -205,27 +182,6 @@ func (w *cuiWidget) moveTo(leftW int, topH int) {
w.showWidgetPlacement(logNow, "moveTo()")
}
/*
func (w *cuiWidget) updateLogicalSizes() {
for _, child := range w.children {
// if (w.isReal)
child.updateLogicalSizes()
if (w.logicalSize.w0 > child.logicalSize.w0) {
w.logicalSize.w0 = child.logicalSize.w0
}
if (w.logicalSize.w1 < child.logicalSize.w1) {
w.logicalSize.w1 = child.logicalSize.w1
}
if (w.logicalSize.h0 > child.logicalSize.h0) {
w.logicalSize.h0 = child.logicalSize.h0
}
if (w.logicalSize.h1 < child.logicalSize.h1) {
w.logicalSize.h1 = child.logicalSize.h1
}
}
}
*/
func (w *cuiWidget) drawGrid() {
w.showWidgetPlacement(logNow, "gridBounds:")

View File

@ -10,101 +10,13 @@ func Quit() {
me.baseGui.Close()
}
// set the widget start width & height
// re-run this when things change to recalibrate the position of the gocui view rect
func (w *cuiWidget) setStartWH() {
log(logInfo, "setStartWH() w.id =", w.id, "w.name", w.name)
switch w.widgetType {
case toolkit.Root:
log(logInfo, "setStartWH() rootNode w.id =", w.id, "w.name", w.name)
w.isFake = true
w.setFake()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Flag:
w.isFake = true
w.setFake()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Window:
w.setTabWH()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Tab:
w.setTabWH()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Box:
w.isFake = true
w.setFake()
w.startW = w.parent.startW
w.startH = w.parent.startH
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Grid:
w.isFake = true
w.setFake()
w.startW = w.parent.startW
w.startH = w.parent.startH
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
case toolkit.Group:
w.startW = w.parent.startW + 4
w.startH = w.parent.startH + 3
t := len(w.text)
w.gocuiSize.width = t + me.buttonPadding
w.gocuiSize.height = me.defaultHeight
w.gocuiSize.startW = w.startW
w.gocuiSize.startH = w.startH
w.setWH()
w.showWidgetPlacement(logNow, "StartWH:")
w.drawView()
return
default:
w.startW = w.parent.startW
w.startH = w.parent.startH
w.setWH()
}
}
/*
func (w *cuiWidget) setStartFromParent() {
p := w.parent
switch p.widgetType {
case toolkit.Box:
w.getBoxWH()
case toolkit.Group:
w.getGroupWH()
case toolkit.Grid:
w.getGridWH()
default:
w.gocuiSize.startW = p.startW
w.gocuiSize.startH = p.startH
}
w.gocuiSize.startW = w.startW
w.gocuiSize.startH = w.startH
w.startW = w.gocuiSize.startW
w.startH = w.gocuiSize.startH
w.showWidgetPlacement(logNow, "sSFP:")
}
*/
func Action(a *toolkit.Action) {
log(logInfo, "Action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
w := findWidget(a.WidgetId, me.rootNode)
switch a.ActionType {
case toolkit.Add:
w = setupWidget(a)
w.setStartWH()
w = makeWidget(a)
w.addWidget()
case toolkit.Show:
if (a.B) {
w.drawView()