EXAMPLE: correctly add a tab to the example app

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2021-10-25 05:25:10 -05:00
parent 585e7f00f0
commit 9a07e2b2af
5 changed files with 24 additions and 11 deletions

View File

@ -26,7 +26,8 @@ func main() {
}
func initGUI() {
gui.NewWindow("jcarr start", 640, 480)
n := gui.NewWindow("jcarr start", 640, 480)
n.AddDemoTab("up the rabbit hole")
}
func watchGUI() {
@ -35,7 +36,7 @@ func watchGUI() {
log.Println("Waiting for customExit()", i)
i += 1
time.Sleep(1 * time.Second)
if i == 2 {
if i == 4 {
log.Println("Sending ExampleWindow to gui.Queue()")
gui.Queue(gui.DebugWindow)
}

2
gui.go
View File

@ -24,6 +24,8 @@ func init() {
Config.counter = 0
Config.prefix = "jwc"
Config.DebugNode = false
Config.DebugTabs = false
}
func GuiInit() {

View File

@ -23,6 +23,8 @@ type GuiConfig struct {
Width int
Height int
Debug bool
DebugNode bool
DebugTabs bool
DebugTable bool
Exit func(*GuiWindow)

View File

@ -356,15 +356,11 @@ func addButton(box *ui.Box, name string) *ui.Button {
return button
}
func (n *Node) AddDemoTab(title string) {
newNode := n.AddTab(title, makeWindowTemplate())
newNode.Dump()
tabSetMargined(newNode.uiTab)
}
func (n *Node) AddDebugTab(title string) {
newNode := n.AddTab(title, makeWindowDebug())
newNode.Dump()
if (Config.DebugNode) {
newNode.Dump()
}
tabSetMargined(newNode.uiTab)
}
@ -372,10 +368,14 @@ func (n *Node) AddDebugTab(title string) {
//
// TODO: do proper tab tracking (will be complicated). low priority
func tabSetMargined(tab *ui.Tab) {
log.Println("tabSetMargined() IGNORE THIS")
if (Config.DebugTabs) {
log.Println("tabSetMargined() IGNORE THIS")
}
c := tab.NumPages()
for i := 0; i < c; i++ {
log.Println("tabSetMargined() i =", i)
if (Config.DebugTabs) {
log.Println("tabSetMargined() i =", i)
}
tab.SetMargined(i, true)
}
}

View File

@ -4,6 +4,14 @@ import "log"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
func (n *Node) AddDemoTab(title string) {
newNode := n.AddTab(title, makeWindowTemplate())
if (Config.DebugNode) {
newNode.Dump()
}
tabSetMargined(newNode.uiTab)
}
func makeWindowTemplate() ui.Control {
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)