use super::*;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct State<T> {
idx: usize,
_marker: std::marker::PhantomData<T>,
}
impl<T: 'static> State<T> {
pub(crate) fn from_idx(idx: usize) -> Self {
Self {
idx,
_marker: std::marker::PhantomData,
}
}
pub fn get<'a>(&self, ui: &'a Context) -> &'a T {
ui.hook_states[self.idx]
.downcast_ref::<T>()
.unwrap_or_else(|| {
panic!(
"use_state type mismatch at hook index {} — expected {}",
self.idx,
std::any::type_name::<T>()
)
})
}
pub fn get_mut<'a>(&self, ui: &'a mut Context) -> &'a mut T {
ui.hook_states[self.idx]
.downcast_mut::<T>()
.unwrap_or_else(|| {
panic!(
"use_state type mismatch at hook index {} — expected {}",
self.idx,
std::any::type_name::<T>()
)
})
}
}
#[derive(Debug, Clone, Default)]
#[must_use = "Response contains interaction state — check .clicked, .hovered, or .changed"]
pub struct Response {
pub clicked: bool,
pub hovered: bool,
pub changed: bool,
pub focused: bool,
pub rect: Rect,
}
impl Response {
pub fn none() -> Self {
Self::default()
}
}