2024-01-01 16:11:54 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-01-08 21:19:42 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-05 13:30:00 -06:00
|
|
|
"go.wit.com/gui/widget"
|
2024-01-01 16:11:54 -06:00
|
|
|
|
2024-01-15 16:11:40 -06:00
|
|
|
"go.wit.com/dev/andlabs/ui"
|
|
|
|
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
2024-01-01 16:11:54 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
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 (p *node) newTab(n *node) {
|
|
|
|
var newt *guiWidget
|
|
|
|
|
|
|
|
if (p == nil) {
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(ERROR, "newTab() p == nil. how the fuck does this happen?", n.WidgetId, n.ParentId)
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
2024-01-05 13:30:00 -06:00
|
|
|
if (p.WidgetType != widget.Window) {
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(ERROR, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
|
2024-01-01 16:11:54 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
t := p.tk
|
|
|
|
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "newTab() START", n.WidgetId, n.ParentId)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
if (t.uiTab == nil) {
|
|
|
|
// this means you have to make a new tab
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
|
2024-01-16 12:55:20 -06:00
|
|
|
newt = rawTab(t.uiWindow, widget.GetString(n.value))
|
2024-01-01 16:11:54 -06:00
|
|
|
t.uiTab = newt.uiTab
|
|
|
|
} else {
|
|
|
|
// this means you have to append a tab
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
|
2024-01-05 13:30:00 -06:00
|
|
|
if (n.WidgetType == widget.Tab) {
|
2024-01-01 16:11:54 -06:00
|
|
|
// andlabs doesn't have multiple tab widgets so make a fake one?
|
|
|
|
// this makes a guiWidget internal structure with the parent values
|
|
|
|
newt = new(guiWidget)
|
|
|
|
newt.uiWindow = t.uiWindow
|
|
|
|
newt.uiTab = t.uiTab
|
|
|
|
} else {
|
2024-01-16 12:55:20 -06:00
|
|
|
newt = t.appendTab(widget.GetString(n.value))
|
2024-01-01 16:11:54 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n.tk = newt
|
|
|
|
}
|
|
|
|
|
|
|
|
// This sets _all_ the tabs to Margin = true
|
|
|
|
//
|
|
|
|
// TODO: do proper tab tracking (will be complicated). low priority
|
|
|
|
func tabSetMargined(tab *ui.Tab, b bool) {
|
|
|
|
c := tab.NumPages()
|
|
|
|
for i := 0; i < c; i++ {
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "SetMargined", i, b)
|
2024-01-01 16:11:54 -06:00
|
|
|
tab.SetMargined(i, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func rawTab(w *ui.Window, name string) *guiWidget {
|
|
|
|
var newt guiWidget
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "rawTab() START", name)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
if (w == nil) {
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
|
|
|
|
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
|
|
|
|
log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
|
2024-01-01 16:11:54 -06:00
|
|
|
// sleep(1)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
tab := ui.NewTab()
|
|
|
|
w.SetChild(tab)
|
|
|
|
newt.uiTab = tab
|
|
|
|
newt.uiControl = tab
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "rawTab() END", name)
|
2024-01-01 16:11:54 -06:00
|
|
|
return &newt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *guiWidget) appendTab(name string) *guiWidget {
|
|
|
|
var newT guiWidget
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "appendTab() ADD", name)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
if (t.uiTab == nil) {
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "UiWindow == nil. I can't add a widget without a place to put it")
|
2024-01-01 16:11:54 -06:00
|
|
|
panic("should never have happened. wit/gui/toolkit has ui.Tab == nil")
|
|
|
|
}
|
2024-01-08 21:19:42 -06:00
|
|
|
log.Log(TOOLKIT, "appendTab() START name =", name)
|
2024-01-01 16:11:54 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|