cleanups after node work

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-19 02:52:57 -06:00
parent d9a04e92fc
commit c2a563ae37
18 changed files with 41 additions and 260 deletions

View File

@ -6,8 +6,12 @@ plugin:
goget: goget:
GO111MODULE="off" go get -v -t -u GO111MODULE="off" go get -v -t -u
goimports:
goimports -w *.go
redomod: redomod:
rm -f go.* rm -f go.*
goimports -w *.go
GO111MODULE= go mod init GO111MODULE= go mod init
GO111MODULE= go mod tidy GO111MODULE= go mod tidy

View File

@ -54,15 +54,6 @@ func ready(n *tree.Node) bool {
} }
return true return true
} }
func (n *node) ready() bool {
if n == nil {
return false
}
if n.tk == nil {
return false
}
return true
}
func show(n *tree.Node, b bool) { func show(n *tree.Node, b bool) {
var tk *guiWidget var tk *guiWidget
@ -101,10 +92,10 @@ func enable(n *tree.Node, b bool) {
} }
} }
func (n *node) pad(b bool) { func pad(n *tree.Node, b bool) {
log.Warn("pad() on WidgetId =", n.WidgetId) log.Warn("pad() on WidgetId =", n.WidgetId)
t := n.tk t := n.TK.(*guiWidget)
if t == nil { if t == nil {
log.Log(ERROR, "pad() toolkit struct == nil. for", n.WidgetId) log.Log(ERROR, "pad() toolkit struct == nil. for", n.WidgetId)
return return
@ -123,33 +114,7 @@ func (n *node) pad(b bool) {
case widget.Box: case widget.Box:
t.uiBox.SetPadded(b) t.uiBox.SetPadded(b)
default: default:
log.Log(ERROR, "TODO: implement pad() for", n.WidgetType, n.progname) log.Log(ERROR, "TODO: implement pad() for", n.WidgetType, n.GetProgName())
}
}
func (n *node) move(newParent *node) {
p := n.parent
switch p.WidgetType {
case widget.Group:
case widget.Tab:
// tabSetMargined(tParent.uiTab, true)
case widget.Window:
// t.uiWindow.SetBorderless(false)
case widget.Grid:
// t.uiGrid.SetPadded(true)
case widget.Box:
log.Log(INFO, "TODO: move() where =", p.ParentId)
log.Log(INFO, "TODO: move() for widget =", n.WidgetId)
stretchy = true
if p.tk.uiBox != nil {
p.tk.uiBox.Append(n.tk.uiControl, stretchy)
}
default:
log.Log(ERROR, "TODO: need to implement move() for type =", n.WidgetType)
log.Log(ERROR, "TODO: need to implement move() for where =", p.ParentId)
log.Log(ERROR, "TODO: need to implement move() for widget =", n.WidgetId)
} }
} }
@ -197,7 +162,6 @@ func processAction(a *widget.Action) {
panic("me.treeRoot == nil") panic("me.treeRoot == nil")
} }
if a.ActionType == widget.Add { if a.ActionType == widget.Add {
add(a) add(a)
return return
@ -219,7 +183,6 @@ func processAction(a *widget.Action) {
return return
} }
switch a.ActionType { switch a.ActionType {
case widget.Delete: case widget.Delete:
widgetDelete(n) widgetDelete(n)

View File

@ -22,7 +22,7 @@ func newButton(p *tree.Node, n *tree.Node) {
newt.parent = ptk newt.parent = ptk
b.OnClicked(func(*ui.Button) { b.OnClicked(func(*ui.Button) {
me.myTree.DoUserEvent(n) me.myTree.SendUserEvent(n)
}) })
n.TK = newt n.TK = newt

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
@ -17,8 +18,11 @@ func newCheckbox(p *tree.Node, n *tree.Node) {
newt.uiControl = newt.uiCheckbox newt.uiControl = newt.uiCheckbox
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
n.SetValue(newt.checked()) var b bool
me.myTree.DoUserEvent(n) b = newt.checked()
n.SetValue(b)
log.Warn("Checkbox is now =", b)
me.myTree.SendUserEvent(n)
}) })
n.TK = newt n.TK = newt

View File

@ -25,7 +25,7 @@ func newCombobox(p, n *tree.Node) {
cb.OnChanged(func(spin *ui.EditableCombobox) { cb.OnChanged(func(spin *ui.EditableCombobox) {
n.SetValue(spin.Text()) n.SetValue(spin.Text())
log.Warn("combobox changed =" + spin.Text() + ".") log.Warn("combobox changed =" + spin.Text() + ".")
me.myTree.DoUserEvent(n) me.myTree.SendUserEvent(n)
}) })
n.TK = newt n.TK = newt

View File

@ -1,61 +0,0 @@
package main
import (
"go.wit.com/widget"
)
type node struct {
parent *node
children []*node
WidgetId int // widget ID
WidgetType widget.WidgetType
ParentId int // parent ID
state widget.State
// a reference name for programming and debuggign. Must be unique
progname string
// the text used for button labesl, window titles, checkbox names, etc
label string
// horizontal means layout widgets like books on a bookshelf
// vertical means layout widgets like books in a stack
// direction widget.Orientation
direction widget.Orientation
// This is how the values are passed back and forth
// values from things like checkboxes & dropdown's
value any
strings []string
// This is used for things like a slider(0,100)
X int
Y int
// This is for the grid size & widget position
W int
H int
AtW int
AtH int
vals []string // dropdown menu items
// horizontal bool `default:false`
hasTabs bool // does the window have tabs?
currentTab bool // the visible tab
// the internal plugin toolkit structure
// in the gtk plugin, it has gtk things like margin & border settings
// in the text console one, it has text console things like colors for menus & buttons
tk *guiWidget
}
/*
func (n *node) doUserEvent() {
log.Log(ERROR, "doUserEvent() ERROR")
}
*/

View File

@ -13,6 +13,7 @@ var stretchy bool // expand things like buttons to the maximum size
var padded bool // add space between things like buttons var padded bool // add space between things like buttons
var margin bool // add space around the frames of windows var margin bool // add space around the frames of windows
/*
var debugToolkit bool = false var debugToolkit bool = false
var debugChange bool = false var debugChange bool = false
var debugPlugin bool = false var debugPlugin bool = false
@ -21,23 +22,9 @@ var debugFlags bool = false
var debugGrid bool = false var debugGrid bool = false
var debugNow bool = true var debugNow bool = true
var debugError bool = true var debugError bool = true
*/
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc // This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func setDefaultBehavior(s bool) {
defaultBehavior = s
if defaultBehavior {
log.Log(NOW, "Setting this toolkit to use the default behavior.")
log.Log(NOW, "This is the 'guessing' part as defined by the wit/gui 'Principles'. Refer to the docs.")
stretchy = false
padded = true
menubar = true
margin = true
canvas = false
bookshelf = true // 99% of the time, things make a vertical stack of objects
} else {
log.Log(NOW, "This toolkit is set to ignore the default behavior.")
}
}
func (t *guiWidget) Dump(b bool) { func (t *guiWidget) Dump(b bool) {
if !b { if !b {
@ -75,46 +62,3 @@ func (t *guiWidget) Dump(b bool) {
log.Log(NOW, "uiCheckbox =", t.uiCheckbox) log.Log(NOW, "uiCheckbox =", t.uiCheckbox)
} }
} }
/*
func GetDebugToolkit () bool {
return debugToolkit
}
*/
func (n *node) dumpWidget(b bool) {
var info, d string
if n == nil {
log.Log(ERROR, "dumpWidget() node == nil")
return
}
info = n.WidgetType.String()
d = string(n.WidgetId) + " " + info + " " + n.progname
var tabs string
for i := 0; i < listChildrenDepth; i++ {
tabs = tabs + defaultPadding
}
log.Log(NOW, tabs+d)
}
var defaultPadding string = " "
var listChildrenDepth int = 0
func (n *node) listChildren(dump bool) {
if n == nil {
return
}
n.dumpWidget(dump)
if len(n.children) == 0 {
return
}
for _, child := range n.children {
listChildrenDepth += 1
child.listChildren(dump)
listChildrenDepth -= 1
}
}

View File

@ -1,54 +0,0 @@
package main
// if you include more than just this import
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
import (
"go.wit.com/log"
"go.wit.com/widget"
)
// delete the child widget from the parent
// p = parent, c = child
func (n *node) destroy() {
pId := n.parent.WidgetId
cId := n.WidgetId
log.Log(NOW, "delete()", pId, cId)
pt := n.parent.tk
ct := n.tk
if ct == nil {
log.Log(NOW, "delete FAILED (ct = mapToolkit[c] == nil) for c", pId, cId)
// this pukes out a whole universe of shit
// listMap()
return
}
switch n.WidgetType {
case widget.Button:
log.Log(NOW, "Should delete Button here:", n.progname)
log.Log(NOW, "Parent:")
pt.Dump(true)
log.Log(NOW, "Child:")
ct.Dump(true)
if pt.uiBox == nil {
log.Log(NOW, "Don't know how to destroy this")
} else {
log.Log(NOW, "Fuck it, destroy the whole box", n.parent.progname)
// pt.uiBox.Destroy() // You have a bug: You cannot destroy a uiControl while it still has a parent.
pt.uiBox.SetPadded(false)
pt.uiBox.Delete(4)
ct.uiButton.Disable()
// ct.uiButton.Hide()
ct.uiButton.Destroy()
}
case widget.Window:
log.Log(NOW, "Should delete Window here:", n.progname)
default:
log.Log(NOW, "Fuckit, let's destroy a button")
if ct.uiButton != nil {
pt.uiBox.Delete(4)
ct.uiButton.Destroy()
}
}
}

View File

@ -31,7 +31,7 @@ func newDropdown(p, n *tree.Node) {
} else { } else {
n.SetValue(newt.val[i]) n.SetValue(newt.val[i])
} }
me.myTree.DoUserEvent(n) me.myTree.SendUserEvent(n)
}) })
n.TK = newt n.TK = newt

