blob: 8d336a9df6f5a010e36f3f40db51c522a007ac9d (
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
|
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)
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")
}
}
}
|