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
|
|
|
|
*/
|
2023-03-29 23:03:04 -05:00
|
|
|
func (t *andlabsT) newTab(a *toolkit.Action) {
|
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-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "newTab() START", a.WidgetId, a.ParentId)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
if (t.uiTab == nil) {
|
2023-03-29 23:03:04 -05:00
|
|
|
if (t.uiWindow == nil) {
|
|
|
|
log(debugToolkit, "newTab() uiWindow == nil. I can't add a toolbar without window", a.WidgetId, a.ParentId)
|
|
|
|
return
|
|
|
|
}
|
2022-10-19 13:23:22 -05:00
|
|
|
// this means you have to make a new tab
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "newTab() GOOD. This should be the first tab:", a.WidgetId, a.ParentId)
|
|
|
|
newt = rawTab(t.uiWindow, a.Text)
|
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-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", a.WidgetId, a.ParentId)
|
|
|
|
newt = t.appendTab(a.Text)
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
// add the structure to the array
|
|
|
|
if (andlabs[a.WidgetId] == nil) {
|
|
|
|
log(logInfo, "newTab() MAPPED", a.WidgetId, a.ParentId)
|
|
|
|
andlabs[a.WidgetId] = newt
|
2023-04-03 10:26:47 -05:00
|
|
|
newt.WidgetType = a.WidgetType
|
2023-03-29 23:03:04 -05:00
|
|
|
} else {
|
|
|
|
log(debugError, "newTab() DO WHAT?", a.WidgetId, a.ParentId)
|
|
|
|
log(debugError, "THIS IS BAD")
|
|
|
|
}
|
|
|
|
|
|
|
|
newt.Name = a.Name
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "t:")
|
2023-03-01 11:35:36 -06:00
|
|
|
t.Dump(debugToolkit)
|
2023-02-25 14:05:25 -06:00
|
|
|
log(debugToolkit, "newt:")
|
2023-03-01 11:35:36 -06:00
|
|
|
newt.Dump(debugToolkit)
|
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
|
2023-03-23 12:35:12 -05:00
|
|
|
func tabSetMargined(tab *ui.Tab, b bool) {
|
2022-10-19 13:23:22 -05:00
|
|
|
c := tab.NumPages()
|
|
|
|
for i := 0; i < c; i++ {
|
2023-03-23 12:35:12 -05:00
|
|
|
log(debugToolkit, "SetMargined", i, b)
|
|
|
|
tab.SetMargined(i, b)
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-01 11:35:36 -06:00
|
|
|
func rawTab(w *ui.Window, name string) *andlabsT {
|
2023-03-03 14:41:38 -06:00
|
|
|
var newt andlabsT
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "rawTab() START", name)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
|
|
|
if (w == nil) {
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugError, "UiWindow == nil. I can't add a tab without a window")
|
|
|
|
log(debugError, "UiWindow == nil. I can't add a tab without a window")
|
|
|
|
log(debugError, "UiWindow == nil. I can't add a tab without a window")
|
2023-02-25 14:05:25 -06:00
|
|
|
sleep(1)
|
2022-10-19 13:23:22 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
tab := ui.NewTab()
|
2022-10-19 13:23:22 -05:00
|
|
|
w.SetChild(tab)
|
2023-03-03 14:41:38 -06:00
|
|
|
newt.uiTab = tab
|
2023-03-23 12:35:12 -05:00
|
|
|
newt.uiControl = tab
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "rawTab() END", name)
|
2023-03-03 14:41:38 -06:00
|
|
|
return &newt
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
func newTab(a *toolkit.Action) {
|
2023-03-29 23:03:04 -05:00
|
|
|
// w := a.Widget
|
|
|
|
log(debugToolkit, "newTab()", a.ParentId)
|
2022-11-14 14:30:28 -06:00
|
|
|
|
2023-03-29 23:03:04 -05:00
|
|
|
t := andlabs[a.ParentId]
|
2022-11-14 14:30:28 -06:00
|
|
|
if (t == nil) {
|
2023-03-29 23:03:04 -05:00
|
|
|
log(debugToolkit, "newTab() parent toolkit == nil. new tab can not be made =", a.ParentId)
|
|
|
|
log(debugToolkit, "look for a window? check for an existing tab?")
|
2022-11-14 14:30:28 -06:00
|
|
|
return
|
|
|
|
}
|
2023-03-29 23:03:04 -05:00
|
|
|
t.newTab(a)
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|