summaryrefslogtreecommitdiff
path: root/toolkit/gocui/tab.go
blob: dc0566c58c961d1139bcf5fdc1c0c0a114d1d4b7 (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

// implements widgets 'Window' and 'Tab'

import (
	"git.wit.org/wit/gui/toolkit"
//	"github.com/awesome-gocui/gocui"
)

func (w *cuiWidget) hideWidgets() {
	switch w.widgetType {
	case toolkit.Root:
	case toolkit.Flag:
	case toolkit.Window:
	case toolkit.Tab:
	case toolkit.Box:
	case toolkit.Grid:
	default:
		w.deleteView()
	}
	for _, child := range w.children {
		child.hideWidgets()
	}
}

func (w *cuiWidget) hideFake() {
	if (w.isFake) {
		w.deleteView()
	}
	for _, child := range w.children {
		child.hideFake()
	}
}

func (w *cuiWidget) showFake() {
	if (w.isFake) {
		w.setFake()
		w.showWidgetPlacement(logNow, "showFake:")
		w.drawView()
	}
	for _, child := range w.children {
		child.showFake()
	}
}

func (w *cuiWidget) showWidgets() {
	if (w.isFake) {
		// don't display by default
	} else {
		w.drawView()
	}
	for _, child := range w.children {
		child.showWidgets()
	}
}

func (w *cuiWidget) setTabWH() {
	// set the start and size of the tab gocui button
	if w.frame {
		// this means it should work like a tab
		w.gocuiSize.w0 = me.rootNode.nextW
		w.gocuiSize.h0 = me.TabH
	} else {
		// this means it should just be a window label
		w.gocuiSize.w0 = me.rootNode.nextW
		w.gocuiSize.h0 = me.WindowH
	}

	t := len(w.text)
	w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW
	w.gocuiSize.h1 = w.gocuiSize.h0 + me.DefaultHeight + me.PadH

	w.realWidth = w.gocuiSize.Width()
	w.realHeight = w.gocuiSize.Height()

	if w.frame {
		w.realWidth += me.FramePadW
		w.realHeight += me.FramePadH

		// move the rootNode width over for the next tab
		me.rootNode.nextW += w.realWidth + me.TabPadW
	} else {
		// move the rootNode width over for the next window
		me.rootNode.nextW += w.realWidth + me.WindowPadW
	}

	w.showWidgetPlacement(logNow, "setTabWH:")
}

func (w *cuiWidget) redoTabs(draw bool) {
	if (w.widgetType == toolkit.Window) {
		var tabs bool = false
		// figure out if the window is just a bunch of tabs
		for _, child := range w.children {
			if (child.widgetType == toolkit.Tab) {
				tabs = true
			}
		}
		if (tabs) {
			// window is tabs. Don't show it as a standard button
			w.frame = false
		} else {
			w.frame = true
		}
		w.setTabWH()
		w.deleteView()
		w.drawView()
	}
	if (w.widgetType == toolkit.Tab) {
		w.setTabWH()
		w.deleteView()
		w.drawView()
	}

	for _, child := range w.children {
		child.redoTabs(draw)
	}
}