-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkbox.go
101 lines (75 loc) · 2.29 KB
/
checkbox.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
100
101
package rlyeh
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
type Checkbox struct {
id int32
Text string
Parent Widget
Bounds rl.Rectangle
Align Align
Fill Fill
Checked bool
state State
}
func NewCheckbox(align Align, fill Fill) *Checkbox {
self := &Checkbox{}
self.Align = align
self.Fill = fill
self.Checked = false
self.state = Normal
return self
}
func (self *Checkbox) GetId() int32 {
return self.id
}
func (self *Checkbox) SetId(id int32) {
self.id = id
}
func (self *Checkbox) GetParent() Widget {
return self.Parent
}
func (self *Checkbox) SetParent(parent Widget) {
self.Parent = parent
}
func (self *Checkbox) GetBounds() rl.Rectangle {
return self.Bounds
}
func (self *Checkbox) SetBounds(bounds rl.Rectangle) {
self.Bounds = bounds
}
func (self *Checkbox) GetAlign() Align {
return self.Align
}
func (self *Checkbox) GetFill() Fill {
return self.Fill
}
func (self *Checkbox) GetDataSize() Size {
var size Size
size.Width = float32(style.LabelBorderWidth) + float32(style.GlobalTextFontsize)
size.Height = size.Width
return size
}
func (self *Checkbox) Update(dt float32) {
state := GetState(self.Bounds)
if Released == state && Released != self.state {
self.Checked = !self.Checked
}
self.state = state
}
func (self *Checkbox) Draw() {
b := self.Bounds.ToInt32()
borderWidth := int32(style.LabelBorderWidth)
if self.Checked {
rl.DrawRectangleLines(b.X, b.Y, b.Width, b.Height, style.CheckboxDefaultBorderColor)
rl.DrawLineEx(rl.Vector2{self.Bounds.X + 2*float32(borderWidth), self.Bounds.Y + 2*float32(borderWidth)},
rl.Vector2{self.Bounds.X + self.Bounds.Width - 2*float32(borderWidth), self.Bounds.Y + self.Bounds.Height - 2*float32(borderWidth)},
float32(borderWidth), style.CheckboxDefaultActiveColor)
rl.DrawLineEx(rl.Vector2{self.Bounds.X + self.Bounds.Width - 2*float32(borderWidth), self.Bounds.Y + 2*float32(borderWidth)},
rl.Vector2{self.Bounds.X + 2*float32(borderWidth), self.Bounds.Y + self.Bounds.Height - 2*float32(borderWidth)},
float32(borderWidth), style.CheckboxDefaultActiveColor)
} else {
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, style.CheckboxDefaultBorderColor)
rl.DrawRectangle(b.X+borderWidth, b.Y+borderWidth, b.Width-(2*borderWidth), b.Height-(2*borderWidth), style.CheckboxDefaultInsideColor)
}
}