-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathlabel.go
80 lines (66 loc) · 1.49 KB
/
label.go
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
//+build windows
package wui
import "github.com/gonutz/w32/v2"
func NewLabel() *Label {
return &Label{}
}
type Label struct {
textControl
alignment TextAlignment
}
var _ Control = (*Label)(nil)
func (*Label) canFocus() bool {
return false
}
func (*Label) eatsTabs() bool {
return false
}
type TextAlignment int
const (
AlignLeft TextAlignment = iota
AlignCenter
AlignRight
)
func (a TextAlignment) String() string {
// NOTE that these strings are used in the designer to get their
// representations as Go code so they must always correspond to their
// constant names and be prefixed with the package name.
switch a {
case AlignLeft:
return "wui.AlignLeft"
case AlignCenter:
return "wui.AlignCenter"
case AlignRight:
return "wui.AlignRight"
default:
return "unknown TextAlignment"
}
}
func (l *Label) create(id int) {
l.textControl.create(id, 0, "STATIC", w32.SS_CENTERIMAGE|alignStyle(l.alignment))
}
func alignStyle(a TextAlignment) uint {
if a == AlignCenter {
return w32.SS_CENTER
}
if a == AlignRight {
return w32.SS_RIGHT
}
return w32.SS_LEFT
}
func (l *Label) SetAlignment(a TextAlignment) {
l.alignment = a
if l.handle != 0 {
style := uint(w32.GetWindowLongPtr(l.handle, w32.GWL_STYLE))
style = style &^ w32.SS_LEFT &^ w32.SS_CENTER &^ w32.SS_RIGHT
w32.SetWindowLongPtr(
l.handle,
w32.GWL_STYLE,
uintptr(style|alignStyle(l.alignment)),
)
w32.InvalidateRect(l.handle, nil, true)
}
}
func (l *Label) Alignment() TextAlignment {
return l.alignment
}