mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-25 08:28:42 -06:00
add interactable active check
This commit is contained in:
parent
e22fa739c1
commit
328f745c39
|
@ -14,6 +14,7 @@ pub enum InteractableEvent {
|
|||
#[default]
|
||||
Click,
|
||||
Hover,
|
||||
Active,
|
||||
}
|
||||
|
||||
/// Wrapper that allows adding click and hover events to any element
|
||||
|
@ -59,6 +60,7 @@ impl UiElement for Interactable {
|
|||
//TODO: actually pass the response
|
||||
InteractableEvent::Click => ctx.input.check_click(rect).is_some(),
|
||||
InteractableEvent::Hover => ctx.input.check_hover(rect),
|
||||
InteractableEvent::Active => ctx.input.check_active(rect).is_some(),
|
||||
};
|
||||
|
||||
if event_happened {
|
||||
|
@ -77,8 +79,11 @@ pub trait ElementInteractableExt: UiElement {
|
|||
/// Wrap the element in an [`Interactable`] that will call the given signal when clicked
|
||||
fn on_click<S: Signal, F: Fn() -> S + 'static>(self, signal: F) -> Interactable;
|
||||
|
||||
/// Wrap the element in an [`Interactable`] that will call the given signal while hovered
|
||||
/// Wrap the element in an [`Interactable`] that will call the given signal continuously while hovered
|
||||
fn on_hover<S: Signal, F: Fn() -> S + 'static>(self, signal: F) -> Interactable;
|
||||
|
||||
/// Wrap the element in an [`Interactable`] that will call the given signal continuously while active
|
||||
fn on_active<S: Signal, F: Fn() -> S + 'static>(self, signal: F) -> Interactable;
|
||||
}
|
||||
|
||||
impl<T: UiElement + 'static> ElementInteractableExt for T {
|
||||
|
@ -93,4 +98,8 @@ impl<T: UiElement + 'static> ElementInteractableExt for T {
|
|||
fn on_hover<S: Signal, F: Fn() -> S + 'static>(self, signal: F) -> Interactable {
|
||||
self.into_interactable(InteractableEvent::Hover, signal)
|
||||
}
|
||||
|
||||
fn on_active<S: Signal, F: Fn() -> S + 'static>(self, signal: F) -> Interactable {
|
||||
self.into_interactable(InteractableEvent::Active, signal)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue