blob: 92ddeadceb86a169e81bdbae95449d38e73e7e72 (
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
|
// 12 february 2014
package main
import (
"fmt"
"sync"
)
// A Button represents a clickable button with some text.
type Button struct {
// This channel gets a message when the button is clicked. Unlike other channels in this package, this channel is initialized to non-nil when creating a new button, and cannot be set to nil later.
Clicked chan struct{}
lock sync.Mutex
created bool
parent Control
sysData *sysData
initText string
}
// NewButton creates a new button with the specified text.
func NewButton(text string) (b *Button) {
return &Button{
sysData: &sysData{
cSysData: cSysData{
ctype: c_button,
},
},
initText: text,
Clicked: make(chan struct{}),
}
}
// SetText sets the button's text.
func (b *Button) SetText(text string) (err error) {
b.lock.Lock()
defer b.lock.Unlock()
if b.pWin != nil && b.pWin.created {
panic("TODO")
}
b.initText = text
return nil
}
func (b *Button) apply(window *sysData) error {
b.lock.Lock()
defer b.lock.Unlock()
b.sysData.event = b.Clicked
return b.sysData.make(b.initText, 300, 300, window)
// TODO size to parent size
}
func (b *Button) setParent(c Control) {
b.parent = c
}
|