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

import (
	"git.wit.org/wit/gui/toolkit"
	"github.com/andlabs/ui"
	_ "github.com/andlabs/ui/winmanifest"
)

func (t *andlabsT) newCheckbox(w *toolkit.Widget) *andlabsT {
	log(debugToolkit, "newCheckbox()", w.Name, w.Type)
	var newt andlabsT
	newt.tw = w

	if t.broken() {
		return nil
	}

	newt.uiCheckbox = ui.NewCheckbox(w.Name)
	newt.uiBox = t.uiBox
	// t.doAppend(&newt, *newt.uiCheckbox)
	t.uiBox.Append(newt.uiCheckbox, stretchy)

	newt.uiCheckbox.OnToggled(func(spin *ui.Checkbox) {
		newt.tw.B = newt.checked()
		log(debugChange, "val =", newt.tw.B)
		newt.commonChange(newt.tw)
	})

	return &newt
}

func (t *andlabsT) checked() bool {
	if t.broken() {
		return false
	}

	return t.uiCheckbox.Checked()
}

func newCheckbox(parentW *toolkit.Widget, w *toolkit.Widget) {
	log(debugToolkit, "newCheckbox()", w.Name)

	t := mapToolkits[parentW]
	if (t == nil) {
		listMap(debugError)
		return
	}
	newt := t.newCheckbox(w)
	mapWidgetsToolkits(w, newt)
}

func doCheckbox(p *toolkit.Widget, c *toolkit.Widget) {
	if broken(c) {
		return
	}
	if (c.Action == "New") {
		newCheckbox(p, c)
		return
	}
	ct := mapToolkits[c]
	if (ct == nil) {
		log(true, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
		return
	}
	if ct.broken() {
		log(true, "checkbox() ct.broken", ct)
		return
	}
	if (ct.uiCheckbox == nil) {
		log(true, "checkbox() uiCheckbox == nil", ct)
		return
	}
	log(debugChange, "Going to attempt:", c.Action)
	switch c.Action {
	case "Enable":
		ct.uiCheckbox.Enable()
	case "Disable":
		ct.uiCheckbox.Disable()
	case "Show":
		ct.uiCheckbox.Show()
	case "Hide":
		ct.uiCheckbox.Hide()
	case "SetText":
		ct.uiCheckbox.SetText(c.S)
	case "Set":
		ct.uiCheckbox.SetChecked(c.B)
	default:
		log(debugError, "Can't do", c.Action, "to a checkbox")
	}
}