-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabel.go
More file actions
33 lines (28 loc) · 716 Bytes
/
label.go
File metadata and controls
33 lines (28 loc) · 716 Bytes
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
package gui
type Label struct {
Widget
text string
}
func NewLabel(text string) *Label {
l := &Label{}
widgetInit(l)
l.style = CurrentGui().Theme().Label
l.text = text
return l
}
func (l *Label) Text() string { return l.text }
func (l *Label) SetText(text string) {
l.text = text
l.Measure()
}
func (l *Label) Measure() {
l.computeContentSize()
l.measuredWidth = l.contentWidth + l.style.Padding.Left + l.style.Padding.Right
l.measuredHeight = l.contentHeight + l.style.Padding.Top + l.style.Padding.Bottom
l.measuredFlex = l.flex
}
func (l *Label) computeContentSize() {
textSize := l.style.Font.TextSize(l.style.FontSize, l.text)
l.contentWidth = textSize.W()
l.contentHeight = textSize.H()
}