summaryrefslogtreecommitdiff
path: root/smartwindow/postReady.go
blob: 99349ff5add5be3d12b0166883c7785ef7360056 (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
// This creates a 'smart window'
// it should work even when it is hidden
// from the gui toolkit plugins
package smartwindow

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

/*
	all these functions run after the window is Ready()
	so they should all start with that check
*/

// reports externally if something has changed
// since the last time it was asked about it
func (sw *SmartWindow) Changed() bool {
	if ! sw.Ready() {return false}

	if sw.changed {
		sw.changed = false
		return true
	}
	return false
}

func (sw *SmartWindow) Show() {
	if ! sw.Ready() {return}

	log.Log(WARN, "Show() window ready =", sw.ready)
	sw.window.Show()
	sw.hidden = false
}

func (sw *SmartWindow) Hide() {
	if ! sw.Ready() {return}

	log.Log(WARN, "Hide() window ready =", sw.ready)
	sw.window.Hide()
	sw.hidden = true
}

func (sw *SmartWindow) Toggle() {
	if ! sw.Ready() {return}

	log.Log(WARN, "Toggle() window ready =", sw.ready)
	if sw.hidden {
		sw.Show()
	} else {
		sw.Hide()
	}
}

func (sw *SmartWindow) Box() *gui.Node {
	if ! sw.Ready() {return nil}

	return sw.box
}

func (sw *SmartWindow) Draw() {
	if ! sw.Ready() {return}

	log.Log(WARN, "Draw() window ready")
	sw.window.Draw()

	if sw.vertical {
		sw.box = sw.window.NewBox("bw vbox", false)
		log.Log(WARN, "BasicWindow.Custom() made vbox")
	} else {
		sw.box = sw.window.NewBox("bw hbox", true)
		log.Log(WARN, "BasicWindow.Custom() made hbox")
	}
	if (sw.populate != nil) {
		log.Log(WARN, "Make() trying to run Custom sw.populate() here")
		sw.populate(sw)
	}
}