-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel.go
46 lines (38 loc) · 988 Bytes
/
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
package rlnicex
import rl "github.com/gen2brain/raylib-go/raylib"
type Label struct {
Label string
Centered bool
Pos rl.Vector2
}
func NewLabel(label string, centered bool, x, y float64) Label {
return Label{
Label: label,
Centered: centered,
Pos: rl.Vector2{
X: float32(x),
Y: float32(y),
},
}
}
func NewLabelSimple(label string) Label {
return NewLabel(label, true, 0, 0)
}
func (l Label) RenderWithStyle(r Offset, style Style) {
final := getFinal(rl.Rectangle{
X: float32(l.Pos.X),
Y: float32(l.Pos.Y),
}, r)
if l.Centered {
o := rl.MeasureTextEx(rl.GetFontDefault(), l.Label, float32(style.FontSize), float32(style.FontSpacing))
final.X -= int32(o.X / 2)
final.Y -= int32(o.Y / 2)
}
rl.DrawTextEx(rl.GetFontDefault(), l.Label, rl.Vector2{
X: float32(final.X),
Y: float32(final.Y),
}, float32(style.FontSize), float32(style.FontSpacing), style.FontColor)
}
func (l Label) Render(r Offset) {
l.RenderWithStyle(r, baseStyle)
}