andlabs: the binary tree limps along again

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-08 11:06:50 -05:00
parent 51b109a976
commit 85c2fb8d70
24 changed files with 83 additions and 69 deletions

View File

@ -134,6 +134,10 @@ Creates a window helpful for debugging this package
TODO: add logic to just load the 1st 'most common' gui toolkit
and allow the 'go-arg' command line args to override the defaults
### func [LoadPlugin](/main.go#L176)
`func LoadPlugin(name string) bool`
### func [LoadToolkit](/plugin.go#L68)
`func LoadToolkit(name string) *aplug`
@ -203,6 +207,10 @@ var Config GuiConfig
The Node is a binary tree. This is how all GUI elements are stored
simply the name and the size of whatever GUI element exists
#### func [New](/common.go#L12)
`func New() *Node`
#### func [NewWindow](/window.go#L13)
`func NewWindow() *Node`
@ -255,10 +263,6 @@ You get a window
`func Start() *Node`
#### func [StartS](/main.go#L181)
`func StartS(name string) *Node`
### type [Symbol](/plugin.go#L16)
`type Symbol any`

View File

@ -3,7 +3,7 @@ package gui
import "git.wit.org/wit/gui/toolkit"
func (n *Node) NewButton(name string, custom func()) *Node {
newNode := n.New(name, toolkit.Button, custom)
newNode := n.newNode(name, toolkit.Button, custom)
var a toolkit.Action
a.Name = name

View File

@ -7,7 +7,7 @@ func (n *Node) Checked() bool {
}
func (n *Node) NewCheckbox(name string) *Node {
newNode := n.New(name, toolkit.Checkbox, nil)
newNode := n.newNode(name, toolkit.Checkbox, nil)
var a toolkit.Action
a.ActionType = toolkit.Add

View File

@ -71,12 +71,12 @@ func buttonWindow() {
g.NewButton("Load 'gocui'", func () {
// this set the xterm and mate-terminal window title. maybe works generally?
fmt.Println("\033]0;" + title + "blah \007")
gui.StartS("gocui")
gui.LoadPlugin("gocui")
gui.Redraw("gocui")
})
g.NewButton("Load 'andlabs'", func () {
gui.StartS("andlabs")
gui.LoadPlugin("andlabs")
})
g.NewButton("NewButton(more)", func () {

View File

@ -9,28 +9,44 @@ import (
// functions for handling text related GUI elements
func (n *Node) Show() {
func New() *Node {
if (Config.rootNode == nil) {
log(logError, "New() ERROR: rootNode is nil")
}
// There should only be one of these per application
// This is due to restrictions by being cross platform
// some toolkit's on some operating systems don't support more than one
// Keep things simple. Do the default expected thing whenever possible
return startS("gocui")
}
func (n *Node) Show() *Node {
var a toolkit.Action
a.ActionType = toolkit.Show
newaction(&a, n, nil)
return n
}
func (n *Node) Hide() {
func (n *Node) Hide() *Node {
var a toolkit.Action
a.ActionType = toolkit.Hide
newaction(&a, n, nil)
return n
}
func (n *Node) Enable() {
func (n *Node) Enable() *Node {
var a toolkit.Action
a.ActionType = toolkit.Enable
newaction(&a, n, nil)
return n
}
func (n *Node) Disable() {
func (n *Node) Disable() *Node {
var a toolkit.Action
a.ActionType = toolkit.Disable
newaction(&a, n, nil)
return n
}
func (n *Node) Add(str string) {
@ -186,7 +202,7 @@ func (n *Node) Unpad() *Node {
// is this better?
// yes, this is better. it allows Internationalization very easily
// me.window = myGui.New2().Window("DNS and IPv6 Control Panel").Standard()
// myFunnyWindow = myGui.New().Window("Hello").Standard().SetText("Hola")
// myFunnyWindow = myGui.NewWindow("Hello").Standard().SetText("Hola")
func (n *Node) New2() *Node {
log(debugNow, "New2() Start")

View File

@ -303,13 +303,7 @@ func (n *Node) debugAddWidgetButton() {
a.AddText(name + " foo")
a.AddText(name + " bar")
case "Label":
newNode := activeWidget.New(name, toolkit.Label, nil)
var a toolkit.Action
a.ActionType = toolkit.Add
newaction(&a, newNode, activeWidget)
// return newNode
// activeWidget.NewLabel(name)
activeWidget.NewLabel(name)
case "Textbox":
activeWidget.NewTextbox(name)
case "Slider":

View File

@ -94,7 +94,7 @@ func (n *Node) DebugTab(title string) *Node {
})
g2.NewButton("load plugin 'gocui'", func () {
StartS("gocui")
startS("gocui")
})
g2.NewButton("Redraw(gocui)", func () {

View File

@ -20,7 +20,7 @@ func (n *Node) SetDropdownName(name string) {
}
func (n *Node) NewDropdown(name string) *Node {
newNode := n.New(name, toolkit.Dropdown, nil)
newNode := n.newNode(name, toolkit.Dropdown, nil)
var a toolkit.Action
a.ActionType = toolkit.Add
@ -33,7 +33,7 @@ func (n *Node) NewDropdown(name string) *Node {
}
func (n *Node) NewCombobox(name string) *Node {
newNode := n.New(name, toolkit.Combobox, nil)
newNode := n.newNode(name, toolkit.Combobox, nil)
var a toolkit.Action
a.ActionType = toolkit.Add

View File

@ -17,7 +17,7 @@ import (
// -----------------------------
func (n *Node) NewGrid(name string, w int, h int) *Node {
newNode := n.New(name, toolkit.Grid, func() {
newNode := n.newNode(name, toolkit.Grid, func() {
log(debugChange, "click() NewGrid not defined =", name)
})
@ -39,7 +39,7 @@ func (n *Node) NewGrid(name string, w int, h int) *Node {
}
func (n *Node) NewBox(name string, b bool) *Node {
newNode := n.New(name, toolkit.Box, nil)
newNode := n.newNode(name, toolkit.Box, nil)
newNode.B = b
var a toolkit.Action

View File

@ -9,7 +9,7 @@ import (
// pre-canned andlabs/ui gtk,macos,windows thing
func (n *Node) NewGroup(name string) *Node {
var newNode *Node
newNode = n.New(name, toolkit.Group, nil)
newNode = n.newNode(name, toolkit.Group, nil)
var a toolkit.Action
a.ActionType = toolkit.Add

View File

@ -6,7 +6,7 @@ import (
func (n *Node) NewImage(name string) *Node {
var newNode *Node
newNode = n.New(name, toolkit.Image, nil)
newNode = n.newNode(name, toolkit.Image, nil)
var a toolkit.Action
a.ActionType = toolkit.Add

View File

@ -5,7 +5,7 @@ import (
)
func (n *Node) NewLabel(text string) *Node {
newNode := n.New(text, toolkit.Label, nil)
newNode := n.newNode(text, toolkit.Label, nil)
var a toolkit.Action
a.ActionType = toolkit.Add

View File

@ -36,7 +36,7 @@ func init() {
Config.rootNode.WidgetType = toolkit.Root
// used to pass debugging flags to the toolkit plugins
Config.flag = Config.rootNode.New("flag", 0, nil)
Config.flag = Config.rootNode.newNode("flag", 0, nil)
Config.flag.WidgetType = toolkit.Flag
Config.guiChan = make(chan toolkit.Action)
@ -173,12 +173,12 @@ func (n *Node) doUserEvent(a toolkit.Action) {
}
}
func (n *Node) LoadPlugin(name string) bool {
StartS(name)
func LoadPlugin(name string) bool {
startS(name)
return true
}
func StartS(name string) *Node {
func startS(name string) *Node {
log(logInfo, "Start() Main(f) for name =", name)
aplug := LoadToolkit(name)
if (aplug == nil) {

View File

@ -5,7 +5,7 @@ import "git.wit.org/wit/gui/toolkit"
/*
generic function to create a new node on the binary tree
*/
func (n *Node) New(title string, t toolkit.WidgetType, custom func()) *Node {
func (n *Node) newNode(title string, t toolkit.WidgetType, custom func()) *Node {
var newN *Node
newN = addNode(title)

View File

@ -5,7 +5,7 @@ import (
)
func (n *Node) NewSlider(name string, x int, y int) *Node {
newNode := n.New(name, toolkit.Slider, func() {
newNode := n.newNode(name, toolkit.Slider, func() {
log(debugGui, "even newer clicker() name in NewSlider name =", name)
})

View File

@ -5,7 +5,7 @@ import (
)
func (n *Node) NewSpinner(name string, x int, y int) *Node {
newNode := n.New(name, toolkit.Spinner, func() {
newNode := n.newNode(name, toolkit.Spinner, func() {
log(debugChange, "default NewSpinner() change", name)
})

2
tab.go
View File

@ -8,7 +8,7 @@ import (
// the 'tab' as a child
func (n *Node) NewTab(text string) *Node {
newNode := n.New(text, toolkit.Tab, nil)
newNode := n.newNode(text, toolkit.Tab, nil)
var a toolkit.Action
a.ActionType = toolkit.Add

View File

@ -5,7 +5,7 @@ import (
)
func (n *Node) NewTextbox(name string) *Node {
newNode := n.New(name, toolkit.Textbox, func() {
newNode := n.newNode(name, toolkit.Textbox, func() {
log(debugGui, "NewTextbox changed =", name)
})

View File

@ -47,7 +47,10 @@ func add(a *toolkit.Action) {
doWindow(a)
return
case toolkit.Tab:
newTab(a)
log(debugError, "add() CAME AT THIS FROM add() =", a.Name)
log(debugError, "add() CAME AT THIS FROM add() =", a.Name)
log(debugError, "add() CAME AT THIS FROM add() =", a.Name)
newTab(*a)
return
case toolkit.Label:
newLabel(a)

View File

@ -26,20 +26,15 @@ func catchActionChannel() {
if (a.WidgetType == toolkit.Window) {
log(logNow, "makeCallback() WINDOW START")
go ui.Main( func() {
log(logNow, "ui.Main() WINDOW START")
rawAction(&a)
log(logNow, "ui.Main() WINDOW START DOING NOTHING")
newWindow(&a)
log(logNow, "ui.Main() WINDOW END")
})
sleep(.5)
log(logNow, "makeCallback() WINDOW END")
} else {
log(logNow, "makeCallback() STUFF")
rawAction(&a)
/*
Queue( func() {
rawAction(&a)
})
*/
rawAction(a)
log(logNow, "makeCallback() STUFF END")
}
// sleep(.1)

View File

@ -22,7 +22,8 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) {
log(debugPlugin, "Send() goodbye. not used anymore")
}
func Action(a *toolkit.Action) {
func oldAction(a *toolkit.Action) {
log(logNow, "Action() START")
if (a == nil) {
log(debugPlugin, "Action = nil")
@ -40,34 +41,35 @@ func Action(a *toolkit.Action) {
log(logNow, "Action() END")
}
func rawAction(a *toolkit.Action) {
func rawAction(a toolkit.Action) {
log(debugAction, "rawAction() START a.ActionType =", a.ActionType)
log(debugAction, "rawAction() START a.S =", a.S)
log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case toolkit.Flag:
flag(a)
flag(&a)
return
}
switch a.ActionType {
case toolkit.Add:
add(a)
add(&a)
case toolkit.Show:
a.B = true
show(a)
show(&a)
case toolkit.Hide:
a.B = false
show(a)
show(&a)
case toolkit.Enable:
a.B = true
enable(a)
enable(&a)
case toolkit.Disable:
a.B = false
enable(a)
enable(&a)
case toolkit.Get:
setText(a)
setText(&a)
case toolkit.GetText:
switch a.WidgetType {
case toolkit.Textbox:
@ -75,24 +77,24 @@ func rawAction(a *toolkit.Action) {
a.S = t.s
}
case toolkit.Set:
setText(a)
setText(&a)
case toolkit.SetText:
setText(a)
setText(&a)
case toolkit.AddText:
setText(a)
setText(&a)
case toolkit.Margin:
pad(a)
pad(&a)
case toolkit.Unmargin:
pad(a)
pad(&a)
case toolkit.Pad:
pad(a)
pad(&a)
case toolkit.Unpad:
pad(a)
pad(&a)
case toolkit.Delete:
uiDelete(a)
uiDelete(&a)
case toolkit.Move:
log(debugNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
move(a)
move(&a)
default:
log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
}

View File

@ -19,7 +19,7 @@ import (
once there is one. If you send a Window here, it will replace
any existing tabs rather than adding a new one
*/
func (t *andlabsT) newTab(a *toolkit.Action) {
func (t *andlabsT) newTab(a toolkit.Action) {
// var w *ui.Window
var newt *andlabsT
@ -118,7 +118,7 @@ func (t *andlabsT) appendTab(name string) *andlabsT {
return &newT
}
func newTab(a *toolkit.Action) {
func newTab(a toolkit.Action) {
// w := a.Widget
log(debugToolkit, "newTab()", a.ParentId)

View File

@ -30,12 +30,12 @@ func newWindow(a *toolkit.Action) {
newt.doUserEvent()
return true
})
win.Show()
newt.uiWindow = win
newt.uiControl = win
newt.Name = a.Name
andlabs[a.WidgetId] = newt
win.Show()
return
}

View File

@ -32,7 +32,7 @@ func NewWindow() *Node {
}
}
// Windows are created off of the master node of the Binary Tree
newNode = Config.rootNode.New(Config.Title, toolkit.Window, custom)
newNode = Config.rootNode.newNode(Config.Title, toolkit.Window, custom)
log(logInfo, "NewWindow()", Config.Title)
@ -53,7 +53,7 @@ func (n *Node) NewWindow2(title string) *Node {
var newNode *Node
// Windows are created off of the master node of the Binary Tree
newNode = n.New(Config.Title, toolkit.Window, StandardExit)
newNode = n.newNode(Config.Title, toolkit.Window, StandardExit)
log(logInfo, "NewWindow()", Config.Title)