Destroy window and node from binary tree

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-15 16:11:40 -06:00
parent 708ea66198
commit 29c39d7a1c
27 changed files with 137 additions and 72 deletions

View File

@ -2,7 +2,7 @@ package main
import (
"strconv"
"github.com/andlabs/ui"
"go.wit.com/dev/andlabs/ui"
"go.wit.com/log"
"go.wit.com/gui/widget"
@ -55,13 +55,13 @@ func (n *node) pad(b bool) {
}
switch n.WidgetType {
case widget.Group:
t.uiGroup.SetMargined(b)
case widget.Tab:
tabSetMargined(t.uiTab, b)
case widget.Window:
t.uiWindow.SetMargined(b)
t.uiWindow.SetBorderless(b)
case widget.Tab:
tabSetMargined(t.uiTab, b)
case widget.Group:
t.uiGroup.SetMargined(b)
case widget.Grid:
t.uiGrid.SetPadded(b)
case widget.Box:
@ -101,13 +101,32 @@ func (n *node) Delete() {
p := n.parent
log.Log(NOW, "uiDelete()", n.WidgetId, "to", p.WidgetId)
if n.WidgetType == widget.Window {
log.Warn("DESTROY uiWindow here")
log.Warn("NEED TO REMOVE n from parent.Children")
n.tk.uiWindow.Destroy()
n.tk.uiWindow = nil
for i, child := range p.children {
log.Warn("parent has child:", i, child.WidgetId, child.progname)
if n == child {
log.Warn("Found child ==", i, child.WidgetId, child.progname)
log.Warn("Found n ==", i, n.WidgetId, n.progname)
p.children = append(p.children[:i], p.children[i+1:]...)
}
// t.uiWindow.SetBorderless(false)
}
for i, child := range p.children {
log.Warn("parent now has child:", i, child.WidgetId, child.progname)
}
return
}
switch p.WidgetType {
case widget.Group:
// tParent.uiGroup.SetMargined(true)
case widget.Tab:
// tabSetMargined(tParent.uiTab, true)
case widget.Window:
// t.uiWindow.SetBorderless(false)
case widget.Grid:
// t.uiGrid.SetPadded(true)
case widget.Box:

View File

@ -18,7 +18,7 @@ func (n *node) addText(a *widget.Action) {
case widget.Dropdown:
n.addDropdownName(getString(a.Value))
case widget.Combobox:
t.addComboboxName(getString(a.Value))
n.addComboboxName(getString(a.Value))
default:
log.Log(ERROR, "plugin Send() Don't know how to addText on", n.WidgetType, "yet", a.ActionType)
}

View File

@ -3,8 +3,8 @@ package main
import (
"go.wit.com/gui/widget"
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
// make new Box here
@ -17,7 +17,7 @@ func (p *node) newBox(n *node) {
} else {
box = ui.NewVerticalBox()
}
box.SetPadded(padded)
box.SetPadded(true)
newt.uiBox = box
newt.uiControl = box

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
func (p *node) newButton(n *node) {

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
func (p *node) newCheckbox(n *node) {

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/gui/widget"
@ -28,24 +28,38 @@ func (p *node) newCombobox(n *node) {
n.tk = newt
p.place(n)
// add the initial dropdown entries
// add the initial combobox entries
for i, s := range n.strings {
log.Warn("add dropdown entries on create", i, s)
n.addDropdownName(s)
log.Warn("add combobox entries on create", n.progname, i, s)
n.addComboboxName(s)
}
cur := widget.GetString(n.value)
n.tk.addComboboxName(cur)
log.Warn("add combobox: TODO: set default value on create", n.progname, cur)
n.setComboboxName(cur)
}
func (t *guiWidget) addComboboxName(title string) {
t.uiEditableCombobox.Append(title)
if (t.val == nil) {
func (n *node) addComboboxName(s string) {
if ! n.ready() { return }
log.Log(INFO, "addComboboxName()", n.WidgetId, "add:", s)
n.tk.uiEditableCombobox.Append(s)
if (n.tk.val == nil) {
log.Log(INFO, "make map didn't work")
return
}
t.val[t.c] = title
n.tk.val[n.tk.c] = s
// If this is the first menu added, set the dropdown to it
// if (t.c == 0) {
// }
t.c = t.c + 1
if (n.tk.c == 0) {
log.Log(INFO, "THIS IS THE FIRST combobox", s)
n.tk.uiEditableCombobox.SetText(s)
}
n.tk.c = n.tk.c + 1
}
func (n *node) setComboboxName(s string) bool {
if ! n.ready() { return false}
log.Log(INFO, "SetComboboxName()", n.WidgetId, ",", s)
n.tk.uiEditableCombobox.SetText(s)
return false
}

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"
)

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"
"go.wit.com/gui/widget"
@ -35,6 +35,7 @@ func (p *node) newDropdown(n *node) {
n.tk = newt
p.place(n)
if n.strings == nil {return}
// add the initial dropdown entries
for i, s := range n.strings {
log.Warn("add dropdown: add entries on create", n.progname, i, s)
@ -45,7 +46,6 @@ func (p *node) newDropdown(n *node) {
n.setDropdownName(cur)
}
func (n *node) SetDropdownInt(i int) {
if ! n.ready() { return }
n.tk.uiCombobox.SetSelected(i)

View File

@ -3,9 +3,9 @@ module go.wit.com/gui/toolkits/andlabs
go 1.21.4
require (
github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e
go.wit.com/dev/andlabs/ui v0.0.1
go.wit.com/gui/widget v1.1.3
go.wit.com/log v0.5.3
go.wit.com/log v0.5.4
)
require go.wit.com/dev/davecgh/spew v1.1.3 // indirect
require go.wit.com/dev/davecgh/spew v1.1.4 // indirect

View File

@ -1,8 +1,12 @@
github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e h1:wSQCJiig/QkoUnpvelSPbLiZNWvh2yMqQTQvIQqSUkU=
github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:5G2EjwzgZUPnnReoKvPWVneT8APYbyKkihDVAHUi0II=
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.3 h1:hqnB5qsPgC2cLZaJXqQJspQ5n/Ugry9kyL3tLk0hVzQ=
go.wit.com/dev/davecgh/spew v1.1.3/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
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/gui/widget v1.1.3 h1:GvLzGSOF9tfmoh6HNbFdN+NSlBo2qeS/Ba2TnQQ1A1U=
go.wit.com/gui/widget v1.1.3/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E=
go.wit.com/log v0.5.3 h1:/zHkniOPusPEuX1R401rMny9uwSO/nSU/QOMx6qoEnE=
go.wit.com/log v0.5.3/go.mod h1:LzIzVxc2xJQxWQBtV9VbV605P4TOxmYDCl+BZF38yGE=
go.wit.com/log v0.5.4 h1:vijLRPTUgChb8J5tx/7Uma/lGTUxeSXosFbheAmL914=
go.wit.com/log v0.5.4/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
// Grid numbering by (X,Y)
@ -18,6 +18,7 @@ func (p *node) newGrid(n *node) {
c := ui.NewGrid()
newt.uiGrid = c
newt.uiControl = c
c.SetPadded(true)
n.tk = newt
p.place(n)

View File

@ -1,15 +1,15 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
func (p *node) newGroup(n *node) {
newt := new(guiWidget)
g := ui.NewGroup(getString(n.value))
g.SetMargined(margin)
g.SetMargined(true)
newt.uiGroup = g
newt.uiControl = g

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
// make new Image using andlabs/ui

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
func (p *node) newLabel(n *node) {

View File

@ -5,15 +5,26 @@ import (
"go.wit.com/log"
"go.wit.com/gui/widget"
"github.com/andlabs/ui"
"go.wit.com/dev/andlabs/ui"
// the _ means we only need this for the init()
_ "github.com/andlabs/ui/winmanifest"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
var uiMainUndef bool = true
var uiMain sync.Once
var muAction sync.Mutex
func queueMain(currentA widget.Action) {
defer func() {
if r := recover(); r != nil {
log.Warn("YAHOOOO Recovered in main application:", r)
}
}()
ui.QueueMain( func() {
rawAction(&currentA)
})
}
func catchActionChannel() {
log.Log(INFO, "catchActionChannel() START")
for {
@ -25,14 +36,25 @@ func catchActionChannel() {
muAction.Lock()
// TODO ui.QueueMain(f)
// TODO ui.QueueMain( func() {rawAction(a)} )
ui.QueueMain( func() {rawAction(&a)} )
// rawAction(a)
queueMain(a)
muAction.Unlock()
log.Log(INFO, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
}
}
}
func guiMain() {
defer func() {
if r := recover(); r != nil {
log.Warn("YAHOOOO Recovered in main application:", r)
}
}()
ui.Main(func() {
demoUI()
})
}
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func init() {
log.Log(INFO, "Init() START")
@ -41,13 +63,10 @@ func init() {
// log.Log(INFO, "init() Setting defaultBehavior = true")
setDefaultBehavior(true)
// TODO: this is messed up. run ui.Main() from the first add? Initialize it with an empty thing first?
// fake out the OS toolkit by making a fake window. This is probably needed for macos & windows
// actually, this probably breaks the macos build
go ui.Main(func() {
demoUI()
})
go guiMain()
// andlabs = make(map[int]*andlabsT)
pluginChan = make(chan widget.Action, 1)

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
func (p *node) newSlider(n *node) {

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
func (p *node) newSpinner(n *node) {

View File

@ -1,7 +1,7 @@
package main
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "go.wit.com/dev/andlabs/ui"
import _ "go.wit.com/dev/andlabs/ui/winmanifest"
// var andlabs map[int]*andlabsT
// var callback func(int) bool

View File

@ -4,8 +4,8 @@ import (
"go.wit.com/log"
"go.wit.com/gui/widget"
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
/*

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
)
func (p *node) newTextbox(n *node) {

View File

@ -1,7 +1,7 @@
package main
import (
"github.com/andlabs/ui"
"go.wit.com/dev/andlabs/ui"
)
// Example showing how to update the UI using the QueueMain function

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/andlabs/ui"
_ "github.com/andlabs/ui/winmanifest"
"go.wit.com/dev/andlabs/ui"
_ "go.wit.com/dev/andlabs/ui/winmanifest"
"go.wit.com/log"
)

View File

@ -5,7 +5,7 @@ go 1.21.4
require (
github.com/awesome-gocui/gocui v1.1.0
go.wit.com/gui/widget v1.1.3
go.wit.com/log v0.5.3
go.wit.com/log v0.5.4
)
require (
@ -14,7 +14,7 @@ require (
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/rivo/uniseg v0.1.0 // indirect
go.wit.com/dev/davecgh/spew v1.1.3 // indirect
go.wit.com/dev/davecgh/spew v1.1.4 // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
golang.org/x/text v0.3.3 // indirect

View File

@ -12,10 +12,14 @@ github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
go.wit.com/dev/davecgh/spew v1.1.3 h1:hqnB5qsPgC2cLZaJXqQJspQ5n/Ugry9kyL3tLk0hVzQ=
go.wit.com/dev/davecgh/spew v1.1.3/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
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/gui/widget v1.1.3 h1:GvLzGSOF9tfmoh6HNbFdN+NSlBo2qeS/Ba2TnQQ1A1U=
go.wit.com/gui/widget v1.1.3/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E=
go.wit.com/log v0.5.3 h1:/zHkniOPusPEuX1R401rMny9uwSO/nSU/QOMx6qoEnE=
go.wit.com/log v0.5.3/go.mod h1:LzIzVxc2xJQxWQBtV9VbV605P4TOxmYDCl+BZF38yGE=
go.wit.com/log v0.5.4 h1:vijLRPTUgChb8J5tx/7Uma/lGTUxeSXosFbheAmL914=
go.wit.com/log v0.5.4/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=

View File

@ -4,7 +4,7 @@ go 1.21.4
require (
go.wit.com/gui/widget v1.1.3
go.wit.com/log v0.5.3
go.wit.com/log v0.5.4
)
require go.wit.com/dev/davecgh/spew v1.1.3 // indirect
require go.wit.com/dev/davecgh/spew v1.1.4 // indirect

View File

@ -1,6 +1,10 @@
go.wit.com/dev/davecgh/spew v1.1.3 h1:hqnB5qsPgC2cLZaJXqQJspQ5n/Ugry9kyL3tLk0hVzQ=
go.wit.com/dev/davecgh/spew v1.1.3/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA=
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/gui/widget v1.1.3 h1:GvLzGSOF9tfmoh6HNbFdN+NSlBo2qeS/Ba2TnQQ1A1U=
go.wit.com/gui/widget v1.1.3/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E=
go.wit.com/log v0.5.3 h1:/zHkniOPusPEuX1R401rMny9uwSO/nSU/QOMx6qoEnE=
go.wit.com/log v0.5.3/go.mod h1:LzIzVxc2xJQxWQBtV9VbV605P4TOxmYDCl+BZF38yGE=
go.wit.com/log v0.5.4 h1:vijLRPTUgChb8J5tx/7Uma/lGTUxeSXosFbheAmL914=
go.wit.com/log v0.5.4/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo=