forked from vova616/GarageEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIButton.go
41 lines (35 loc) · 881 Bytes
/
UIButton.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
package components
import (
//"gl"
"github.com/LaPingvino/GarageEngine/engine"
"github.com/LaPingvino/GarageEngine/engine/input"
)
type UIButton struct {
engine.BaseComponent
onPressCallback func()
onHoverCallback func(bool)
mouseOn bool
}
func NewUIButton(ClickCallback func(), HoverCallback func(bool)) *UIButton {
return &UIButton{engine.NewComponent(), ClickCallback, HoverCallback, false}
}
func (btn *UIButton) Update() {
if btn.mouseOn {
if btn.onPressCallback != nil && input.MousePress(input.Mouse1) {
btn.onPressCallback()
}
}
}
func (btn *UIButton) OnMouseEnter(arbiter engine.Arbiter) bool {
btn.mouseOn = true
if btn.onHoverCallback != nil {
btn.onHoverCallback(true)
}
return true
}
func (btn *UIButton) OnMouseExit(arbiter engine.Arbiter) {
btn.mouseOn = false
if btn.onHoverCallback != nil {
btn.onHoverCallback(false)
}
}