summaryrefslogtreecommitdiff
path: root/label.go
blob: df33a5a00fc2b80a0270e8db5168dc8799176c39 (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
package gui

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

func (parent *Node) NewLabel(text string) *Node {
	newNode := parent.newNode(text, widget.Label)
	newNode.label = text
	newNode.progname = text

	// inform the toolkits
	sendAction(newNode, widget.Add)
	return newNode
}

// an experiemental idea
// basically, this is like a cell in a spreadsheet that is viable
// in one place but also exists sonewhere else
func (parent *Node) Mirror(m *Node) *Node {
	switch m.WidgetType {
	case widget.Label:
		text := m.label
		newNode := parent.newNode(text, widget.Label)
		newNode.label = text
		newNode.progname = text
		newNode.isMirror = m
		m.hasMirrors = append(m.hasMirrors, newNode)

		// inform the toolkits
		sendAction(newNode, widget.Add)
		return newNode
	default:
		return nil
	}
}

// make a mirror widget without a parent
func RawMirror(m *Node) *Node {
	switch m.WidgetType {
	case widget.Label:
		newNode := rawNode("MIRROR", widget.Label)
		newNode.isMirror = m
		m.hasMirrors = append(m.hasMirrors, newNode)
		return newNode
	default:
		return nil
	}
}

func (n *Node) IsMirror() bool {
	if n.isMirror == nil {
		return false
	}
	return true
}

func (n *Node) hasMirror() bool {
	if len(n.hasMirrors) == 0 {
		return false
	}
	return true
}

func (n *Node) updateMirrors() {
	if n.IsMirror() {
		// n is a mirror of something else
		return
	}
	for _, m := range n.hasMirrors {
		switch m.WidgetType {
		case widget.Label:
			m.label = n.label
			m.changed = true
			// inform the toolkits
			sendAction(m, widget.SetText)
		default:
			log.Log(WARN, "can not mirror widget type", m.WidgetType)
		}
	}
}