12
go.mod
View File

@ -1,12 +0,0 @@
module go.wit.com/toolkits/andlabs
go 1.21.4
require (
go.wit.com/dev/andlabs/ui v0.0.1
go.wit.com/log v0.5.5
go.wit.com/toolkits/tree v0.0.4
go.wit.com/widget v1.1.5
)
require go.wit.com/dev/davecgh/spew v1.1.4 // indirect

10
go.sum
View File

@ -1,10 +0,0 @@
go.wit.com/dev/andlabs/ui v0.0.1 h1:SowOybLBu/qUOqp905EZikz5/iPa3GpmnCAPzNOYajM=
go.wit.com/dev/andlabs/ui v0.0.1/go.mod h1:mlKEEe05ZJURzjh1LtjzdGMHVbJm9a7BUaVpA9cHxsM=
go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek=
go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
go.wit.com/log v0.5.5 h1:bK3b94uVKgev4jB5wg06FnvCFBEapQICTSH2YW+CWr4=
go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
go.wit.com/toolkits/tree v0.0.4 h1:m9IPB4zsMamYgFMZX1BbvpnM7Upk7Q8wnjuECX/bNu8=
go.wit.com/toolkits/tree v0.0.4/go.mod h1:n4F2seonm1aYMml+YGOpCqWo0bkFwT/RH834J6f5/iE=
go.wit.com/widget v1.1.5 h1:jx5hJ2WLZJnCcvMuaLHegzpNlzwo+0kOkzsRkzRiB30=
go.wit.com/widget v1.1.5/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=

