cleanups after node work
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d9a04e92fc
commit
c2a563ae37
4
Makefile
4
Makefile
|
@ -6,8 +6,12 @@ plugin:
|
|||
goget:
|
||||
GO111MODULE="off" go get -v -t -u
|
||||
|
||||
goimports:
|
||||
goimports -w *.go
|
||||
|
||||
redomod:
|
||||
rm -f go.*
|
||||
goimports -w *.go
|
||||
GO111MODULE= go mod init
|
||||
GO111MODULE= go mod tidy
|
||||
|
||||
|
|
43
action.go
43
action.go
|
@ -54,15 +54,6 @@ func ready(n *tree.Node) bool {
|
|||
}
|
||||
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) {
|
||||
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)
|
||||
|
||||
t := n.tk
|
||||
t := n.TK.(*guiWidget)
|
||||
if t == nil {
|
||||
log.Log(ERROR, "pad() toolkit struct == nil. for", n.WidgetId)
|
||||
return
|
||||
|
@ -123,33 +114,7 @@ func (n *node) pad(b bool) {
|
|||
case widget.Box:
|
||||
t.uiBox.SetPadded(b)
|
||||
default:
|
||||
log.Log(ERROR, "TODO: implement pad() for", n.WidgetType, n.progname)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
log.Log(ERROR, "TODO: implement pad() for", n.WidgetType, n.GetProgName())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +162,6 @@ func processAction(a *widget.Action) {
|
|||
panic("me.treeRoot == nil")
|
||||
}
|
||||
|
||||
|
||||
if a.ActionType == widget.Add {
|
||||
add(a)
|
||||
return
|
||||
|
@ -219,7 +183,6 @@ func processAction(a *widget.Action) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
switch a.ActionType {
|
||||
case widget.Delete:
|
||||
widgetDelete(n)
|
||||
|
|
|
@ -22,7 +22,7 @@ func newButton(p *tree.Node, n *tree.Node) {
|
|||
newt.parent = ptk
|
||||
|
||||
b.OnClicked(func(*ui.Button) {
|
||||
me.myTree.DoUserEvent(n)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
|
||||
n.TK = newt
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/toolkits/tree"
|
||||
|
||||
"go.wit.com/dev/andlabs/ui"
|
||||
|
@ -17,8 +18,11 @@ func newCheckbox(p *tree.Node, n *tree.Node) {
|
|||
newt.uiControl = newt.uiCheckbox
|
||||
|
||||
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
|
||||
n.SetValue(newt.checked())
|
||||
me.myTree.DoUserEvent(n)
|
||||
var b bool
|
||||
b = newt.checked()
|
||||
n.SetValue(b)
|
||||
log.Warn("Checkbox is now =", b)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
|
||||
n.TK = newt
|
||||
|
|
|
@ -25,7 +25,7 @@ func newCombobox(p, n *tree.Node) {
|
|||
cb.OnChanged(func(spin *ui.EditableCombobox) {
|
||||
n.SetValue(spin.Text())
|
||||
log.Warn("combobox changed =" + spin.Text() + ".")
|
||||
me.myTree.DoUserEvent(n)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
|
||||
n.TK = newt
|
||||
|
|
61
common.go
61
common.go
|
@ -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")
|
||||
}
|
||||
*/
|
60
debug.go
60
debug.go
|
@ -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 margin bool // add space around the frames of windows
|
||||
|
||||
/*
|
||||
var debugToolkit bool = false
|
||||
var debugChange bool = false
|
||||
var debugPlugin bool = false
|
||||
|
@ -21,23 +22,9 @@ var debugFlags bool = false
|
|||
var debugGrid bool = false
|
||||
var debugNow bool = true
|
||||
var debugError bool = true
|
||||
*/
|
||||
|
||||
// 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) {
|
||||
if !b {
|
||||
|
@ -75,46 +62,3 @@ func (t *guiWidget) Dump(b bool) {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
54
delete.go
54
delete.go
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ func newDropdown(p, n *tree.Node) {
|
|||
} else {
|
||||
n.SetValue(newt.val[i])
|
||||
}
|
||||
me.myTree.DoUserEvent(n)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
|
||||
n.TK = newt
|
||||
|
|
12
go.mod
12
go.mod
|
@ -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
10
go.sum
|
@ -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=
|
2
image.go
2
image.go
|
@ -1,5 +1,6 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
import (
|
||||
"go.wit.com/dev/andlabs/ui"
|
||||
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
||||
|
@ -18,6 +19,7 @@ func (p *node) newImage(n *node) {
|
|||
n.tk = newt
|
||||
// p.place(n)
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if (a.Name == "image") {
|
||||
|
|
24
main.go
24
main.go
|
@ -19,16 +19,16 @@ var muAction sync.Mutex
|
|||
|
||||
func queueMain(currentA widget.Action) {
|
||||
/*
|
||||
// this never happends
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Warn("YAHOOOO Recovered in queueMain() application:", r)
|
||||
log.Println("Recovered from panic:", r)
|
||||
log.Println("Stack trace:")
|
||||
debug.PrintStack()
|
||||
me.myTree.DoToolkitPanic()
|
||||
}
|
||||
}()
|
||||
// this never happends
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Warn("YAHOOOO Recovered in queueMain() application:", r)
|
||||
log.Println("Recovered from panic:", r)
|
||||
log.Println("Stack trace:")
|
||||
debug.PrintStack()
|
||||
me.myTree.SendToolkitPanic()
|
||||
}
|
||||
}()
|
||||
*/
|
||||
// andlabs puts this inside the gofunction over there
|
||||
// probably this should be changed around here
|
||||
|
@ -48,7 +48,7 @@ func guiMain() {
|
|||
log.Println("Recovered from panic:", r)
|
||||
log.Println("Stack trace:")
|
||||
debug.PrintStack()
|
||||
me.myTree.DoToolkitPanic()
|
||||
me.myTree.SendToolkitPanic()
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
@ -70,7 +70,7 @@ func init() {
|
|||
log.Log(INFO, "Init()")
|
||||
// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
|
||||
// log.Log(INFO, "init() Setting defaultBehavior = true")
|
||||
setDefaultBehavior(true)
|
||||
// setDefaultBehavior(true)
|
||||
|
||||
me.myTree = tree.New()
|
||||
me.myTree.PluginName = "andlabs"
|
||||
|
|
|
@ -23,7 +23,7 @@ func newSlider(p, n *tree.Node) {
|
|||
|
||||
s.OnChanged(func(spin *ui.Slider) {
|
||||
n.SetValue(newt.uiSlider.Value())
|
||||
me.myTree.DoUserEvent(n)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
|
||||
n.TK = newt
|
||||
|
|
|
@ -19,7 +19,7 @@ func newSpinner(p, n *tree.Node) {
|
|||
|
||||
s.OnChanged(func(s *ui.Spinbox) {
|
||||
n.SetValue(newt.uiSpinbox.Value())
|
||||
me.myTree.DoUserEvent(n)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
|
||||
n.TK = newt
|
||||
|
|
3
tab.go
3
tab.go
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/widget"
|
||||
|
||||
"go.wit.com/dev/andlabs/ui"
|
||||
_ "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
|
||||
any existing tabs rather than adding a new one
|
||||
*/
|
||||
/*
|
||||
func (p *node) newTab(n *node) {
|
||||
var newt *guiWidget
|
||||
|
||||
|
@ -55,6 +55,7 @@ func (p *node) newTab(n *node) {
|
|||
|
||||
n.tk = newt
|
||||
}
|
||||
*/
|
||||
|
||||
// This sets _all_ the tabs to Margin = true
|
||||
//
|
||||
|
|
|
@ -20,7 +20,7 @@ func newTextbox(p, n *tree.Node) {
|
|||
|
||||
e.OnChanged(func(spin *ui.Entry) {
|
||||
n.SetValue(spin.Text())
|
||||
me.myTree.DoUserEvent(n)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
} else {
|
||||
e := ui.NewNonWrappingMultilineEntry()
|
||||
|
@ -29,7 +29,7 @@ func newTextbox(p, n *tree.Node) {
|
|||
|
||||
e.OnChanged(func(spin *ui.MultilineEntry) {
|
||||
n.SetValue(spin.Text())
|
||||
me.myTree.DoUserEvent(n)
|
||||
me.myTree.SendUserEvent(n)
|
||||
})
|
||||
}
|
||||
n.TK = newt
|
||||
|
|
|
@ -4,9 +4,7 @@ import (
|
|||
"go.wit.com/dev/andlabs/ui"
|
||||
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
||||
|
||||
"go.wit.com/log"
|
||||
"go.wit.com/toolkits/tree"
|
||||
"go.wit.com/widget"
|
||||
)
|
||||
|
||||
func (t *guiWidget) MessageWindow(msg1 string, msg2 string) {
|
||||
|
@ -27,7 +25,7 @@ func newWindow(p, n *tree.Node) {
|
|||
win.SetMargined(margin)
|
||||
win.OnClosing(func(*ui.Window) bool {
|
||||
// show(n, false)
|
||||
me.myTree.DoWindowCloseEvent(n)
|
||||
me.myTree.SendWindowCloseEvent(n)
|
||||
return true
|
||||
})
|
||||
newt.uiWindow = win
|
||||
|
@ -39,6 +37,7 @@ func newWindow(p, n *tree.Node) {
|
|||
return
|
||||
}
|
||||
|
||||
/*
|
||||
func (n *node) SetWindowTitle(title string) {
|
||||
log.Log(CHANGE, "toolkit NewWindow", widget.GetString(n.value), "title", title)
|
||||
win := n.tk.uiWindow
|
||||
|
@ -49,3 +48,4 @@ func (n *node) SetWindowTitle(title string) {
|
|||
log.Log(CHANGE, "Setting the window title", title)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue