From 328f745c392b809f9104203f190f32275fac5f58 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sat, 23 Mar 2024 15:52:14 +0100 Subject: [PATCH] add interactable active check --- hui/src/element/builtin/interactable.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hui/src/element/builtin/interactable.rs b/hui/src/element/builtin/interactable.rs index f86c0b8..4ae7f14 100644 --- a/hui/src/element/builtin/interactable.rs +++ b/hui/src/element/builtin/interactable.rs @@ -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 + '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 + 'static>(self, signal: F) -> Interactable; + + /// Wrap the element in an [`Interactable`] that will call the given signal continuously while active + fn on_active S + 'static>(self, signal: F) -> Interactable; } impl ElementInteractableExt for T { @@ -93,4 +98,8 @@ impl ElementInteractableExt for T { fn on_hover S + 'static>(self, signal: F) -> Interactable { self.into_interactable(InteractableEvent::Hover, signal) } + + fn on_active S + 'static>(self, signal: F) -> Interactable { + self.into_interactable(InteractableEvent::Active, signal) + } }