-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel.go
95 lines (68 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
package rlyeh
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
type Label struct {
id int32
Text string
BorderColor rl.Color
BackgroundColor rl.Color
TextColor rl.Color
Parent Widget
Bounds rl.Rectangle
Align Align
Fill Fill
}
func NewLabel(align Align, fill Fill, text string) *Label {
self := &Label{}
self.Align = align
self.Fill = fill
self.Text = text
self.BackgroundColor = style.GlobalBackgroundColor
self.TextColor = style.LabelTextColor
return self
}
func (self *Label) GetId() int32 {
return self.id
}
func (self *Label) SetId(id int32) {
self.id = id
}
func (self *Label) GetParent() Widget {
return self.Parent
}
func (self *Label) SetParent(parent Widget) {
self.Parent = parent
}
func (self *Label) GetBounds() rl.Rectangle {
return self.Bounds
}
func (self *Label) SetBounds(bounds rl.Rectangle) {
self.Bounds = bounds
}
func (self *Label) GetAlign() Align {
return self.Align
}
func (self *Label) GetFill() Fill {
return self.Fill
}
func (self *Label) GetDataSize() Size {
var size Size
size.Width = float32(rl.MeasureText(self.Text, int32(style.GlobalTextFontsize)))
size.Height = float32(style.GlobalTextFontsize)
size.Width += float32(style.LabelTextPadding)
size.Height += float32(style.LabelTextPadding) / 2
return size
}
func (self *Label) Update(dt float32) {
}
func (self *Label) Draw() {
textColor := self.TextColor
b := self.Bounds.ToInt32()
textWidth := rl.MeasureText(self.Text, int32(style.GlobalTextFontsize))
rl.DrawRectangleLinesEx(self.Bounds, int32(style.LabelBorderWidth), self.BorderColor)
rl.DrawRectangle(b.X+int32(style.LabelBorderWidth), b.Y+int32(style.LabelBorderWidth), b.Width-(2*int32(style.LabelBorderWidth)), b.Height-(2*int32(style.LabelBorderWidth)), self.BackgroundColor)
if "" != self.Text {
rl.DrawText(self.Text, b.X+((b.Width/2)-(textWidth/2)), b.Y+((b.Height/2)-(int32(style.GlobalTextFontsize)/2)), int32(style.GlobalTextFontsize), textColor)
}
}