things are moving to widget.State

pass borderless
    windows correctly destroy themselves from the binary tree
    checkbox state cleanups

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-19 12:18:11 -06:00
parent c2a563ae37
commit f48b950655
11 changed files with 83 additions and 31 deletions

View File

@ -34,6 +34,19 @@ func notNew(n *tree.Node) bool {
return false return false
} }
func tkbad(n *tree.Node) bool {
if n == nil {
log.Warn("ready() n = nil")
return true
}
if n.TK == nil {
log.Warn("ready() n.TK = nil", n.WidgetId, n.GetProgName())
return true
}
return false
}
// this makes sure widget and it's parent exists
func ready(n *tree.Node) bool { func ready(n *tree.Node) bool {
if n == nil { if n == nil {
log.Warn("ready() n = nil") log.Warn("ready() n = nil")
@ -56,6 +69,9 @@ func ready(n *tree.Node) bool {
} }
func show(n *tree.Node, b bool) { func show(n *tree.Node, b bool) {
if tkbad(n) {
return
}
var tk *guiWidget var tk *guiWidget
tk = n.TK.(*guiWidget) tk = n.TK.(*guiWidget)
// tk = getTK(n) // tk = getTK(n)
@ -93,6 +109,9 @@ func enable(n *tree.Node, b bool) {
} }
func pad(n *tree.Node, b bool) { func pad(n *tree.Node, b bool) {
if tkbad(n) {
return
}
log.Warn("pad() on WidgetId =", n.WidgetId) log.Warn("pad() on WidgetId =", n.WidgetId)
t := n.TK.(*guiWidget) t := n.TK.(*guiWidget)
@ -126,14 +145,16 @@ func widgetDelete(n *tree.Node) {
if n.WidgetType == widget.Window { if n.WidgetType == widget.Window {
log.Warn("DESTROY uiWindow here") log.Warn("DESTROY uiWindow here")
log.Warn("NEED TO REMOVE n from parent.Children") log.Warn("NEED TO REMOVE n from parent.Children")
tk.uiWindow.Destroy() if tk.uiWindow != nil {
tk.uiWindow = nil tk.uiWindow.Destroy()
tk.uiWindow = nil
}
n.DeleteNode() n.DeleteNode()
} }
} }
func processAction(a *widget.Action) { func processAction(a *widget.Action) {
log.Log(INFO, "processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value) log.Warn("processAction() START a.ActionType =", a.ActionType, "a.Value", a.Value)
if a.ActionType == widget.ToolkitInit { if a.ActionType == widget.ToolkitInit {
Init() Init()
@ -163,7 +184,10 @@ func processAction(a *widget.Action) {
} }
if a.ActionType == widget.Add { if a.ActionType == widget.Add {
add(a) n := add(a)
show(n, n.State.Visable)
// pad(n, n.State.Pad)
// expand(n, a.State.Expand)
return return
} }
@ -195,6 +219,8 @@ func processAction(a *widget.Action) {
case widget.Disable: case widget.Disable:
log.Warn("andlabs got disable for", n.WidgetId, n.State.ProgName) log.Warn("andlabs got disable for", n.WidgetId, n.State.ProgName)
enable(n, false) enable(n, false)
case widget.Checked:
setChecked(n, a.State.Checked)
case widget.Get: case widget.Get:
setText(n, a) setText(n, a)
case widget.GetText: case widget.GetText:

24
add.go
View File

@ -2,16 +2,17 @@ package main
import ( import (
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
) )
func add(a *widget.Action) { func add(a *widget.Action) *tree.Node {
log.Warn("andlabs add()", a.WidgetId, a.State.ProgName) log.Warn("andlabs add()", a.WidgetId, a.State.ProgName)
if a.WidgetType == widget.Root { if a.WidgetType == widget.Root {
if me.treeRoot == nil { if me.treeRoot == nil {
me.treeRoot = me.myTree.AddNode(a) me.treeRoot = me.myTree.AddNode(a)
} }
return return me.treeRoot
} }
n := me.myTree.AddNode(a) n := me.myTree.AddNode(a)
@ -20,52 +21,35 @@ func add(a *widget.Action) {
case widget.Window: case widget.Window:
log.Warn("SPEEDY Add window", n.WidgetId, n.GetProgName()) log.Warn("SPEEDY Add window", n.WidgetId, n.GetProgName())
newWindow(p, n) newWindow(p, n)
return
case widget.Group: case widget.Group:
log.Warn("SPEEDY Add Group", n.WidgetId, n.GetProgName()) log.Warn("SPEEDY Add Group", n.WidgetId, n.GetProgName())
newGroup(p, n) newGroup(p, n)
return
case widget.Grid: case widget.Grid:
newGrid(n) newGrid(n)
return
case widget.Box: case widget.Box:
newBox(n) newBox(n)
return
/*
case widget.Tab:
newTab(n)
return
*/
case widget.Label: case widget.Label:
newLabel(p, n) newLabel(p, n)
return
case widget.Button: case widget.Button:
newButton(p, n) newButton(p, n)
return
case widget.Checkbox: case widget.Checkbox:
newCheckbox(p, n) newCheckbox(p, n)
return
case widget.Spinner: case widget.Spinner:
newSpinner(p, n) newSpinner(p, n)
return
case widget.Slider: case widget.Slider:
newSlider(p, n) newSlider(p, n)
return
case widget.Dropdown: case widget.Dropdown:
newDropdown(p, n) newDropdown(p, n)
return
case widget.Combobox: case widget.Combobox:
newCombobox(p, n) newCombobox(p, n)
return
case widget.Textbox: case widget.Textbox:
newTextbox(p, n) newTextbox(p, n)
return
/* /*
case widget.Image: case widget.Image:
newImage(p, n) newImage(p, n)
return
*/ */
default: default:
log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.State.ProgName) log.Log(ERROR, "add() error TODO: ", n.WidgetType, n.State.ProgName)
} }
return n
} }

View File

@ -3,6 +3,7 @@ package main
import ( import (
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"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"
@ -32,3 +33,12 @@ func newCheckbox(p *tree.Node, n *tree.Node) {
func (t *guiWidget) checked() bool { func (t *guiWidget) checked() bool {
return t.uiCheckbox.Checked() return t.uiCheckbox.Checked()
} }
func setChecked(n *tree.Node, b bool) {
if n.WidgetType != widget.Checkbox {
}
var tk *guiWidget
tk = n.TK.(*guiWidget)
tk.uiCheckbox.SetChecked(b)
}

View File

@ -6,12 +6,14 @@ import (
var defaultBehavior bool = true var defaultBehavior bool = true
/*
var bookshelf bool // do you want things arranged in the box like a bookshelf or a stack? var bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
var canvas bool // if set to true, the windows are a raw canvas var canvas bool // if set to true, the windows are a raw canvas
var menubar bool // for windows var menubar bool // for windows
var stretchy bool // expand things like buttons to the maximum size 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

12
go.mod Normal file
View File

@ -0,0 +1,12 @@
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.5
go.wit.com/widget v1.1.6
)
require go.wit.com/dev/davecgh/spew v1.1.4 // indirect

10
go.sum Normal file
View File

@ -0,0 +1,10 @@
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.5 h1:weWlg58OSPtEOOD40G1P5CJ5nNJIYfJ6vMuJb8sGzUE=
go.wit.com/toolkits/tree v0.0.5/go.mod h1:n4F2seonm1aYMml+YGOpCqWo0bkFwT/RH834J6f5/iE=
go.wit.com/widget v1.1.6 h1:av2miF5vlohMfARA/QGPTPfgW/ADup1c+oeAOKgroPY=
go.wit.com/widget v1.1.6/go.mod h1:I8tnD3x3ECbB/CRNnLCdC+uoyk7rK0AEkzK1bQYSqoQ=

View File

@ -36,6 +36,7 @@ func queueMain(currentA widget.Action) {
// it's easier to code it this way however // it's easier to code it this way however
// also, if it dies here, it get's caught // also, if it dies here, it get's caught
// usually, this is where it dies // usually, this is where it dies
log.Warn("about to send action into the andlabs ui.QueueMain()")
ui.QueueMain(func() { ui.QueueMain(func() {
processAction(&currentA) processAction(&currentA)
}) })
@ -57,6 +58,10 @@ func guiMain() {
// a better way would be to spawn ui.Main on the first actual window // a better way would be to spawn ui.Main on the first actual window
// that is supposed to be displayed // that is supposed to be displayed
placeholderUI() placeholderUI()
// if nothing is working, run this instead to make
// sure you have something
// demoUI()
}) })
} }

View File

@ -78,7 +78,7 @@ func place(p *tree.Node, n *tree.Node) bool {
if n.WidgetType == widget.Textbox { if n.WidgetType == widget.Textbox {
ptk.uiBox.Append(tk.uiControl, true) ptk.uiBox.Append(tk.uiControl, true)
} else { } else {
ptk.uiBox.Append(tk.uiControl, stretchy) ptk.uiBox.Append(tk.uiControl, n.State.Expand)
} }
return true return true
case widget.Tab: case widget.Tab:
@ -104,7 +104,7 @@ func place(p *tree.Node, n *tree.Node) bool {
if n.WidgetType == widget.Textbox { if n.WidgetType == widget.Textbox {
ptk.uiBox.Append(tk.uiControl, true) ptk.uiBox.Append(tk.uiControl, true)
} else { } else {
ptk.uiBox.Append(tk.uiControl, stretchy) ptk.uiBox.Append(tk.uiControl, n.State.Expand)
} }
ptk.boxC += 1 ptk.boxC += 1
return true return true

2
tab.go
View File

@ -88,6 +88,7 @@ func rawTab(w *ui.Window, name string) *guiWidget {
return &newt return &newt
} }
/*
func (t *guiWidget) appendTab(name string) *guiWidget { func (t *guiWidget) appendTab(name string) *guiWidget {
var newT guiWidget var newT guiWidget
log.Log(TOOLKIT, "appendTab() ADD", name) log.Log(TOOLKIT, "appendTab() ADD", name)
@ -116,3 +117,4 @@ func (t *guiWidget) appendTab(name string) *guiWidget {
newT.uiBox = hbox newT.uiBox = hbox
return &newT return &newT
} }
*/

View File

@ -99,5 +99,5 @@ func demoUI() {
}) })
// this is messed up. // this is messed up.
// mainWindow.Show() mainWindow.Show()
} }

View File

@ -19,13 +19,14 @@ func newWindow(p, n *tree.Node) {
var newt *guiWidget var newt *guiWidget
newt = new(guiWidget) newt = new(guiWidget)
// menubar bool is if the OS defined border on the window should be used // bool == false is if the OS defined border on the window should be used
win := ui.NewWindow(n.GetProgName(), 640, 480, menubar) win := ui.NewWindow(n.GetProgName(), 640, 480, n.State.Borderless)
win.SetBorderless(canvas) win.SetBorderless(n.State.Borderless)
win.SetMargined(margin) win.SetMargined(n.State.Pad)
win.OnClosing(func(*ui.Window) bool { win.OnClosing(func(*ui.Window) bool {
// show(n, false) // show(n, false)
me.myTree.SendWindowCloseEvent(n) me.myTree.SendWindowCloseEvent(n)
n.DeleteNode()
return true return true
}) })
newt.uiWindow = win newt.uiWindow = win