use crate::{element::UiElement, draw::UiDrawCommands}; pub struct Interactable { pub element: T, pub hovered: Option>, pub clicked: Option>, } impl Interactable { pub fn new(element: T) -> Self { Self { element, hovered: None, clicked: None, } } pub fn on_click(self, clicked: impl FnOnce() + 'static) -> Self { Self { clicked: Some(Box::new(clicked)), ..self } } pub fn on_hover(self, clicked: impl FnOnce() + 'static) -> Self { Self { clicked: Some(Box::new(clicked)), ..self } } } impl UiElement for Interactable { fn measure(&self, state: &crate::state::StateRepo, layout: &crate::LayoutInfo) -> crate::measure::Response { self.element.measure(state, layout) } fn process(&self, measure: &crate::measure::Response, state: &mut crate::state::StateRepo, layout: &crate::LayoutInfo, draw: &mut UiDrawCommands) { self.element.process(measure, state, layout, draw) } } pub trait IntoInteractable: UiElement { fn into_interactable(self) -> Interactable; } impl IntoInteractable for T { fn into_interactable(self) -> Interactable { Interactable::new(self) } }