summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/common.go
blob: 94e19e1b034b41802a7d196f2de77824afb489be (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
package main

// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func init() {
	// Can you pass values to a plugin init() ? Otherwise, there is no way to safely print
	// log(debugToolkit, "gui/toolkit init() Setting defaultBehavior = true")
	setDefaultBehavior(true)
}

func (t andlabsT) commonChange(widget string) {
	s := t.String()
	log(debugChange, "commonChange() START widget   =", widget)
	log(debugChange, "commonChange() t.String =", s)
	if (t.OnChanged != nil) {
		// log(debugChange, "commonChange() toolkit.OnChanged() START")
		// t.OnChanged(&t)
		exit("OnChanged is not implemented. TODO: FIX THIS")
		return
	}
	if (t.Custom != nil) {
		log(debugChange, "commonChange() START toolkit.Custom()")
		t.Custom()
		log(debugChange, "commonChange() END toolkit.Custom()")
		return
	}
	if (widget == "Checkbox") {
		log(debugChange, "commonChange() END Need to read the Checkbox value")
		return
	}
	if (widget == "Dropdown") {
		t.getDropdown()
		if (t.tw == nil) {
			log(debugChange, "commonChange() END tw.Custom == nil")
		}
		if (t.tw.Custom == nil) {
			log(debugChange, "commonChange() END Dropdown (no custom())")
		}
		t.tw.Custom()
		log(debugChange, "commonChange() END Dropdown")
		return
	}
	log(debugChange, "commonChange() t.String =", s)
	log(debugChange, "commonChange() ENDED without finding any callback")
}

func (t *andlabsT) getDropdown() {
	log(debugChange, "commonChange() Need to read the dropdown menu")
	if (t.uiCombobox == nil) {
		log(debugChange, "commonChange() END BAD NEWS. t.uiCombobox == nil")
		return
	}
	i := t.uiCombobox.Selected()
	log(debugChange, "commonChange() t.uiCombobox = ", i)
	if (t.tw == nil) {
		log(debugChange, "commonChange() END tw = nil")
		return
	}
	t.tw.S = t.String()
	log(debugChange, "commonChange() END tw = ", t.tw)
	return
}

// does some sanity checks on the internal structs of the binary tree
// TODO: probably this should not panic unless it's running in devel mode (?)
func (t *andlabsT) broken() bool {
	if (t.uiBox == nil) {
		if (t.uiWindow != nil) {
			log(debugToolkit, "gui.Toolkit.UiBox == nil. This is an empty window. Try to add a box")
			t.NewBox()
			return false
		}
		log(debugToolkit, "gui.Toolkit.UiBox == nil. I can't add a widget without a place to put it")
		// log(debugToolkit, "probably could just make a box here?")
		// corruption or something horrible?
		panic("wit/gui toolkit/andlabs func broken() invalid goroutine access into this toolkit?")
		panic("wit/gui toolkit/andlabs func broken() this probably should not cause the app to panic here (?)")
		return true
	}
	if (t.uiWindow == nil) {
		log(debugToolkit, "gui.Toolkit.UiWindow == nil. I can't add a widget without a place to put it (IGNORING FOR NOW)")
		forceDump(t)
		return false
	}
	return false
}