2022-11-14 14:30:28 -06:00
|
|
|
package main
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
import (
|
2022-11-14 14:30:28 -06:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
"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
|
|
|
|
*/
|
2022-11-14 14:30:28 -06:00
|
|
|
func (t *andlabsT) newTab(name string) *andlabsT {
|
2022-10-21 11:40:08 -05:00
|
|
|
// var w *ui.Window
|
2022-11-14 14:30:28 -06:00
|
|
|
var newt *andlabsT
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.AddTab()")
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
if (t.uiWindow == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.Toolkit.UiWindow == nil. I can't add a toolbar without window")
|
2022-10-19 13:23:22 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t.uiTab == nil) {
|
|
|
|
// this means you have to make a new tab
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.NewTab() GOOD. This should be the first tab:", name)
|
2022-10-21 11:40:08 -05:00
|
|
|
newt = newTab(t.uiWindow, name)
|
2022-10-19 13:23:22 -05:00
|
|
|
t.uiTab = newt.uiTab
|
|
|
|
} else {
|
2022-10-21 11:40:08 -05:00
|
|
|
// this means you have to append a tab
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.NewTab() GOOD. This should be an additional tab:", name)
|
2022-10-19 13:23:22 -05:00
|
|
|
newt = t.appendTab(name)
|
|
|
|
}
|
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
newt.Name = name
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "t:")
|
|
|
|
t.Dump()
|
|
|
|
log(debugToolkit, "newt:")
|
|
|
|
newt.Dump()
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
return newt
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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++ {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "SetMargined", i, margin)
|
2022-10-21 11:40:08 -05:00
|
|
|
tab.SetMargined(i, margin)
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
func newTab(w *ui.Window, name string) *andlabsT {
|
|
|
|
var t andlabsT
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.NewTab() ADD", name)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
if (w == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
|
|
|
|
log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
|
|
|
|
log(debugToolkit, "gui.toolkit.NewTab() node.UiWindow == nil. I can't add a tab without a window")
|
|
|
|
sleep(1)
|
2022-10-19 13:23:22 -05:00
|
|
|
return nil
|
|
|
|
}
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.AddTab() START name =", name)
|
2022-10-19 13:23:22 -05:00
|
|
|
tab := ui.NewTab()
|
2022-10-21 11:40:08 -05:00
|
|
|
w.SetMargined(margin)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
hbox := ui.NewHorizontalBox() // this makes everything go along the horizon
|
2022-10-21 11:40:08 -05:00
|
|
|
hbox.SetPadded(padded)
|
2022-10-19 13:23:22 -05:00
|
|
|
tab.Append(name, hbox)
|
2022-10-21 11:40:08 -05:00
|
|
|
tabSetMargined(tab) // TODO: run this in the right place(?)
|
2022-10-19 13:23:22 -05:00
|
|
|
w.SetChild(tab)
|
|
|
|
|
|
|
|
t.uiWindow = w
|
|
|
|
t.uiTab = tab
|
|
|
|
t.uiBox = hbox
|
|
|
|
return &t
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:30:28 -06:00
|
|
|
func (t *andlabsT) appendTab(name string) *andlabsT {
|
|
|
|
var newT andlabsT
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.NewTab() ADD", name)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
if (t.uiTab == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.Toolkit.UiWindow == nil. I can't add a widget without a place to put it")
|
2022-10-21 11:40:08 -05:00
|
|
|
panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.toolkit.AddTab() START name =", name)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2022-10-21 11:40:08 -05:00
|
|
|
var hbox *ui.Box
|
|
|
|
if (defaultBehavior) {
|
|
|
|
hbox = ui.NewHorizontalBox()
|
|
|
|
} else {
|
|
|
|
if (bookshelf) {
|
|
|
|
hbox = ui.NewHorizontalBox()
|
|
|
|
} else {
|
|
|
|
hbox = ui.NewVerticalBox()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hbox.SetPadded(padded)
|
2022-10-19 13:23:22 -05:00
|
|
|
t.uiTab.Append(name, hbox)
|
|
|
|
|
|
|
|
newT.uiWindow = t.uiWindow
|
|
|
|
newT.uiTab = t.uiTab
|
|
|
|
newT.uiBox = hbox
|
|
|
|
return &newT
|
|
|
|
}
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
func NewTab(parentW *toolkit.Widget, w *toolkit.Widget) {
|
|
|
|
var newt *andlabsT
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "gui.andlabs.NewTab()", w.Name)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
|
|
|
t := mapToolkits[parentW]
|
|
|
|
if (t == nil) {
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "go.andlabs.NewTab() toolkit struct == nil. name=", parentW.Name, w.Name)
|
2022-11-14 14:30:28 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
newt = t.newTab(w.Name)
|
|
|
|
mapWidgetsToolkits(w, newt)
|
|
|
|
}
|