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

25
grid.go
View File

@ -25,8 +25,8 @@ import (
func (n *Node) NewGrid(name string, w int, h int) *Node {
newNode := n.newNode(name, toolkit.Grid)
newNode.X = w
newNode.Y = h
newNode.W = w
newNode.H = h
newNode.NextW = 1
newNode.NextH = 1
@ -51,10 +51,10 @@ func (n *Node) gridIncrement() {
return
}
n.NextH += 1
if (n.NextH > n.Y) {
n.NextW += 1
n.NextH = 1
n.NextW += 1
if (n.NextW > n.W) {
n.NextW = 1
n.NextH += 1
}
n.gridIncrement()
@ -74,16 +74,3 @@ func (n *Node) At(w int, h int) *Node {
}
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
height int
// used for anything that needs a range
// used for anything that needs a range (for example: a slider)
X int
Y int
// the position of the widget in a grid
AtW int
AtH int
// where the next widget should be put in a grid
// the grid max width and height
// ignore max height when there is no space left?
W int
H int
// where the next widget should be put in this grid
NextW int
NextH int
// if this widget is in a grid, this is the position
AtW int
AtH int
// used for values
I int
S string

View File

@ -171,8 +171,8 @@ func (n *node) Delete() {
}
func rawAction(a toolkit.Action) {
log(logNow, "rawAction() START a.ActionType =", a.ActionType)
log(logNow, "rawAction() START a.S =", a.S)
log(logInfo, "rawAction() START a.ActionType =", a.ActionType)
log(logInfo, "rawAction() START a.S =", a.S)
if (a.ActionType == toolkit.InitToolkit) {
// TODO: make sure to only do this once
@ -184,7 +184,7 @@ func rawAction(a toolkit.Action) {
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 {
case toolkit.Flag:
flag(&a)
@ -198,7 +198,7 @@ func rawAction(a toolkit.Action) {
ui.QueueMain(func() {
add(a)
})
sleep(.1)
sleep(.05)
case toolkit.Show:
n.show(true)
case toolkit.Hide:
@ -237,5 +237,5 @@ func rawAction(a toolkit.Action) {
default:
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)
switch p.WidgetType {
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.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
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)
return true
case toolkit.Group:
if (p.tk.uiBox == nil) {
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
} else {
p.tk.uiBox.Append(n.tk.uiControl, stretchy)

View File

@ -92,6 +92,24 @@ func GetDebugToolkit () bool {
func flag(a *toolkit.Action) {
// should set the checkbox to this value
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":
debugToolkit = a.B
case "Change":
@ -100,8 +118,6 @@ func flag(a *toolkit.Action) {
debugPlugin = a.B
case "Flags":
debugFlags = a.B
case "Error":
debugError = a.B
case "Now":
debugNow = a.B
case "Show":

View File

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

View File

@ -20,19 +20,19 @@ var uiMain sync.Once
var muAction sync.Mutex
func catchActionChannel() {
log(logNow, "catchActionChannel() START")
log(logInfo, "catchActionChannel() START")
for {
log(logNow, "catchActionChannel() for loop")
log(logInfo, "catchActionChannel() for loop")
select {
case a := <-pluginChan:
log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
log(logInfo, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
log(logInfo, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
muAction.Lock()
// TODO ui.QueueMain(f)
// TODO ui.QueueMain( func() {rawAction(a)} )
rawAction(a)
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) {
found = me.rootNode
}
found.setRealSize()
// ? TODO: found.setRealSize()
me.ctrlDown.gocuiSize.w0 = found.startW
me.ctrlDown.gocuiSize.h0 = found.startH
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.i = a.I
w.s = a.S
w.X = a.X
w.Y = a.Y
t := len(w.text)
w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW
w.gocuiSize.h1 = w.gocuiSize.h0 + me.DefaultHeight + me.PadH

View File

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

View File

@ -93,7 +93,7 @@ var (
// this is the standard binary tree structure for toolkits
type node struct {
parent *node
parent *node
children []*node
WidgetId int // widget ID
@ -115,6 +115,12 @@ type node struct {
X int
Y int
// This is for the grid size & widget position
W int
H int
AtW int
AtH int
// the internal plugin toolkit structure
tk *cuiWidget
}
@ -199,7 +205,7 @@ type cuiWidget struct {
v *gocui.View
frame bool
parent *cuiWidget
parent *cuiWidget
children []*cuiWidget
}