summaryrefslogtreecommitdiff
path: root/toolkit/andlabs2/tab.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2022-11-13 08:53:03 -0600
committerJeff Carr <[email protected]>2022-11-13 08:53:03 -0600
commit207cf7ea16f1da8fa9f893504d77a2856298cc22 (patch)
tree54d513b83ce797be75268f7d8867e0b01ab8f23e /toolkit/andlabs2/tab.go
parented382bec55be25039e4dcf020d1512139855c9bb (diff)
Massive refactor to use go plugins. This is neat.
update README.md set xterm title. make os.Exit() default on window close add a toolkit.Widget to the node structure remove 'Greeter' symbol mapping scheme removed the testing greeter code plugins: attempt to load plugins in a sensible order andlabs/ui: working andlabs/ui plugin (andlabs2) buttons work in andlabs plugin TODO: re-implement non-plugin version for Windows mswindows doesn't support go plugins yet gocui: put the gocui console so file in the binary does a full init of gocui plugin Button() and Group() working very well with gogui cleanly exit gocui technically you can load two toolkits at the same time kinda both working at the same time. esoteric two working plugins at the same time give up working on two gui's at the same time this is fun, but _not interesting wow. this actually works. NewButton() from both toolkits examples: all the examples run again remove early helloplugin example buttonplugin example cmd code buttonplugin runs and ldd is minimum Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/andlabs2/tab.go')
-rw-r--r--toolkit/andlabs2/tab.go147
1 files changed, 147 insertions, 0 deletions
diff --git a/toolkit/andlabs2/tab.go b/toolkit/andlabs2/tab.go
new file mode 100644
index 0000000..0556fb9
--- /dev/null
+++ b/toolkit/andlabs2/tab.go
@@ -0,0 +1,147 @@
+package main
+
+import (
+ "log"
+ "time"
+
+ "git.wit.org/wit/gui/toolkit"
+
+ "github.com/andlabs/ui"
+ _ "github.com/andlabs/ui/winmanifest"
+)
+
+/*
+ This adds a tab
+
+ andlabs/ui is goofy in the sense that you have to determine
+ if the ui.Window already has a tab in it. If it does, then
+ you need to add this tab and not run SetChild() on the window
+ or instead it replaces the existing tab with the new one
+
+ I work around this by always sending a Toolkit that is a tab
+ 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(name string) *andlabsT {
+ // var w *ui.Window
+ var newt *andlabsT
+
+ log.Println("gui.toolkit.AddTab() sleep 3")
+
+ if (t.uiWindow == nil) {
+ log.Println("gui.Toolkit.UiWindow == nil. I can't add a toolbar without window")
+ return nil
+ }
+
+ if (t.uiTab == nil) {
+ // this means you have to make a new tab
+ log.Println("gui.toolkit.NewTab() GOOD. This should be the first tab:", name)
+ newt = newTab(t.uiWindow, name)
+ t.uiTab = newt.uiTab
+ } else {
+ // this means you have to append a tab
+ log.Println("gui.toolkit.NewTab() GOOD. This should be an additional tab:", name)
+ newt = t.appendTab(name)
+ }
+
+ newt.Name = name
+
+ if (DebugToolkit) {
+ log.Println("t:")
+ t.Dump()
+ log.Println("newt:")
+ newt.Dump()
+ }
+
+ return newt
+}
+
+// This sets _all_ the tabs to Margin = true
+//
+// TODO: do proper tab tracking (will be complicated). low priority
+func tabSetMargined(tab *ui.Tab) {
+ c := tab.NumPages()
+ for i := 0; i < c; i++ {
+ if (DebugToolkit) {
+ log.Println("SetMargined", i, margin)
+ }
+ tab.SetMargined(i, margin)
+ }
+}
+
+func newTab(w *ui.Window, name string) *andlabsT {
+ var t andlabsT
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.NewTab() ADD", name)
+ }
+
+ if (w == nil) {
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ log.Println("gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
+ time.Sleep(1 * time.Second)
+ return nil
+ }
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.AddTab() START name =", name)
+ }
+ tab := ui.NewTab()
+ w.SetMargined(margin)
+
+ hbox := ui.NewHorizontalBox() // this makes everything go along the horizon
+ hbox.SetPadded(padded)
+ tab.Append(name, hbox)
+ tabSetMargined(tab) // TODO: run this in the right place(?)
+ w.SetChild(tab)
+
+ t.uiWindow = w
+ t.uiTab = tab
+ t.uiBox = hbox
+ return &t
+}
+
+func (t *andlabsT) appendTab(name string) *andlabsT {
+ var newT andlabsT
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.NewTab() ADD", name)
+ }
+
+ if (t.uiTab == nil) {
+ log.Println("gui.Toolkit.UiWindow == nil. I can't add a widget without a place to put it")
+ panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
+ }
+ if (DebugToolkit) {
+ log.Println("gui.toolkit.AddTab() START name =", name)
+ }
+
+ var hbox *ui.Box
+ if (defaultBehavior) {
+ hbox = ui.NewHorizontalBox()
+ } else {
+ if (bookshelf) {
+ hbox = ui.NewHorizontalBox()
+ } else {
+ hbox = ui.NewVerticalBox()
+ }
+ }
+ hbox.SetPadded(padded)
+ t.uiTab.Append(name, hbox)
+
+ newT.uiWindow = t.uiWindow
+ newT.uiTab = t.uiTab
+ newT.uiBox = hbox
+ return &newT
+}
+
+func NewTab(parentW *toolkit.Widget, w *toolkit.Widget) {
+ var newt *andlabsT
+ log.Println("gui.andlabs.NewTab()", w.Name)
+
+ t := mapToolkits[parentW]
+ if (t == nil) {
+ log.Println("go.andlabs.NewTab() toolkit struct == nil. name=", parentW.Name, w.Name)
+ return
+ }
+ newt = t.newTab(w.Name)
+ mapWidgetsToolkits(w, newt)
+}