summaryrefslogtreecommitdiff
path: root/tab.go
blob: e684df9453a2a32ddfb35dad89ed6fc8ebebc60d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main

import (
	"go.wit.com/log"

	"go.wit.com/dev/andlabs/ui"
	_ "go.wit.com/dev/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 (p *node) newTab(n *node) {
	var newt *guiWidget

	if p == nil {
		log.Log(ERROR, "newTab() p == nil. how the fuck does this happen?", n.WidgetId, n.ParentId)
	}
	if p.WidgetType != widget.Window {
		log.Log(ERROR, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
		return
	}
	t := p.tk

	log.Log(ANDLABS, "newTab() START", n.WidgetId, n.ParentId)

	if t.uiTab == nil {
		// this means you have to make a new tab
		log.Log(ANDLABS, "newTab() GOOD. This should be the first tab:", n.WidgetId, n.ParentId)
		newt = rawTab(t.uiWindow, widget.GetString(n.value))
		t.uiTab = newt.uiTab
	} else {
		// this means you have to append a tab
		log.Log(ANDLABS, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
		if n.WidgetType == widget.Tab {
			// 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 {
			newt = t.appendTab(widget.GetString(n.value))
		}
	}

	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++ {
		log.Log(ANDLABS, "SetMargined", i, b)
		tab.SetMargined(i, b)
	}
}

func rawTab(w *ui.Window, name string) *guiWidget {
	var newt guiWidget
	log.Log(ANDLABS, "rawTab() START", name)

	if w == nil {
		log.Log(ERROR, "UiWindow == nil. I can't add a tab without a window")
		// sleep(1)
		return nil
	}

	tab := ui.NewTab()
	w.SetChild(tab)
	newt.uiTab = tab
	newt.uiControl = tab
	log.Log(ANDLABS, "rawTab() END", name)
	return &newt
}

/*
func (t *guiWidget) appendTab(name string) *guiWidget {
	var newT guiWidget
	log.Log(ANDLABS, "appendTab() ADD", name)

	if t.uiTab == nil {
		log.Log(ANDLABS, "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")
	}
	log.Log(ANDLABS, "appendTab() 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
}
*/