blob: a8b9168b26c49f99a8c848ee0a1211689cc001d7 (
plain)
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
|
package ui
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
type DetectionType uint8
const (
OnClick DetectionType = iota
OnHold
)
type Button struct {
WidthWeight float32
DisplayElement UIElement
EventType DetectionType
ButtonType rl.MouseButton
clicked func(rl.MouseButton) bool
}
func (base *Button) Init(parent *Menu) {
base.DisplayElement.Init(parent)
if base.WidthWeight == 0 {
base.WidthWeight = 1
}
switch base.EventType {
case OnClick:
base.clicked = rl.IsMouseButtonReleased
case OnHold:
base.clicked = rl.IsMouseButtonDown
}
}
func (base *Button) Destroy() {
}
func (base *Button) GetOccupationWeight() float32 {
return base.WidthWeight
}
func (base *Button) Draw(position *rl.Rectangle) {
base.DisplayElement.Draw(position)
if base.clicked(base.ButtonType) {
var mousePos = rl.GetMousePosition()
if rl.CheckCollisionPointRec(mousePos, *position) {
rl.TraceLog(rl.LogInfo, "xdx")
}
}
}
|