/
label.go
96 lines (78 loc) · 2.42 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
package widget
import (
"image/color"
"fyne.io/fyne"
"fyne.io/fyne/theme"
)
// Label widget is a label component with appropriate padding and layout.
type Label struct {
textProvider
Text string
Alignment fyne.TextAlign // The alignment of the Text
TextStyle fyne.TextStyle // The style of the label text
}
// NewLabel creates a new label widget with the set text content
func NewLabel(text string) *Label {
return NewLabelWithStyle(text, fyne.TextAlignLeading, fyne.TextStyle{})
}
// NewLabelWithStyle creates a new label widget with the set text content
func NewLabelWithStyle(text string, alignment fyne.TextAlign, style fyne.TextStyle) *Label {
l := &Label{
Text: text,
Alignment: alignment,
TextStyle: style,
}
return l
}
// SetText sets the text of the label
func (l *Label) SetText(text string) {
l.Text = text
l.textProvider.SetText(text) // calls refresh
}
// textAlign tells the rendering textProvider our alignment
func (l *Label) textAlign() fyne.TextAlign {
return l.Alignment
}
// textStyle tells the rendering textProvider our style
func (l *Label) textStyle() fyne.TextStyle {
return l.TextStyle
}
// textColor tells the rendering textProvider our color
func (l *Label) textColor() color.Color {
return theme.TextColor()
}
// password tells the rendering textProvider if we are a password field
func (l *Label) password() bool {
return false
}
// object returns the root object of the widget so it can be referenced
func (l *Label) object() fyne.Widget {
return l
}
// CreateRenderer is a private method to Fyne which links this widget to it's renderer
func (l *Label) CreateRenderer() fyne.WidgetRenderer {
l.textProvider = newTextProvider(l.Text, l)
return l.textProvider.CreateRenderer()
}
// Resize sets a new size for a widget.
// Note this should not be used if the widget is being managed by a Layout within a Container.
func (l *Label) Resize(size fyne.Size) {
l.resize(size, l)
}
// Move the widget to a new position, relative to it's parent.
// Note this should not be used if the widget is being managed by a Layout within a Container.
func (l *Label) Move(pos fyne.Position) {
l.move(pos, l)
}
// MinSize returns the smallest size this widget can shrink to
func (l *Label) MinSize() fyne.Size {
return l.minSize(l)
}
// Show this widget, if it was previously hidden
func (l *Label) Show() {
l.show(l)
}
// Hide this widget, if it was previously visible
func (l *Label) Hide() {
l.hide(l)
}