correctly deprecate *widget to plugins

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-06 20:50:00 -05:00
parent 45d43c3616
commit 57283a4da7
12 changed files with 31 additions and 87 deletions

View File

@ -9,8 +9,6 @@ func (n *Node) NewButton(name string, custom func()) *Node {
a.Name = name a.Name = name
a.Text = name a.Text = name
a.ActionType = toolkit.Add a.ActionType = toolkit.Add
// deprecate this once andlabs is refactored
a.Callback = callback
newaction(&a, newNode, n) newaction(&a, newNode, n)
return newNode return newNode

View File

@ -251,21 +251,15 @@ func loadfile(filename string) *plugin.Plugin {
return plug return plug
} }
// Sends a widget and what to do with it to the plugin // 2023/04/06 Queue() is also being used and channels are being used. memcopy() only
// parent = n, child = c
// THIS COPIES THE WIDGET STRUCT 2023/03/16 as it's not crashing. Queue() is also being used
// never mind that comment. no it doesn't
func newaction(a *toolkit.Action, n *Node, where *Node) { func newaction(a *toolkit.Action, n *Node, where *Node) {
if (n != nil) { if (n != nil) {
a.Widget = &n.widget
a.WidgetId = n.id a.WidgetId = n.id
a.WidgetType = n.widget.Type a.WidgetType = n.widget.Type
a.ActionType = a.ActionType a.ActionType = a.ActionType
} }
// action(&a, newNode, n)
// newaction(&a, newNode, n)
// TODO: redo this grid logic
if (where != nil) { if (where != nil) {
log(debugGui, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY) log(debugGui, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY)
a.ParentId = where.id a.ParentId = where.id

View File

@ -8,9 +8,7 @@ import (
func (t *andlabsT) newCheckbox(a *toolkit.Action) *andlabsT { func (t *andlabsT) newCheckbox(a *toolkit.Action) *andlabsT {
var newt andlabsT var newt andlabsT
w := a.Widget
log(debugToolkit, "newCheckbox()", a.Name, a.WidgetType) log(debugToolkit, "newCheckbox()", a.Name, a.WidgetType)
newt.tw = w
newt.WidgetType = a.WidgetType newt.WidgetType = a.WidgetType
newt.wId = a.WidgetId newt.wId = a.WidgetId
newt.Name = a.Name newt.Name = a.Name
@ -21,7 +19,7 @@ func (t *andlabsT) newCheckbox(a *toolkit.Action) *andlabsT {
newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
newt.b = newt.checked() newt.b = newt.checked()
log(debugChange, "val =", newt.tw.B) log(debugChange, "val =", newt.b)
newt.doUserEvent() newt.doUserEvent()
}) })

View File

@ -1,6 +1,6 @@
package main package main
import "git.wit.org/wit/gui/toolkit" // import "git.wit.org/wit/gui/toolkit"
var defaultBehavior bool = true var defaultBehavior bool = true
@ -81,26 +81,6 @@ func (t *andlabsT) Dump(b bool) {
if (t.uiCheckbox != nil) { if (t.uiCheckbox != nil) {
log(b, "uiCheckbox =", t.uiCheckbox) log(b, "uiCheckbox =", t.uiCheckbox)
} }
widgetDump(b, t.tw)
}
func widgetDump(b bool, w *toolkit.Widget) {
if (w == nil) {
log(b, "widget = nil")
return
}
/*
log(b, "widget.Name =", w.Name)
log(b, "widget.Type =", w.Type)
log(b, "widget.Custom =", w.Custom)
log(b, "widget.B =", w.B)
log(b, "widget.I =", w.I)
log(b, "widget.Width =", w.Width)
log(b, "widget.Height =", w.Height)
log(b, "widget.X =", w.X)
log(b, "widget.Y =", w.Y)
*/
} }
/* /*

View File

@ -8,10 +8,8 @@ import (
func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT { func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
var newt andlabsT var newt andlabsT
w := a.Widget
log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Name) log(debugToolkit, "gui.Toolbox.newDropdown() START", a.Name)
newt.tw = w
newt.WidgetType = a.WidgetType newt.WidgetType = a.WidgetType
newt.wId = a.WidgetId newt.wId = a.WidgetId
s := ui.NewCombobox() s := ui.NewCombobox()
@ -35,7 +33,7 @@ func (t *andlabsT) newDropdown(a *toolkit.Action) *andlabsT {
return &newt return &newt
} }
func (t *andlabsT) AddDropdownName(title string) { func (t *andlabsT) addDropdownName(title string) {
t.uiCombobox.Append(title) t.uiCombobox.Append(title)
if (t.val == nil) { if (t.val == nil) {
log(debugToolkit, "make map didn't work") log(debugToolkit, "make map didn't work")
@ -64,7 +62,7 @@ func AddDropdownName(a *toolkit.Action) {
listMap(debugToolkit) listMap(debugToolkit)
return return
} }
t.AddDropdownName(a.S) t.addDropdownName(a.S)
} }
func SetDropdownName(a *toolkit.Action, s string) { func SetDropdownName(a *toolkit.Action, s string) {
@ -78,7 +76,7 @@ func SetDropdownName(a *toolkit.Action, s string) {
} }
t.SetDropdown(1) t.SetDropdown(1)
// TODO: send back to wit/gui goroutine with the chan // TODO: send back to wit/gui goroutine with the chan
t.tw.S = s t.s = s
} }
func newDropdown(a *toolkit.Action) { func newDropdown(a *toolkit.Action) {

View File

@ -21,7 +21,6 @@ func newGrid(a *toolkit.Action) {
c := ui.NewGrid() c := ui.NewGrid()
newt.uiGrid = c newt.uiGrid = c
newt.uiControl = c newt.uiControl = c
newt.tw = a.Widget
newt.WidgetType = toolkit.Grid newt.WidgetType = toolkit.Grid
newt.gridX = 0 newt.gridX = 0
newt.gridY = 0 newt.gridY = 0

View File

@ -31,15 +31,6 @@ func Action(a *toolkit.Action) {
rawAction(a) rawAction(a)
} }
/*
if (callback == nil) {
if (a.Callback != nil) {
log(debugNow, "setting Callback", a.Callback)
callback = a.Callback
}
}
*/
// f() // f()
Queue(f) Queue(f)
} }
@ -48,7 +39,6 @@ func rawAction(a *toolkit.Action) {
log(debugAction, "Action() START a.ActionType =", a.ActionType) log(debugAction, "Action() START a.ActionType =", a.ActionType)
log(debugAction, "Action() START a.S =", a.S) log(debugAction, "Action() START a.S =", a.S)
log(debugAction, "Action() START a.Widget =", a.Widget)
log(logInfo, "Action() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId) log(logInfo, "Action() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType { switch a.WidgetType {
@ -61,21 +51,21 @@ func rawAction(a *toolkit.Action) {
case toolkit.Add: case toolkit.Add:
add(a) add(a)
case toolkit.Show: case toolkit.Show:
a.Widget.B = true a.B = true
show(a) show(a)
case toolkit.Hide: case toolkit.Hide:
a.Widget.B = false a.B = false
show(a) show(a)
case toolkit.Enable: case toolkit.Enable:
a.Widget.B = true a.B = true
enable(a) enable(a)
case toolkit.Disable: case toolkit.Disable:
a.Widget.B = false a.B = false
enable(a) enable(a)
case toolkit.Get: case toolkit.Get:
setText(a) setText(a)
case toolkit.GetText: case toolkit.GetText:
switch a.Widget.Type { switch a.WidgetType {
case toolkit.Textbox: case toolkit.Textbox:
t := andlabs[a.WidgetId] t := andlabs[a.WidgetId]
a.S = t.s a.S = t.s
@ -97,12 +87,12 @@ func rawAction(a *toolkit.Action) {
case toolkit.Delete: case toolkit.Delete:
uiDelete(a) uiDelete(a)
case toolkit.Move: case toolkit.Move:
log(debugNow, "attempt to move() =", a.ActionType, a.Widget) log(debugNow, "attempt to move() =", a.ActionType, a.WidgetType)
move(a) move(a)
default: default:
log(debugError, "Action() Unknown =", a.ActionType, a.Widget) log(debugError, "Action() Unknown =", a.ActionType, a.WidgetType)
} }
log(debugAction, "Action() END =", a.ActionType, a.Widget) log(debugAction, "Action() END =", a.ActionType, a.WidgetType)
} }
func flag(a *toolkit.Action) { func flag(a *toolkit.Action) {
@ -153,11 +143,11 @@ func setText(a *toolkit.Action) {
case toolkit.SetText: case toolkit.SetText:
t.uiCheckbox.SetText(a.S) t.uiCheckbox.SetText(a.S)
case toolkit.Get: case toolkit.Get:
t.tw.B = t.uiCheckbox.Checked() t.b = t.uiCheckbox.Checked()
case toolkit.Set: case toolkit.Set:
// TODO: commented out while working on chan // TODO: commented out while working on chan
// t.uiCheckbox.SetChecked(a.B) t.b = a.B
t.tw.B = a.B t.uiCheckbox.SetChecked(t.b)
default: default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name)
} }
@ -167,10 +157,6 @@ func setText(a *toolkit.Action) {
t.uiMultilineEntry.SetText(a.S) t.uiMultilineEntry.SetText(a.S)
case toolkit.SetText: case toolkit.SetText:
t.uiMultilineEntry.SetText(a.S) t.uiMultilineEntry.SetText(a.S)
case toolkit.Get:
t.tw.S = t.s
case toolkit.GetText:
t.tw.S = t.s
default: default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name)
} }
@ -181,7 +167,7 @@ func setText(a *toolkit.Action) {
case toolkit.Slider: case toolkit.Slider:
switch a.ActionType { switch a.ActionType {
case toolkit.Get: case toolkit.Get:
t.tw.I = t.uiSlider.Value() t.i = t.uiSlider.Value()
case toolkit.Set: case toolkit.Set:
t.uiSlider.SetValue(a.I) t.uiSlider.SetValue(a.I)
default: default:
@ -190,7 +176,7 @@ func setText(a *toolkit.Action) {
case toolkit.Spinner: case toolkit.Spinner:
switch a.ActionType { switch a.ActionType {
case toolkit.Get: case toolkit.Get:
t.tw.I = t.uiSpinbox.Value() t.i = t.uiSpinbox.Value()
case toolkit.Set: case toolkit.Set:
t.uiSpinbox.SetValue(a.I) t.uiSpinbox.SetValue(a.I)
default: default:
@ -211,7 +197,7 @@ func setText(a *toolkit.Action) {
log(debugChange, "i, s", i, s) log(debugChange, "i, s", i, s)
if (a.S == s) { if (a.S == s) {
t.uiCombobox.SetSelected(i) t.uiCombobox.SetSelected(i)
log(debugChange, "setText() Dropdown worked.", t.tw.S) log(debugChange, "setText() Dropdown worked.", t.s)
return return
} }
} }
@ -225,9 +211,9 @@ func setText(a *toolkit.Action) {
t.uiCombobox.SetSelected(i) t.uiCombobox.SetSelected(i)
} }
case toolkit.Get: case toolkit.Get:
t.tw.S = t.s // t.S = t.s
case toolkit.GetText: case toolkit.GetText:
t.tw.S = t.s // t.S = t.s
default: default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name)
} }
@ -241,10 +227,6 @@ func setText(a *toolkit.Action) {
case toolkit.SetText: case toolkit.SetText:
t.uiEditableCombobox.SetText(a.S) t.uiEditableCombobox.SetText(a.S)
t.s = a.S t.s = a.S
case toolkit.Get:
t.tw.S = t.s
case toolkit.GetText:
t.tw.S = t.s
default: default:
log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name) log(debugError, "setText() unknown", a.ActionType, "on checkbox", t.Name)
} }

View File

@ -9,12 +9,10 @@ import (
func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT { func (t *andlabsT) newSlider(a *toolkit.Action) *andlabsT {
var newt andlabsT var newt andlabsT
w := a.Widget
s := ui.NewSlider(a.X, a.Y) s := ui.NewSlider(a.X, a.Y)
newt.uiSlider = s newt.uiSlider = s
newt.uiControl = s newt.uiControl = s
newt.tw = w
newt.WidgetType = toolkit.Slider newt.WidgetType = toolkit.Slider
newt.wId = a.WidgetId newt.wId = a.WidgetId

View File

@ -9,13 +9,10 @@ import (
func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT { func (t *andlabsT) newSpinner(a *toolkit.Action) *andlabsT {
var newt andlabsT var newt andlabsT
w := a.Widget
// log(debugToolkit, "newSpinner()", w.X, w.Y)
s := ui.NewSpinbox(a.X, a.Y) s := ui.NewSpinbox(a.X, a.Y)
newt.uiSpinbox = s newt.uiSpinbox = s
newt.uiControl = s newt.uiControl = s
newt.tw = w
newt.wId = a.WidgetId newt.wId = a.WidgetId
newt.WidgetType = toolkit.Spinner newt.WidgetType = toolkit.Spinner

View File

@ -20,7 +20,7 @@ type andlabsT struct {
Width int Width int
Height int Height int
tw *toolkit.Widget // tw *toolkit.Widget
parent *andlabsT parent *andlabsT
uiControl ui.Control uiControl ui.Control

View File

@ -8,26 +8,26 @@ import (
) )
// func newTextbox(a *toolkit.Action) { // func newTextbox(a *toolkit.Action) {
func (t *andlabsT) newTextbox(w *toolkit.Widget) *andlabsT { func (t *andlabsT) newTextbox() *andlabsT {
var newt andlabsT var newt andlabsT
c := ui.NewNonWrappingMultilineEntry() c := ui.NewNonWrappingMultilineEntry()
newt.uiMultilineEntry = c newt.uiMultilineEntry = c
newt.uiControl = c newt.uiControl = c
newt.tw = w
newt.WidgetType = toolkit.Textbox newt.WidgetType = toolkit.Textbox
c.OnChanged(func(spin *ui.MultilineEntry) { c.OnChanged(func(spin *ui.MultilineEntry) {
t.s = spin.Text() newt.s = spin.Text()
// this is still dangerous // this is still dangerous
log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry") log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry")
newt.s = spin.Text()
newt.doUserEvent()
}) })
return &newt return &newt
} }
func newTextbox(a *toolkit.Action) { func newTextbox(a *toolkit.Action) {
w := a.Widget
log(debugToolkit, "newCombobox()", a.Name) log(debugToolkit, "newCombobox()", a.Name)
t := andlabs[a.ParentId] t := andlabs[a.ParentId]
@ -36,7 +36,8 @@ func newTextbox(a *toolkit.Action) {
listMap(debugToolkit) listMap(debugToolkit)
return return
} }
newt := t.newTextbox(w) newt := t.newTextbox()
newt.Name = a.Name newt.Name = a.Name
newt.wId = a.WidgetId
place(a, t, newt) place(a, t, newt)
} }

View File

@ -53,8 +53,7 @@ type Action struct {
// this should be the widget // this should be the widget
// if the action is New, Hide, Enable, etc // if the action is New, Hide, Enable, etc
Widget *Widget // Widget *Widget
Callback func(int) bool
// This is how the values are passed back and forth // This is how the values are passed back and forth
// values from things like checkboxes & dropdown's // values from things like checkboxes & dropdown's