summaryrefslogtreecommitdiff
path: root/tab.go
blob: 463944e4bff55d225ee50b8a8eebf4ced278563e (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
package gui

import (
	"go.wit.com/gui/gui/toolkit"
)

// This function should make a new node with the parent and
// the 'tab' as a child

func (n *Node) NewTab(text string) *Node {
	// check to make sure n is actually a window

	if (n.WidgetType != toolkit.Window) {
		// figure out what the actual window is
		log(logError, "NewTab() is being requested on something that isn't a Window. node =", n)
		if (n.parent == nil) {
			// TODO: find a window. any window. never give up. never die.
			log(logError, "NewTab() TODO: make a window here", n)
			panic("NewTab did not get passed a window")
		}
		log(logError, "NewTab() parent =", n.parent)
		if (n.parent.WidgetType == toolkit.Root) {
			// also broken
			log(logError, "NewTab() TODO: make or find a window here", n)
			panic("NewTab() did not get passed a window")
		}
		// go up the binary tree until we find a window widget to add a tab too
		return n.parent.NewTab(text)
	}
	newNode := n.newNode(text, toolkit.Tab)

	a := newAction(newNode, toolkit.Add)
	sendAction(a)

	// by default, create a box inside the tab
	// TODO: allow this to be configurable
	newBox := newNode.NewBox(text + " box", true)

	return newBox
}