diff options
Diffstat (limited to 'toolkit')
| -rw-r--r-- | toolkit/andlabs/append.go | 103 | ||||
| -rw-r--r-- | toolkit/andlabs/box.go | 14 | ||||
| -rw-r--r-- | toolkit/andlabs/checkbox.go | 24 | ||||
| -rw-r--r-- | toolkit/andlabs/combobox.go | 100 | ||||
| -rw-r--r-- | toolkit/andlabs/common.go | 143 | ||||
| -rw-r--r-- | toolkit/andlabs/debug.go | 102 | ||||
| -rw-r--r-- | toolkit/andlabs/dropdown.go | 73 | ||||
| -rw-r--r-- | toolkit/andlabs/grid.go | 102 | ||||
| -rw-r--r-- | toolkit/andlabs/group.go | 33 | ||||
| -rw-r--r-- | toolkit/andlabs/icon.go | 27 | ||||
| -rw-r--r-- | toolkit/andlabs/label.go | 3 | ||||
| -rw-r--r-- | toolkit/andlabs/main.go | 7 | ||||
| -rw-r--r-- | toolkit/andlabs/plugin.go | 38 | ||||
| -rw-r--r-- | toolkit/andlabs/resources/ping6.broken.png | bin | 0 -> 9486 bytes | |||
| -rw-r--r-- | toolkit/andlabs/resources/ping6.pure-bright.png | bin | 0 -> 11989 bytes | |||
| -rw-r--r-- | toolkit/andlabs/resources/ping6.pure.png | bin | 0 -> 9072 bytes | |||
| -rw-r--r-- | toolkit/andlabs/resources/ping6.working.png | bin | 0 -> 3654 bytes | |||
| -rw-r--r-- | toolkit/andlabs/slider.go | 3 | ||||
| -rw-r--r-- | toolkit/andlabs/spinner.go | 3 | ||||
| -rw-r--r-- | toolkit/andlabs/structs.go | 2 | ||||
| -rw-r--r-- | toolkit/andlabs/tab.go | 10 | ||||
| -rw-r--r-- | toolkit/andlabs/textbox.go | 62 | ||||
| -rw-r--r-- | toolkit/widget.go | 9 |
23 files changed, 700 insertions, 158 deletions
diff --git a/toolkit/andlabs/append.go b/toolkit/andlabs/append.go new file mode 100644 index 0000000..811ffbc --- /dev/null +++ b/toolkit/andlabs/append.go @@ -0,0 +1,103 @@ +package main + +import ( + "git.wit.org/wit/gui/toolkit" + + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" +) + +// make new Group here +func (t *andlabsT) doAppend(newt *andlabsT, c *ui.Control) { + + if (newt.tw != nil) { + if (newt.tw.Type == toolkit.Grid) { + log(true, "doAppend() going to attempt uiGrid") + // hack to add shit to a grid + button1 := ui.NewButton("a(0,2)") + newt.uiGrid.Append(button1, + 0, 2, 1, 1, + false, ui.AlignFill, false, ui.AlignFill) + button2 := ui.NewButton("a(1,2)") + newt.uiGrid.Append(button2, + 1, 2, 1, 1, + false, ui.AlignFill, false, ui.AlignFill) + + if (t.uiBox != nil) { + log(true, "doAppend() on uiGrid to a uiBox") + if (newt.Name == "output") { + t.uiBox.Append(newt.uiGrid, true) + } else { + t.uiBox.Append(newt.uiGrid, stretchy) + } + return + } + log(true, "doAppend() on uiGrid failed") + return + } + } else { + log(true, "doAppend() newt.tw == nil ERROR on newt.Name =", newt.Name) + } + + // hack to pass a group + if (c == nil) { + log(true, "attempting to doAppend() on a uiGroup") + if (t.uiBox != nil) { + if (newt.Name == "output") { + t.uiBox.Append(newt.uiGroup, true) + } else { + t.uiBox.Append(newt.uiGroup, stretchy) + } + return + } + + if (t.uiWindow != nil) { + log(true, "This is a raw window without a box. probably make a box here and add the group to that") + t.Dump(true) + newt.Dump(true) + t.uiBox = ui.NewHorizontalBox() + t.uiWindow.SetChild(t.uiBox) + log(true, "tried to make a box", t.uiBox) + if (newt.Name == "output") { + log(true, "tried to t.uiBox.Append(*c, true)") + if (t.uiBox == nil) { + log(true, "tried to t.uiBox.Append(*c, true)") + } + t.uiBox.Append(newt.uiGroup, true) + } else { + log(true, "tried to t.uiBox.Append(*c, stretchy)") + t.uiBox.Append(newt.uiGroup, stretchy) + } + return + } + + log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it") + log(debugError, "probably could just make a box here?") + exit("internal wit/gui error") + } + if (t.uiBox != nil) { + // TODO: temporary hack to make the output textbox 'fullscreen' + if (newt.Name == "output") { + t.uiBox.Append(*c, true) + } else { + t.uiBox.Append(*c, stretchy) + } + return + } + if (t.uiWindow != nil) { + log(true, "This is a raw window without a box. probably make a box here and add the group to that") + t.uiBox = ui.NewHorizontalBox() + t.uiWindow.SetChild(t.uiBox) + log(true, "tried to make a box") + if (newt.Name == "output") { + t.uiBox.Append(*c, true) + } else { + t.uiBox.Append(*c, stretchy) + } + return + } + + log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it") + log(debugError, "probably could just make a box here?") + exit("internal wit/gui error") +} diff --git a/toolkit/andlabs/box.go b/toolkit/andlabs/box.go index 430e78e..265d7c8 100644 --- a/toolkit/andlabs/box.go +++ b/toolkit/andlabs/box.go @@ -4,16 +4,16 @@ import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" // create a new box -func (t *andlabsT) GetBox() *ui.Box { +func (t *andlabsT) getBox() *ui.Box { return t.uiBox } // create a new box -func (t *andlabsT) NewBox() *andlabsT { - log(debugToolkit, "gui.Toolbox.NewBox() START create default") +func (t *andlabsT) newBox() *andlabsT { + log(debugToolkit, "newBox() START create default") t.Dump(debugToolkit) if (t.uiGroup != nil) { - log(debugToolkit, "\tgui.Toolbox.NewBox() is a Group") + log(debugToolkit, "\tnewBox() is a Group") var newTK andlabsT vbox := ui.NewVerticalBox() @@ -24,7 +24,7 @@ func (t *andlabsT) NewBox() *andlabsT { return &newTK } if (t.uiBox != nil) { - log(debugToolkit, "\tgui.Toolbox.NewBox() is a Box") + log(debugToolkit, "\tnewBox() is a Box") var newTK andlabsT vbox := ui.NewVerticalBox() @@ -36,7 +36,7 @@ func (t *andlabsT) NewBox() *andlabsT { return &newTK } if (t.uiWindow != nil) { - log(debugToolkit, "\tgui.Toolbox.NewBox() is a Window") + log(debugToolkit, "\tnewBox() is a Window") var newT andlabsT vbox := ui.NewVerticalBox() @@ -48,7 +48,7 @@ func (t *andlabsT) NewBox() *andlabsT { // panic("WTF") return &newT } - log(debugToolkit, "\tgui.Toolbox.NewBox() FAILED. Couldn't figure out where to make a box") + log(debugToolkit, "\tnewBox() FAILED. Couldn't figure out where to make a box") t.Dump(debugToolkit) return nil } diff --git a/toolkit/andlabs/checkbox.go b/toolkit/andlabs/checkbox.go index 29a8e4d..16e4eed 100644 --- a/toolkit/andlabs/checkbox.go +++ b/toolkit/andlabs/checkbox.go @@ -6,8 +6,8 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func (t andlabsT) NewCheckbox(w *toolkit.Widget) *andlabsT { - log(debugToolkit, "NewCheckbox()", w.Name, w.Type) +func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT { + log(debugToolkit, "newCheckbox()", w.Name, w.Type) var newt andlabsT newt.tw = w @@ -15,13 +15,13 @@ func (t andlabsT) NewCheckbox(w *toolkit.Widget) *andlabsT { return nil } - c := ui.NewCheckbox(w.Name) - newt.uiCheckbox = c + newt.uiCheckbox = ui.NewCheckbox(w.Name) newt.uiBox = t.uiBox - t.uiBox.Append(c, stretchy) + // t.doAppend(&newt, *newt.uiCheckbox) + t.uiBox.Append(newt.uiCheckbox, stretchy) - c.OnToggled(func(spin *ui.Checkbox) { - newt.tw.B = newt.Checked() + newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) { + newt.tw.B = newt.checked() log(debugChange, "val =", newt.tw.B) newt.commonChange(newt.tw) }) @@ -29,7 +29,7 @@ func (t andlabsT) NewCheckbox(w *toolkit.Widget) *andlabsT { return &newt } -func (t andlabsT) Checked() bool { +func (t *andlabsT) checked() bool { if t.broken() { return false } @@ -37,15 +37,15 @@ func (t andlabsT) Checked() bool { return t.uiCheckbox.Checked() } -func NewCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) { - log(debugToolkit, "NewCheckbox()", w.Name) +func newCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) { + log(debugToolkit, "newCheckbox()", w.Name) t := mapToolkits[parentW] if (t == nil) { listMap(debugError) return } - newt := t.NewCheckbox(w) + newt := t.newCheckbox(w) mapWidgetsToolkits(w, newt) } @@ -54,7 +54,7 @@ func doCheckbox(p *toolkit.Widget, c *toolkit.Widget) { return } if (c.Action == "New") { - NewCheckbox(p, c) + newCheckbox(p, c) return } ct := mapToolkits[c] diff --git a/toolkit/andlabs/combobox.go b/toolkit/andlabs/combobox.go new file mode 100644 index 0000000..08e7148 --- /dev/null +++ b/toolkit/andlabs/combobox.go @@ -0,0 +1,100 @@ +package main + +import ( + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" + "git.wit.org/wit/gui/toolkit" +) + +func (t *andlabsT) newCombobox(w *toolkit.Widget) *andlabsT { + var newt andlabsT + log(debugToolkit, "newCombobox() START", w.Name) + + if t.broken() { + return nil + } + + newt.tw = w + s := ui.NewEditableCombobox() + newt.uiEditableCombobox = s + newt.uiBox = t.uiBox + t.uiBox.Append(s, stretchy) + + // initialize the index + newt.c = 0 + newt.val = make(map[int]string) + + s.OnChanged(func(spin *ui.EditableCombobox) { + newt.tw.S = spin.Text() + newt.commonChange(newt.tw) + }) + + return &newt +} + +func (t *andlabsT) AddComboboxName(title string) { + t.uiEditableCombobox.Append(title) + if (t.val == nil) { + log(debugToolkit, "make map didn't work") + return + } + t.val[t.c] = title + + // If this is the first menu added, set the dropdown to it + // if (t.c == 0) { + // } + t.c = t.c + 1 +} + +func newCombobox(parentW *toolkit.Widget, w *toolkit.Widget) { + log(debugToolkit, "newCombobox()", w.Name) + + t := mapToolkits[parentW] + if (t == nil) { + log(debugToolkit, "newCombobox() toolkit struct == nil. name=", parentW.Name, w.Name) + listMap(debugToolkit) + return + } + newt := t.newCombobox(w) + mapWidgetsToolkits(w, newt) +} + +func doCombobox(p *toolkit.Widget, c *toolkit.Widget) { + if broken(c) { + return + } + if (c.Action == "New") { + newCombobox(p, c) + return + } + ct := mapToolkits[c] + if (ct == nil) { + log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) + return + } + if ct.broken() { + log(true, "Combobox() ct.broken", ct) + return + } + if (ct.uiEditableCombobox == nil) { + log(true, "Combobox() uiEditableCombobox == nil", ct) + return + } + log(true, "Going to attempt:", c.Action) + switch c.Action { + case "Add": + ct.AddComboboxName(c.S) + case "Enable": + ct.uiEditableCombobox.Enable() + case "Disable": + ct.uiEditableCombobox.Disable() + case "Show": + ct.uiEditableCombobox.Show() + case "Hide": + ct.uiEditableCombobox.Hide() + case "Set": + ct.uiEditableCombobox.SetText(c.S) + default: + log(true, "Can't do", c.Action, "to a Combobox") + } +} diff --git a/toolkit/andlabs/common.go b/toolkit/andlabs/common.go index 31b73e6..d2811cb 100644 --- a/toolkit/andlabs/common.go +++ b/toolkit/andlabs/common.go @@ -2,6 +2,7 @@ package main import ( "git.wit.org/wit/gui/toolkit" + "github.com/davecgh/go-spew/spew" ) // This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc @@ -11,7 +12,7 @@ func init() { setDefaultBehavior(true) } -func (t andlabsT) commonChange(tw *toolkit.Widget) { +func (t *andlabsT) commonChange(tw *toolkit.Widget) { log(debugChange, "commonChange() START widget =", t.Name, t.Type) if (tw == nil) { log(true, "commonChange() What the fuck. there is no widget t.tw == nil") @@ -35,7 +36,7 @@ func (t *andlabsT) broken() bool { if (t.uiBox == nil) { if (t.uiWindow != nil) { log(debugToolkit, "UiBox == nil. This is an empty window. Try to add a box") - t.NewBox() + t.newBox() return false } log(true, "UiBox == nil. I can't add a widget without a place to put it") @@ -60,3 +61,141 @@ func broken(w *toolkit.Widget) bool { } return false } + +func dump(p *toolkit.Widget, c *toolkit.Widget, b bool) { + log(b, "Parent:") + pt := mapToolkits[p] + if (pt == nil) { + log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) + return + } + pt.Dump(b) + + log(b, "Child:") + ct := mapToolkits[c] + if (ct == nil) { + log(b, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) + return + } + ct.Dump(b) +} + +func setMarginNew(w *toolkit.Widget, b bool) { + wt := mapToolkits[w] + log(true, "START setMarginNew", w.Name) + if (wt == nil) { + return + } + if (wt.uiGroup != nil) { + log(true, "uiGroup.SetMargined(true)") + wt.uiGroup.SetMargined(b) + } + if (wt.uiTab != nil) { + i := wt.uiTab.NumPages() + log(true, "tab.NumPages() =", i) + for i > 0 { + i -= 1 + log(true, "uiTab.SetMargined(true) for i =", i) + wt.uiTab.SetMargined(i, b) + } + } else { + log(true, "no uitab") + } + if (wt.uiWindow != nil) { + log(true, "uiWindow.SetMargined(true)") + wt.uiWindow.SetMargined(b) + } + log(true, "END setMarginNew", w.Name) +} + +func setMargin(p *toolkit.Widget, c *toolkit.Widget, b bool) { + log(true, "Starting to implement SetMargin here") + dump(p, c, true) + + setMarginNew(c, b) + setMarginNew(p, b) +} + +func (t *andlabsT) String() string { + return t.GetText() +} + +func (t *andlabsT) GetText() string { + log(debugToolkit, "GetText() Enter debugToolkit=", debugToolkit) + if (t.uiEntry != nil) { + log(debugToolkit, "uiEntry.Text() =", t.uiEntry.Text()) + return t.uiEntry.Text() + } + if (t.uiMultilineEntry != nil) { + log(debugToolkit, "uiMultilineEntry.Text() =", t.uiMultilineEntry.Text()) + text := t.uiMultilineEntry.Text() + log(debugToolkit, "uiMultilineEntry.Text() =", text) + t.text = text + return text + } + if (t.uiCombobox != nil) { + log(debugToolkit, "uiCombobox() =", t.text) + return t.text + } + return "" +} + +func (t *andlabsT) SetText(s string) bool { + log(debugToolkit, "Text() SetText() Enter") + if (t.uiEntry != nil) { + log(debugToolkit, "Value() =", t.uiEntry.Text) + t.uiEntry.SetText(s) + return true + } + if (t.uiMultilineEntry != nil) { + log(debugToolkit, "Value() =", t.uiMultilineEntry.Text) + t.uiMultilineEntry.SetText(s) + return true + } + return false +} + +func sanity(t *andlabsT) bool { + if (debugToolkit) { + log(debugToolkit, "Value() Enter") + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(t) + } + if (t.uiEntry == nil) { + log(debugToolkit, "Value() =", t.uiEntry.Text) + return false + } + return true +} + +func (t *andlabsT) SetValue(i int) bool { + log(debugToolkit, "SetValue() START") + if (sanity(t)) { + return false + } + t.Dump(debugToolkit) + // panic("got to toolkit.SetValue") + return true +} + +func (t *andlabsT) Value() int { + if (debugToolkit) { + log(debugToolkit, "Value() Enter") + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(t) + } + if (t == nil) { + log(debugToolkit, "Value() can not get value t == nil") + return 0 + } + if (t.uiSlider != nil) { + log(debugToolkit, "Value() =", t.uiSlider.Value) + return t.uiSlider.Value() + } + if (t.uiSpinbox != nil) { + log(debugToolkit, "Value() =", t.uiSpinbox.Value) + return t.uiSpinbox.Value() + } + log(debugToolkit, "Value() Could not find a ui element to get a value from") + return 0 +} diff --git a/toolkit/andlabs/debug.go b/toolkit/andlabs/debug.go index befbaa0..8b11f8c 100644 --- a/toolkit/andlabs/debug.go +++ b/toolkit/andlabs/debug.go @@ -2,7 +2,7 @@ package main import "git.wit.org/wit/gui/toolkit" -import "github.com/davecgh/go-spew/spew" +// import "github.com/davecgh/go-spew/spew" var defaultBehavior bool = true @@ -16,6 +16,7 @@ var margin bool // add space around the frames of windows var debugToolkit bool var debugChange bool var debugPlugin bool +var debugFlag bool var debugError bool = true // var DebugToolkit bool @@ -36,6 +37,7 @@ func setDefaultBehavior(s bool) { } } +/* func SetDebugToolkit (s bool) { debugToolkit = s log(true, "debugToolkit =", debugToolkit) @@ -47,98 +49,12 @@ func SetDebugChange (s bool) { log(true, "debugToolkit =", debugToolkit) log(true, "debugChange =", debugChange) } +*/ func ShowDebug () { log(true, "debugToolkit =", debugToolkit) - log(true, "debugChange =", debugChange) -} - -func GetDebugToolkit () bool { - return debugToolkit -} - -func (t *andlabsT) String() string { - return t.GetText() -} - -func (t *andlabsT) GetText() string { - log(debugToolkit, "GetText() Enter debugToolkit=", debugToolkit) - if (t.uiEntry != nil) { - log(debugToolkit, "uiEntry.Text() =", t.uiEntry.Text()) - return t.uiEntry.Text() - } - if (t.uiMultilineEntry != nil) { - log(debugToolkit, "uiMultilineEntry.Text() =", t.uiMultilineEntry.Text()) - text := t.uiMultilineEntry.Text() - log(debugToolkit, "uiMultilineEntry.Text() =", text) - t.text = text - return text - } - if (t.uiCombobox != nil) { - log(debugToolkit, "uiCombobox() =", t.text) - return t.text - } - return "" -} - -func (t *andlabsT) SetText(s string) bool { - log(debugToolkit, "Text() SetText() Enter") - if (t.uiEntry != nil) { - log(debugToolkit, "Value() =", t.uiEntry.Text) - t.uiEntry.SetText(s) - return true - } - if (t.uiMultilineEntry != nil) { - log(debugToolkit, "Value() =", t.uiMultilineEntry.Text) - t.uiMultilineEntry.SetText(s) - return true - } - return false -} - -func sanity(t *andlabsT) bool { - if (debugToolkit) { - log(debugToolkit, "Value() Enter") - scs := spew.ConfigState{MaxDepth: 1} - scs.Dump(t) - } - if (t.uiEntry == nil) { - log(debugToolkit, "Value() =", t.uiEntry.Text) - return false - } - return true -} - -func (t *andlabsT) SetValue(i int) bool { - log(debugToolkit, "SetValue() START") - if (sanity(t)) { - return false - } - t.Dump(debugToolkit) - // panic("got to toolkit.SetValue") - return true -} - -func (t *andlabsT) Value() int { - if (debugToolkit) { - log(debugToolkit, "Value() Enter") - scs := spew.ConfigState{MaxDepth: 1} - scs.Dump(t) - } - if (t == nil) { - log(debugToolkit, "Value() can not get value t == nil") - return 0 - } - if (t.uiSlider != nil) { - log(debugToolkit, "Value() =", t.uiSlider.Value) - return t.uiSlider.Value() - } - if (t.uiSpinbox != nil) { - log(debugToolkit, "Value() =", t.uiSpinbox.Value) - return t.uiSpinbox.Value() - } - log(debugToolkit, "Value() Could not find a ui element to get a value from") - return 0 + log(true, "debugError =", debugError) + log(true, "debugChange =", debugChange) } func (t *andlabsT) Dump(b bool) { @@ -196,3 +112,9 @@ func widgetDump(b bool, w *toolkit.Widget) { log(b, "widget.X =", w.X) log(b, "widget.Y =", w.Y) } + +/* +func GetDebugToolkit () bool { + return debugToolkit +} +*/ diff --git a/toolkit/andlabs/dropdown.go b/toolkit/andlabs/dropdown.go index 935741c..57642e0 100644 --- a/toolkit/andlabs/dropdown.go +++ b/toolkit/andlabs/dropdown.go @@ -6,9 +6,9 @@ import ( "git.wit.org/wit/gui/toolkit" ) -func (t *andlabsT) NewDropdown(w *toolkit.Widget) *andlabsT { +func (t *andlabsT) newDropdown(w *toolkit.Widget) *andlabsT { var newt andlabsT - log(debugToolkit, "gui.Toolbox.NewDropdown() START", w.Name) + log(debugToolkit, "gui.Toolbox.newDropdown() START", w.Name) if t.broken() { return nil @@ -53,23 +53,10 @@ func (t *andlabsT) AddDropdownName(title string) { t.c = t.c + 1 } -func (t andlabsT) SetDropdown(i int) { +func (t *andlabsT) SetDropdown(i int) { t.uiCombobox.SetSelected(i) } -func NewDropdown(parentW *toolkit.Widget, w *toolkit.Widget) { - log(debugToolkit, "gui.andlabs.NewDropdown()", w.Name) - - t := mapToolkits[parentW] - if (t == nil) { - log(debugToolkit, "go.andlabs.NewDropdown() toolkit struct == nil. name=", parentW.Name, w.Name) - listMap(debugToolkit) - return - } - newt := t.NewDropdown(w) - mapWidgetsToolkits(w, newt) -} - func AddDropdownName(w *toolkit.Widget, s string) { log(debugToolkit, "gui.andlabs.AddDropdownName()", w.Name, "add:", s) @@ -94,3 +81,57 @@ func SetDropdownName(w *toolkit.Widget, s string) { t.SetDropdown(1) t.tw.S = s } + +func newDropdown(parentW *toolkit.Widget, w *toolkit.Widget) { + log(debugToolkit, "gui.andlabs.newDropdown()", w.Name) + + t := mapToolkits[parentW] + if (t == nil) { + log(debugToolkit, "go.andlabs.newDropdown() toolkit struct == nil. name=", parentW.Name, w.Name) + listMap(debugToolkit) + return + } + newt := t.newDropdown(w) + mapWidgetsToolkits(w, newt) +} + +func doDropdown(p *toolkit.Widget, c *toolkit.Widget) { + if broken(c) { + return + } + if (c.Action == "New") { + newDropdown(p, c) + return + } + ct := mapToolkits[c] + if (ct == nil) { + log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) + return + } + if ct.broken() { + log(true, "Dropdown() ct.broken", ct) + return + } + if (ct.uiCombobox == nil) { + log(true, "Dropdown() uiCombobox == nil", ct) + return + } + log(true, "Going to attempt:", c.Action) + switch c.Action { + case "Add": + ct.AddDropdownName(c.S) + // ct.uiCombobox.Enable() + case "Enable": + ct.uiCombobox.Enable() + case "Disable": + ct.uiCombobox.Disable() + case "Show": + ct.uiCombobox.Show() + case "Hide": + ct.uiCombobox.Hide() + case "Set": + ct.uiCombobox.SetSelected(1) + default: + log(true, "Can't do", c.Action, "to a Dropdown") + } +} diff --git a/toolkit/andlabs/grid.go b/toolkit/andlabs/grid.go new file mode 100644 index 0000000..8d09152 --- /dev/null +++ b/toolkit/andlabs/grid.go @@ -0,0 +1,102 @@ +package main + +import ( + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" + + "git.wit.org/wit/gui/toolkit" +) + +// Grid numbering by (X,Y) +// ----------------------------- +// -- (1,1) -- (2,1) -- (3,1) -- +// -- (1,2) -- (2,1) -- (3,1) -- +// ----------------------------- +func newGrid(parentW *toolkit.Widget, w *toolkit.Widget) { + var newt *andlabsT + log(debugToolkit, "NewGrid()", w.Name) + + t := mapToolkits[parentW] + if (t == nil) { + listMap(debugError) + log(debugError, "ERROR newGrid() listMap()") + log(debugError, "ERROR FFFFFFFFFFFF listMap()") + log(debugError, "ERROR FFFFFFFFFFFF listMap()") + return + } + + log(debugToolkit, "NewGrid()", w.Name) + if t.broken() { + return + } + + newt = new(andlabsT) + + c := ui.NewGrid() + newt.uiGrid = c + newt.uiBox = t.uiBox + newt.tw = w + t.doAppend(newt, nil) + /* + if (defaultBehavior) { + t.uiBox.Append(c, stretchy) + } + + button1 := ui.NewButton("a(0,0)") + c.Append(button1, + 0, 0, 1, 1, + false, ui.AlignFill, false, ui.AlignFill) + + button2 := ui.NewButton("a(1,0)") + c.Append(button2, + 1, 0, 1, 1, + false, ui.AlignFill, false, ui.AlignFill) + */ + + // Append(child Control, + // left, top int, + // xspan, yspan int, + // hexpand bool, halign Align, + // vexpand bool, valign Align) { + + mapWidgetsToolkits(w, newt) +} + +func doGrid(p *toolkit.Widget, c *toolkit.Widget) { + if broken(c) { + return + } + if (c.Action == "New") { + newGrid(p, c) + return + } + ct := mapToolkits[c] + if (ct == nil) { + log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c) + return + } + if ct.broken() { + log(true, "Grid() ct.broken", ct) + return + } + if (ct.uiGrid == nil) { + + log(true, "Grid() uiGrid == nil", ct) + return + } + log(true, "Going to attempt:", c.Action) + switch c.Action { + case "Enable": + ct.uiGrid.Enable() + case "Disable": + ct.uiGrid.Disable() + case "Show": + ct.uiGrid.Show() + case "Hide": + ct.uiGrid.Hide() + case "Set": + log(true, "Can I use 'Set' to place a *Node in a Grid?") + default: + log(true, "Can't do", c.Action, "to a Grid") + } +} diff --git a/toolkit/andlabs/group.go b/toolkit/andlabs/group.go index 613efb6..903cb4f 100644 --- a/toolkit/andlabs/group.go +++ b/toolkit/andlabs/group.go @@ -8,49 +8,62 @@ import ( ) func newGroup(parentW *toolkit.Widget, w *toolkit.Widget) { - log(debugToolkit, "gui.andlabs.NewGroup()", w.Name) + // log(debugToolkit, "gui.andlabs.NewGroup()", w.Name) + log(true, "NewGroup()", w.Name) t := mapToolkits[parentW] if (t == nil) { - log(debugToolkit, "go.andlabs.NewGroup() toolkit struct == nil. name=", parentW.Name, w.Name) + log(debugToolkit, "NewGroup() toolkit struct == nil. name=", parentW.Name, w.Name) listMap(debugToolkit) } - newt := t.NewGroup(w.Name) + newt := t.rawGroup(w.Name) mapWidgetsToolkits(w, newt) } // make new Group here -func (t andlabsT) NewGroup(title string) *andlabsT { +func (t *andlabsT) rawGroup(title string) *andlabsT { var newt andlabsT + newt.Name = title - log(debugToolkit, "NewGroup() create", title) + log(debugToolkit, "NewGroup() create", newt.Name) - g := ui.NewGroup(title) + g := ui.NewGroup(newt.Name) g.SetMargined(margin) + newt.uiGroup = g + t.doAppend(&newt, nil) + /* if (t.uiBox != nil) { // TODO: temporary hack to make the output textbox 'fullscreen' - if (title == "output") { + if (newt.Name == "output") { t.uiBox.Append(g, true) } else { t.uiBox.Append(g, stretchy) } } else if (t.uiWindow != nil) { - t.uiWindow.SetChild(g) + log(true, "This is a raw window without a box. probably make a box here and add the group to that") + t.uiBox = ui.NewHorizontalBox() + t.uiWindow.SetChild(t.uiBox) + log(true, "tried to make a box") + if (newt.Name == "output") { + t.uiBox.Append(g, true) + } else { + t.uiBox.Append(g, stretchy) + } } else { log(debugError, "NewGroup() node.UiBox == nil. I can't add a range UI element without a place to put it") log(debugError, "probably could just make a box here?") exit("internal wit/gui error") } + */ hbox := ui.NewVerticalBox() hbox.SetPadded(padded) g.SetChild(hbox) - newt.uiGroup = g newt.uiBox = hbox newt.uiWindow = t.uiWindow - newt.Name = title + newt.uiTab = t.uiTab return &newt } diff --git a/toolkit/andlabs/icon.go b/toolkit/andlabs/icon.go new file mode 100644 index 0000000..00c25f6 --- /dev/null +++ b/toolkit/andlabs/icon.go @@ -0,0 +1,27 @@ +package main + +var rawImage = []byte{ + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, + 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, + 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0xf3, 0xff, 0x61, 0x00, 0x00, 0x00, + 0x01, 0x73, 0x52, 0x47, 0x42, 0x00, 0xae, 0xce, 0x1c, 0xe9, 0x00, 0x00, + 0x00, 0xca, 0x49, 0x44, 0x41, 0x54, 0x38, 0x11, 0xa5, 0x93, 0xb1, 0x0d, + 0xc2, 0x40, 0x0c, 0x45, 0x1d, 0xc4, 0x14, 0x0c, 0x12, 0x41, 0x0f, 0x62, + 0x12, 0x46, 0x80, 0x8a, 0x2e, 0x15, 0x30, 0x02, 0x93, 0x20, 0x68, 0x11, + 0x51, 0x06, 0x61, 0x0d, 0x88, 0x2d, 0x7f, 0xdb, 0x07, 0x87, 0x08, 0xdc, + 0x49, 0x91, 0x7d, 0xf6, 0xf7, 0xf3, 0x4f, 0xa4, 0x54, 0xbb, 0xeb, 0xf6, + 0x41, 0x05, 0x67, 0xcc, 0xb3, 0x9b, 0xfa, 0xf6, 0x17, 0x62, 0xdf, 0xcd, + 0x48, 0x00, 0x32, 0xbd, 0xa8, 0x1d, 0x72, 0xee, 0x3c, 0x47, 0x16, 0xfb, + 0x5c, 0x53, 0x8d, 0x03, 0x30, 0x14, 0x84, 0xf7, 0xd5, 0x89, 0x26, 0xc7, + 0x25, 0x10, 0x36, 0xe4, 0x05, 0xa2, 0x51, 0xbc, 0xc4, 0x1c, 0xc3, 0x1c, + 0xed, 0x30, 0x1c, 0x8f, 0x16, 0x3f, 0x02, 0x78, 0x33, 0x20, 0x06, 0x60, + 0x97, 0x70, 0xaa, 0x45, 0x7f, 0x85, 0x60, 0x5d, 0xb6, 0xf4, 0xc2, 0xc4, + 0x3e, 0x0f, 0x44, 0xcd, 0x1b, 0x20, 0x90, 0x0f, 0xed, 0x85, 0xa8, 0x55, + 0x05, 0x42, 0x43, 0xb4, 0x9e, 0xce, 0x71, 0xb3, 0xe8, 0x0e, 0xb4, 0xc4, + 0xc3, 0x39, 0x21, 0xb7, 0x73, 0xbd, 0xe4, 0x1b, 0xe4, 0x04, 0xb6, 0xaa, + 0x4f, 0x18, 0x2c, 0xee, 0x42, 0x31, 0x01, 0x84, 0xfa, 0xe0, 0xd4, 0x00, + 0xdf, 0xb6, 0x83, 0xf8, 0xea, 0xc2, 0x00, 0x10, 0xfc, 0x1a, 0x05, 0x30, + 0x74, 0x3b, 0xe0, 0xd1, 0x45, 0xb1, 0x83, 0xaa, 0xf4, 0x77, 0x7e, 0x02, + 0x87, 0x1f, 0x42, 0x7f, 0x9e, 0x2b, 0xe8, 0xdf, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, +} diff --git a/toolkit/andlabs/label.go b/toolkit/andlabs/label.go index 6bdd9b2..fca9abb 100644 --- a/toolkit/andlabs/label.go +++ b/toolkit/andlabs/label.go @@ -27,7 +27,7 @@ func newLabel(parentW *toolkit.Widget, w *toolkit.Widget) { newt = new(andlabsT) - c := ui.NewLabel(w.Name + " FIX") + c := ui.NewLabel(w.Name) newt.uiLabel = c newt.uiBox = t.uiBox @@ -39,7 +39,6 @@ func newLabel(parentW *toolkit.Widget, w *toolkit.Widget) { mapWidgetsToolkits(w, newt) } - func doLabel(p *toolkit.Widget, c *toolkit.Widget) { if broken(c) { return diff --git a/toolkit/andlabs/main.go b/toolkit/andlabs/main.go index a72821a..20bbd8b 100644 --- a/toolkit/andlabs/main.go +++ b/toolkit/andlabs/main.go @@ -1,6 +1,7 @@ package main import ( + "embed" "git.wit.org/wit/gui/toolkit" "github.com/andlabs/ui" @@ -8,6 +9,9 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) +//go:embed resources +var res embed.FS + func Main(f func()) { log(debugToolkit, "Starting gui.Main() (using gtk via andlabs/ui)") ui.Main( func() { @@ -33,9 +37,8 @@ func Main(f func()) { // func Queue(f func()) { log(debugToolkit, "Sending function to ui.QueueMain()") - log(true, "THIS DOES BREAK. TODO: wrap this") + log(true, "using gui.Queue() in this plugin DOES BREAK. TODO: wrap this") ui.QueueMain(f) - // f() } func Init() { diff --git a/toolkit/andlabs/plugin.go b/toolkit/andlabs/plugin.go index 5bc40a0..8b75766 100644 --- a/toolkit/andlabs/plugin.go +++ b/toolkit/andlabs/plugin.go @@ -26,6 +26,12 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { } log(debugPlugin, "Send() child =", c.Name, ",", c.Action, ",", c.Type) + if (c.Action == "SetMargin") { + log(true, "need to implement SetMargin here") + setMargin(p, c, c.B) + return + } + switch c.Type { case toolkit.Window: newWindow(c) @@ -45,10 +51,36 @@ func Send(p *toolkit.Widget, c *toolkit.Widget) { newSlider(p, c) case toolkit.Spinner: newSpinner(p, c) + case toolkit.Dropdown: + doDropdown(p, c) + case toolkit.Combobox: + doCombobox(p, c) + case toolkit.Grid: + doGrid(p, c) + case toolkit.Flag: + log(debugFlag, "plugin Send() flag parent =", p.Name, p.Type) + log(debugFlag, "plugin Send() flag child =", c.Name, c.Type) + log(debugFlag, "plugin Send() flag child.Action =", c.Action) + log(debugFlag, "plugin Send() flag child.S =", c.S) + log(debugFlag, "plugin Send() flag child.B =", c.B) + log(debugFlag, "plugin Send() what to flag?") + // should set the checkbox to this value + switch c.S { + case "Error": + debugError = c.B + case "Toolkit": + debugToolkit = c.B + case "Change": + debugChange = c.B + case "Show": + ShowDebug() + default: + log(debugError, "Can't set unknown flag", c.S) + } default: - log(true, "unknown parent =", p.Name, p.Type) - log(true, "unknown child =", c.Name, c.Type) - log(true, "Don't know how to do", c.Type, "yet") + log(true, "plugin Send() unknown parent =", p.Name, p.Type) + log(true, "plugin Send() unknown child =", c.Name, c.Type) + log(true, "plugin Send() Don't know how to do", c.Type, "yet") } } diff --git a/toolkit/andlabs/resources/ping6.broken.png b/toolkit/andlabs/resources/ping6.broken.png Binary files differnew file mode 100644 index 0000000..9a3e2ae --- /dev/null +++ b/toolkit/andlabs/resources/ping6.broken.png diff --git a/toolkit/andlabs/resources/ping6.pure-bright.png b/toolkit/andlabs/resources/ping6.pure-bright.png Binary files differnew file mode 100644 index 0000000..82c554d --- /dev/null +++ b/toolkit/andlabs/resources/ping6.pure-bright.png diff --git a/toolkit/andlabs/resources/ping6.pure.png b/toolkit/andlabs/resources/ping6.pure.png Binary files differnew file mode 100644 index 0000000..9e08140 --- /dev/null +++ b/toolkit/andlabs/resources/ping6.pure.png diff --git a/toolkit/andlabs/resources/ping6.working.png b/toolkit/andlabs/resources/ping6.working.png Binary files differnew file mode 100644 index 0000000..6767c59 --- /dev/null +++ b/toolkit/andlabs/resources/ping6.working.png diff --git a/toolkit/andlabs/slider.go b/toolkit/andlabs/slider.go index 87639ca..f75947a 100644 --- a/toolkit/andlabs/slider.go +++ b/toolkit/andlabs/slider.go @@ -7,7 +7,7 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func (t andlabsT) newSlider(w *toolkit.Widget) *andlabsT { +func (t *andlabsT) newSlider(w *toolkit.Widget) *andlabsT { // make new node here log(debugToolkit, w.Name, w.Type, w.X, w.Y) var newt andlabsT @@ -26,6 +26,7 @@ func (t andlabsT) newSlider(w *toolkit.Widget) *andlabsT { t.uiBox.Append(s, stretchy) s.OnChanged(func(spin *ui.Slider) { + newt.tw.I = newt.uiSlider.Value() newt.commonChange(newt.tw) }) diff --git a/toolkit/andlabs/spinner.go b/toolkit/andlabs/spinner.go index 1a7430e..2ee556c 100644 --- a/toolkit/andlabs/spinner.go +++ b/toolkit/andlabs/spinner.go @@ -7,7 +7,7 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func (t andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { +func (t *andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { // make new node here log(debugToolkit, "newSpinner()", w.X, w.Y) var newt andlabsT @@ -24,6 +24,7 @@ func (t andlabsT) newSpinner(w *toolkit.Widget) *andlabsT { t.uiBox.Append(s, stretchy) s.OnChanged(func(s *ui.Spinbox) { + newt.tw.I = newt.uiSpinbox.Value() newt.commonChange(newt.tw) }) diff --git a/toolkit/andlabs/structs.go b/toolkit/andlabs/structs.go index 45b6d1d..3353401 100644 --- a/toolkit/andlabs/structs.go +++ b/toolkit/andlabs/structs.go @@ -28,9 +28,9 @@ type andlabsT struct { uiSpinbox *ui.Spinbox uiTab *ui.Tab uiWindow *ui.Window - // UiWindowBad *ui.Window // erase this uiMultilineEntry *ui.MultilineEntry uiEditableCombobox *ui.EditableCombobox + uiGrid *ui.Grid // used as a counter to work around limitations of widgets like combobox // this is probably fucked up and in many ways wrong because of unsafe goroutine threading diff --git a/toolkit/andlabs/tab.go b/toolkit/andlabs/tab.go index 995bbbd..aaac102 100644 --- a/toolkit/andlabs/tab.go +++ b/toolkit/andlabs/tab.go @@ -63,7 +63,7 @@ func tabSetMargined(tab *ui.Tab) { } func rawTab(w *ui.Window, name string) *andlabsT { - var t andlabsT + var newt andlabsT log(debugToolkit, "gui.toolkit.NewTab() ADD", name) if (w == nil) { @@ -83,10 +83,10 @@ func rawTab(w *ui.Window, name string) *andlabsT { tabSetMargined(tab) // TODO: run this in the right place(?) w.SetChild(tab) - t.uiWindow = w - t.uiTab = tab - t.uiBox = hbox - return &t + newt.uiWindow = w + newt.uiTab = tab + newt.uiBox = hbox + return &newt } func (t *andlabsT) appendTab(name string) *andlabsT { diff --git a/toolkit/andlabs/textbox.go b/toolkit/andlabs/textbox.go index e916fd9..ddc27a4 100644 --- a/toolkit/andlabs/textbox.go +++ b/toolkit/andlabs/textbox.go @@ -1,9 +1,11 @@ package main -import "git.wit.org/wit/gui/toolkit" +import ( + "git.wit.org/wit/gui/toolkit" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" +) func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) { log(debugToolkit, "NewTexbox()", w.Name) @@ -15,8 +17,9 @@ func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) { log(debugError, "FFFFFFFFFFFF listMap()") log(debugError, "FFFFFFFFFFFF listMap()") } + // t.NewTextbox(w) -// func (t andlabsT) NewTextbox(w *toolkit.Widget) *andlabsT { +// func (t *andlabsT) NewTextbox(w *toolkit.Widget) *andlabsT { var newt *andlabsT newt = new(andlabsT) @@ -37,6 +40,41 @@ func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) { t.uiBox.Append(c, stretchy) } + /* + // don't bother with "images" on andlabs/ui + "image" + "bytes" + _ "image/png" + "image/draw" + + if (w.Name == "image") { + log(true, "NewTextbox() trying to add a new image") + i := ui.NewImage(16, 16) + img, _, err := image.Decode(bytes.NewReader(rawImage)) + if err != nil { + panic(err) + } + nr, ok := img.(*image.RGBA) + if !ok { + i2 := image.NewRGBA(img.Bounds()) + draw.Draw(i2, i2.Bounds(), img, img.Bounds().Min, draw.Src) + nr = i2 + } + i.Append(nr) + t.uiBox.Append(i, true) + + var img *ui.Image + var icon []byte + var imgA image.Image + + icon, _ = res.ReadFile("resources/ping6.working.png") + // imgA, _, err := image.Decode(bytes.NewReader(b)) + imgA, _, _ = image.Decode(icon) + img.Append(imgA) + img.Append(icon) + } + */ + c.OnChanged(func(spin *ui.MultilineEntry) { w.S = newt.uiMultilineEntry.Text() // this is still dangerous @@ -81,9 +119,21 @@ func (t *andlabsT) doSimpleAction() { log(debugChange, "Going to attempt:", t.tw.Action) switch t.tw.Action { case "Enable": - t.uiMultilineEntry.Enable() + if (t.uiEntry != nil) { + t.uiEntry.Enable() + } else if (t.uiMultilineEntry != nil) { + t.uiMultilineEntry.Enable() + } else { + log(true, "don't know what to enable", t.Name) + } case "Disable": - t.uiMultilineEntry.Disable() + if (t.uiEntry != nil) { + t.uiEntry.Disable() + } else if (t.uiMultilineEntry != nil) { + t.uiMultilineEntry.Disable() + } else { + log(true, "don't know what to disable", t.Name) + } case "Show": t.uiMultilineEntry.Show() case "Hide": diff --git a/toolkit/widget.go b/toolkit/widget.go index fcb6d31..9241d5a 100644 --- a/toolkit/widget.go +++ b/toolkit/widget.go @@ -56,10 +56,13 @@ const ( Button Checkbox Dropdown + Combobox Label Textbox Slider Spinner + Grid + Flag ) func (s WidgetType) String() string { @@ -78,6 +81,8 @@ func (s WidgetType) String() string { return "Checkbox" case Dropdown: return "Dropdown" + case Combobox: + return "Combobox" case Label: return "Label" case Textbox: @@ -86,6 +91,10 @@ func (s WidgetType) String() string { return "Slider" case Spinner: return "Spinner" + case Grid: + return "Grid" + case Flag: + return "Flag" case Unknown: return "Unknown" } |