View File

@ -1,5 +1,6 @@
package main package main
/*
import ( import (
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "go.wit.com/dev/andlabs/ui/winmanifest"
@ -18,6 +19,7 @@ func (p *node) newImage(n *node) {
n.tk = newt n.tk = newt
// p.place(n) // p.place(n)
} }
*/
/* /*
if (a.Name == "image") { if (a.Name == "image") {

24
main.go
View File

@ -19,16 +19,16 @@ var muAction sync.Mutex
func queueMain(currentA widget.Action) { func queueMain(currentA widget.Action) {
/* /*
// this never happends // this never happends
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
log.Warn("YAHOOOO Recovered in queueMain() application:", r) log.Warn("YAHOOOO Recovered in queueMain() application:", r)
log.Println("Recovered from panic:", r) log.Println("Recovered from panic:", r)
log.Println("Stack trace:") log.Println("Stack trace:")
debug.PrintStack() debug.PrintStack()
me.myTree.DoToolkitPanic() me.myTree.SendToolkitPanic()
} }
}() }()
*/ */
// andlabs puts this inside the gofunction over there // andlabs puts this inside the gofunction over there
// probably this should be changed around here // probably this should be changed around here
@ -48,7 +48,7 @@ func guiMain() {
log.Println("Recovered from panic:", r) log.Println("Recovered from panic:", r)
log.Println("Stack trace:") log.Println("Stack trace:")
debug.PrintStack() debug.PrintStack()
me.myTree.DoToolkitPanic() me.myTree.SendToolkitPanic()
return return
} }
}() }()
@ -70,7 +70,7 @@ func init() {
log.Log(INFO, "Init()") log.Log(INFO, "Init()")
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print // Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
// log.Log(INFO, "init() Setting defaultBehavior = true") // log.Log(INFO, "init() Setting defaultBehavior = true")
setDefaultBehavior(true) // setDefaultBehavior(true)
me.myTree = tree.New() me.myTree = tree.New()
me.myTree.PluginName = "andlabs" me.myTree.PluginName = "andlabs"

View File

@ -23,7 +23,7 @@ func newSlider(p, n *tree.Node) {
s.OnChanged(func(spin *ui.Slider) { s.OnChanged(func(spin *ui.Slider) {
n.SetValue(newt.uiSlider.Value()) n.SetValue(newt.uiSlider.Value())
me.myTree.DoUserEvent(n) me.myTree.SendUserEvent(n)
}) })
n.TK = newt n.TK = newt

View File

@ -19,7 +19,7 @@ func newSpinner(p, n *tree.Node) {
s.OnChanged(func(s *ui.Spinbox) { s.OnChanged(func(s *ui.Spinbox) {
n.SetValue(newt.uiSpinbox.Value()) n.SetValue(newt.uiSpinbox.Value())
me.myTree.DoUserEvent(n) me.myTree.SendUserEvent(n)
}) })
n.TK = newt n.TK = newt

3
tab.go
View File

@ -2,7 +2,6 @@ package main
import ( import (
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/widget"
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "go.wit.com/dev/andlabs/ui/winmanifest"
@ -20,6 +19,7 @@ I work around this by always sending a Toolkit that is a tab
once there is one. If you send a Window here, it will replace once there is one. If you send a Window here, it will replace
any existing tabs rather than adding a new one any existing tabs rather than adding a new one
*/ */
/*
func (p *node) newTab(n *node) { func (p *node) newTab(n *node) {
var newt *guiWidget var newt *guiWidget
@ -55,6 +55,7 @@ func (p *node) newTab(n *node) {
n.tk = newt n.tk = newt
} }
*/
// This sets _all_ the tabs to Margin = true // This sets _all_ the tabs to Margin = true
// //

View File

@ -20,7 +20,7 @@ func newTextbox(p, n *tree.Node) {
e.OnChanged(func(spin *ui.Entry) { e.OnChanged(func(spin *ui.Entry) {
n.SetValue(spin.Text()) n.SetValue(spin.Text())
me.myTree.DoUserEvent(n) me.myTree.SendUserEvent(n)
}) })
} else { } else {
e := ui.NewNonWrappingMultilineEntry() e := ui.NewNonWrappingMultilineEntry()
@ -29,7 +29,7 @@ func newTextbox(p, n *tree.Node) {
e.OnChanged(func(spin *ui.MultilineEntry) { e.OnChanged(func(spin *ui.MultilineEntry) {
n.SetValue(spin.Text()) n.SetValue(spin.Text())
me.myTree.DoUserEvent(n) me.myTree.SendUserEvent(n)
}) })
} }
n.TK = newt n.TK = newt

View File

@ -4,9 +4,7 @@ import (
"go.wit.com/dev/andlabs/ui" "go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest" _ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget"
) )
func (t *guiWidget) MessageWindow(msg1 string, msg2 string) { func (t *guiWidget) MessageWindow(msg1 string, msg2 string) {
@ -27,7 +25,7 @@ func newWindow(p, n *tree.Node) {
win.SetMargined(margin) win.SetMargined(margin)
win.OnClosing(func(*ui.Window) bool { win.OnClosing(func(*ui.Window) bool {
// show(n, false) // show(n, false)
me.myTree.DoWindowCloseEvent(n) me.myTree.SendWindowCloseEvent(n)
return true return true
}) })
newt.uiWindow = win newt.uiWindow = win
@ -39,6 +37,7 @@ func newWindow(p, n *tree.Node) {
return return
} }
/*
func (n *node) SetWindowTitle(title string) { func (n *node) SetWindowTitle(title string) {
log.Log(CHANGE, "toolkit NewWindow", widget.GetString(n.value), "title", title) log.Log(CHANGE, "toolkit NewWindow", widget.GetString(n.value), "title", title)
win := n.tk.uiWindow win := n.tk.uiWindow
@ -49,3 +48,4 @@ func (n *node) SetWindowTitle(title string) {
log.Log(CHANGE, "Setting the window title", title) log.Log(CHANGE, "Setting the window title", title)
} }
} }
*/