andlabs: debugging flags working again

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-05-10 14:28:30 -05:00
parent be3c212bae
commit 603d5ba7de
12 changed files with 67 additions and 51 deletions

View File

@ -14,7 +14,7 @@ var myGui *gui.Node
var buttonCounter int = 5 var buttonCounter int = 5
var gridW int = 5 var gridW int = 5
var gridH int = 2 var gridH int = 3
func main() { func main() {
// This will turn on all debugging // This will turn on all debugging
@ -72,8 +72,8 @@ func buttonWindow() {
}) })
g.NewButton("NewButton(more)", func () { g.NewButton("NewButton(more)", func () {
log.Println("new foobar 2. Adding button 'foobar 3'")
name := "foobar " + strconv.Itoa(buttonCounter) name := "foobar " + strconv.Itoa(buttonCounter)
log.Println("NewButton(more) Adding button", name)
buttonCounter += 1 buttonCounter += 1
more.NewButton(name, func () { more.NewButton(name, func () {
log.Println("Got all the way to main() name =", name) log.Println("Got all the way to main() name =", name)
@ -81,8 +81,8 @@ func buttonWindow() {
}) })
g.NewButton("NewButton(more2)", func () { g.NewButton("NewButton(more2)", func () {
log.Println("new foobar 2. Adding button 'foobar 3'")
name := "foobar " + strconv.Itoa(buttonCounter) name := "foobar " + strconv.Itoa(buttonCounter)
log.Println("NewButton(more2) Adding button", name)
buttonCounter += 1 buttonCounter += 1
more2.NewButton(name, func () { more2.NewButton(name, func () {
log.Println("Got all the way to main() name =", name) log.Println("Got all the way to main() name =", name)
@ -90,8 +90,8 @@ func buttonWindow() {
}) })
g.NewButton("NewButton(more2 d)", func () { g.NewButton("NewButton(more2 d)", func () {
log.Println("new foobar 2. Adding button 'foobar 3'")
name := "d" + strconv.Itoa(buttonCounter) name := "d" + strconv.Itoa(buttonCounter)
log.Println("NewButton(more2 d) Adding button", name)
buttonCounter += 1 buttonCounter += 1
more2.NewButton(name, func () { more2.NewButton(name, func () {
log.Println("Got all the way to main() name =", name) log.Println("Got all the way to main() name =", name)
@ -99,8 +99,8 @@ func buttonWindow() {
}) })
g.NewButton("NewGroup()", func () { g.NewButton("NewGroup()", func () {
log.Println("new foobar 2. Adding button 'foobar 3'")
name := "neat " + strconv.Itoa(buttonCounter) name := "neat " + strconv.Itoa(buttonCounter)
log.Println("NewGroup() Adding button", name)
buttonCounter += 1 buttonCounter += 1
more.NewGroup(name) more.NewGroup(name)
}) })

23
grid.go
View File

@ -25,8 +25,8 @@ import (
func (n *Node) NewGrid(name string, w int, h int) *Node { func (n *Node) NewGrid(name string, w int, h int) *Node {
newNode := n.newNode(name, toolkit.Grid) newNode := n.newNode(name, toolkit.Grid)
newNode.X = w newNode.W = w
newNode.Y = h newNode.H = h
newNode.NextW = 1 newNode.NextW = 1
newNode.NextH = 1 newNode.NextH = 1
@ -51,10 +51,10 @@ func (n *Node) gridIncrement() {
return return
} }
n.NextH += 1
if (n.NextH > n.Y) {
n.NextW += 1 n.NextW += 1
n.NextH = 1 if (n.NextW > n.W) {
n.NextW = 1
n.NextH += 1
} }
n.gridIncrement() n.gridIncrement()
@ -74,16 +74,3 @@ func (n *Node) At(w int, h int) *Node {
} }
return n return n
} }
// finds the next place on the grid to place the new node 'n'
func placeGrid(a *toolkit.Action, n *Node, where *Node) {
where.NextH += 1
if (where.NextH > where.Y) {
where.NextW += 1
where.NextH = 1
}
a.X = where.NextW
a.Y = where.NextH
log(logNow, "placeGrid() (X,Y)", where.X, where.Y, " next(X,Y) =", where.NextW, where.NextH)
}

View File

@ -66,17 +66,22 @@ type Node struct {
width int width int
height int height int
// used for anything that needs a range // used for anything that needs a range (for example: a slider)
X int X int
Y int Y int
// the position of the widget in a grid // the grid max width and height
AtW int // ignore max height when there is no space left?
AtH int W int
// where the next widget should be put in a grid H int
// where the next widget should be put in this grid
NextW int NextW int
NextH int NextH int
// if this widget is in a grid, this is the position
AtW int
AtH int
// used for values // used for values
I int I int
S string S string

View File

@ -171,8 +171,8 @@ func (n *node) Delete() {
} }
func rawAction(a toolkit.Action) { func rawAction(a toolkit.Action) {
log(logNow, "rawAction() START a.ActionType =", a.ActionType) log(logInfo, "rawAction() START a.ActionType =", a.ActionType)
log(logNow, "rawAction() START a.S =", a.S) log(logInfo, "rawAction() START a.S =", a.S)
if (a.ActionType == toolkit.InitToolkit) { if (a.ActionType == toolkit.InitToolkit) {
// TODO: make sure to only do this once // TODO: make sure to only do this once
@ -184,7 +184,7 @@ func rawAction(a toolkit.Action) {
return return
} }
log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId) log(logInfo, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType { switch a.WidgetType {
case toolkit.Flag: case toolkit.Flag:
flag(&a) flag(&a)
@ -198,7 +198,7 @@ func rawAction(a toolkit.Action) {
ui.QueueMain(func() { ui.QueueMain(func() {
add(a) add(a)
}) })
sleep(.1) sleep(.05)
case toolkit.Show: case toolkit.Show:
n.show(true) n.show(true)
case toolkit.Hide: case toolkit.Hide:
@ -237,5 +237,5 @@ func rawAction(a toolkit.Action) {
default: default:
log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType) log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
} }
log(debugAction, "rawAction() END =", a.ActionType, a.WidgetType) log(logInfo, "rawAction() END =", a.ActionType, a.WidgetType)
} }

View File

@ -107,19 +107,19 @@ func (p *node) place(n *node) bool {
log(logInfo, "place() switch", p.WidgetType) log(logInfo, "place() switch", p.WidgetType)
switch p.WidgetType { switch p.WidgetType {
case toolkit.Grid: case toolkit.Grid:
log(debugGrid, "place() Grid try at Parent X,Y =", n.X, n.Y) log(logInfo, "place() Grid try at Parent X,Y =", n.X, n.Y)
n.tk.gridX = n.AtW - 1 n.tk.gridX = n.AtW - 1
n.tk.gridY = n.AtH - 1 n.tk.gridY = n.AtH - 1
log(debugGrid, "place() Grid try at gridX,gridY", n.tk.gridX, n.tk.gridY) log(logInfo, "place() Grid try at gridX,gridY", n.tk.gridX, n.tk.gridY)
// at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero // at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
p.tk.uiGrid.Append(n.tk.uiControl, p.tk.uiGrid.Append(n.tk.uiControl,
n.tk.gridY, n.tk.gridX, 1, 1, n.tk.gridX, n.tk.gridY, 1, 1,
false, ui.AlignFill, false, ui.AlignFill) false, ui.AlignFill, false, ui.AlignFill)
return true return true
case toolkit.Group: case toolkit.Group:
if (p.tk.uiBox == nil) { if (p.tk.uiBox == nil) {
p.tk.uiGroup.SetChild(n.tk.uiControl) p.tk.uiGroup.SetChild(n.tk.uiControl)
log(debugGrid, "place() hack Group to use this as the box?", n.Name, n.WidgetType) log(logInfo, "place() hack Group to use this as the box?", n.Name, n.WidgetType)
p.tk.uiBox = n.tk.uiBox p.tk.uiBox = n.tk.uiBox
} else { } else {
p.tk.uiBox.Append(n.tk.uiControl, stretchy) p.tk.uiBox.Append(n.tk.uiControl, stretchy)

View File

@ -92,6 +92,24 @@ func GetDebugToolkit () bool {
func flag(a *toolkit.Action) { func flag(a *toolkit.Action) {
// should set the checkbox to this value // should set the checkbox to this value
switch a.S { switch a.S {
case "Quiet":
logInfo = a.B
logVerbose = a.B
logWarn = a.B
logError = a.B
case "Error":
logError = a.B
case "Info":
logInfo = a.B
case "Verbose":
logInfo = a.B
logVerbose = a.B
logWarn = a.B
logError = a.B
debugToolkit = a.B
debugChange = a.B
debugPlugin = a.B
debugFlags = a.B
case "Toolkit": case "Toolkit":
debugToolkit = a.B debugToolkit = a.B
case "Change": case "Change":
@ -100,8 +118,6 @@ func flag(a *toolkit.Action) {
debugPlugin = a.B debugPlugin = a.B
case "Flags": case "Flags":
debugFlags = a.B debugFlags = a.B
case "Error":
debugError = a.B
case "Now": case "Now":
debugNow = a.B debugNow = a.B
case "Show": case "Show":

View File

@ -8,8 +8,8 @@ import (
var logNow bool = true // useful for active development var logNow bool = true // useful for active development
var logError bool = true var logError bool = true
var logWarn bool = true var logWarn bool = true
var logInfo bool = true var logInfo bool = false
var logVerbose bool = true var logVerbose bool = false
func log(a ...any) { func log(a ...any) {
witlog.Where = "wit/gui/andlabs" witlog.Where = "wit/gui/andlabs"

View File

@ -20,19 +20,19 @@ var uiMain sync.Once
var muAction sync.Mutex var muAction sync.Mutex
func catchActionChannel() { func catchActionChannel() {
log(logNow, "catchActionChannel() START") log(logInfo, "catchActionChannel() START")
for { for {
log(logNow, "catchActionChannel() for loop") log(logInfo, "catchActionChannel() for loop")
select { select {
case a := <-pluginChan: case a := <-pluginChan:
log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name) log(logInfo, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType) log(logInfo, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
muAction.Lock() muAction.Lock()
// TODO ui.QueueMain(f) // TODO ui.QueueMain(f)
// TODO ui.QueueMain( func() {rawAction(a)} ) // TODO ui.QueueMain( func() {rawAction(a)} )
rawAction(a) rawAction(a)
muAction.Unlock() muAction.Unlock()
log(logNow, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType) log(logInfo, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
} }
} }
} }

View File

@ -260,7 +260,7 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
if (found == nil) { if (found == nil) {
found = me.rootNode found = me.rootNode
} }
found.setRealSize() // ? TODO: found.setRealSize()
me.ctrlDown.gocuiSize.w0 = found.startW me.ctrlDown.gocuiSize.w0 = found.startW
me.ctrlDown.gocuiSize.h0 = found.startH me.ctrlDown.gocuiSize.h0 = found.startH
me.ctrlDown.gocuiSize.w1 = me.ctrlDown.gocuiSize.w0 + found.realWidth me.ctrlDown.gocuiSize.w1 = me.ctrlDown.gocuiSize.w0 + found.realWidth

View File

@ -15,10 +15,10 @@ func makeWidget(a *toolkit.Action) *cuiWidget {
w.b = a.B w.b = a.B
w.i = a.I w.i = a.I
w.s = a.S w.s = a.S
w.X = a.X w.X = a.X
w.Y = a.Y w.Y = a.Y
t := len(w.text) t := len(w.text)
w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW
w.gocuiSize.h1 = w.gocuiSize.h0 + me.DefaultHeight + me.PadH w.gocuiSize.h1 = w.gocuiSize.h0 + me.DefaultHeight + me.PadH

View File

@ -257,5 +257,7 @@ func (w *cuiWidget) placeGrid() {
w.showWidgetPlacement(logNow, "grid3:") w.showWidgetPlacement(logNow, "grid3:")
} }
/*
func (w *cuiWidget) setRealSize() { func (w *cuiWidget) setRealSize() {
} }
*/

View File

@ -115,6 +115,12 @@ type node struct {
X int X int
Y int Y int
// This is for the grid size & widget position
W int
H int
AtW int
AtH int
// the internal plugin toolkit structure // the internal plugin toolkit structure
tk *cuiWidget tk *cuiWidget
} }