forked from lxn/walk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.go
99 lines (73 loc) · 1.94 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package walk
import "github.com/lxn/win"
type EllipsisMode int
const (
EllipsisNone EllipsisMode = 0
EllipsisEnd = EllipsisMode(win.SS_ENDELLIPSIS)
EllipsisPath = EllipsisMode(win.SS_PATHELLIPSIS)
)
type Label struct {
static
textChangedPublisher EventPublisher
}
func NewLabel(parent Container) (*Label, error) {
return NewLabelWithStyle(parent, 0)
}
func NewLabelWithStyle(parent Container, style uint32) (*Label, error) {
l := new(Label)
if err := l.init(l, parent); err != nil {
return nil, err
}
l.SetTextAlignment(AlignNear)
l.MustRegisterProperty("Text", NewProperty(
func() interface{} {
return l.Text()
},
func(v interface{}) error {
return l.SetText(assertStringOr(v, ""))
},
l.textChangedPublisher.Event()))
return l, nil
}
func (l *Label) asStatic() *static {
return &l.static
}
func (l *Label) EllipsisMode() EllipsisMode {
return EllipsisMode(win.GetWindowLong(l.hwndStatic, win.GWL_STYLE) & (win.SS_ENDELLIPSIS | win.SS_PATHELLIPSIS))
}
func (l *Label) SetEllipsisMode(mode EllipsisMode) error {
oldMode := l.EllipsisMode()
if mode == oldMode {
return nil
}
if err := setAndClearWindowLongBits(l.hwndStatic, win.GWL_STYLE, uint32(mode), uint32(oldMode)); err != nil {
return err
}
l.RequestLayout()
return nil
}
func (l *Label) TextAlignment() Alignment1D {
return l.textAlignment1D()
}
func (l *Label) SetTextAlignment(alignment Alignment1D) error {
if alignment == AlignDefault {
alignment = AlignNear
}
return l.setTextAlignment1D(alignment)
}
func (l *Label) Text() string {
return l.text()
}
func (l *Label) SetText(text string) error {
if changed, err := l.setText(text); err != nil {
return err
} else if !changed {
return nil
}
l.textChangedPublisher.Publish()
return nil
}