Added [optional] 'Clicked' state and GetInteractionState function
This commit is contained in:
parent
8e6dcc45e1
commit
eff176bb13
1 changed files with 31 additions and 0 deletions
|
@ -2,6 +2,10 @@
|
|||
|
||||
package raygui
|
||||
|
||||
import (
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
// GUI controls states
|
||||
type ControlState int
|
||||
|
||||
|
@ -13,4 +17,31 @@ const (
|
|||
Focused
|
||||
// Pressed indicates the mouse is hovering over the GUI element and LMB is pressed down.
|
||||
Pressed
|
||||
// Clicked indicates the mouse is hovering over the GUI element and LMB has just been released.
|
||||
Clicked
|
||||
)
|
||||
|
||||
// IsColliding will return true if 'point' is within any of the given rectangles.
|
||||
func IsInAny(point rl.Vector2, rectangles ...rl.Rectangle) bool {
|
||||
for _, rect := range rectangles {
|
||||
if rl.CheckCollisionPointRec(point, rect) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetInteractionState determines the current state of a control based on mouse position and
|
||||
// button states.
|
||||
func GetInteractionState(rectangles ...rl.Rectangle) ControlState {
|
||||
switch {
|
||||
case !IsInAny(rl.GetMousePosition(), rectangles...):
|
||||
return Normal
|
||||
case rl.IsMouseButtonDown(rl.MouseLeftButton):
|
||||
return Pressed
|
||||
case rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton):
|
||||
return Clicked
|
||||
default:
|
||||
return Focused
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue