use crate::core::Handle;
use crate::view::uniform_list::UniformListState;
use crate::widgets::TextInput;
use rustc_hash::FxHashMap;
use std::any::Any;
#[derive(Default)]
pub(crate) struct WidgetStore {
text_inputs: FxHashMap<&'static str, Handle<TextInput>>,
text_submits: FxHashMap<&'static str, bool>,
uniform_lists: FxHashMap<&'static str, UniformListState>,
tasks: FxHashMap<&'static str, Box<dyn Any>>,
}
impl WidgetStore {
pub(crate) fn text_input(&self, key: &'static str) -> Option<Handle<TextInput>> {
self.text_inputs.get(key).copied()
}
pub(crate) fn insert_text_input(&mut self, key: &'static str, input: Handle<TextInput>) {
self.text_inputs.insert(key, input);
}
pub(crate) fn has_text_submit(&self, key: &'static str) -> bool {
self.text_submits.contains_key(key)
}
pub(crate) fn mark_text_submit(&mut self, key: &'static str) {
self.text_submits.insert(key, true);
}
pub(crate) fn uniform_list(&mut self, key: &'static str) -> UniformListState {
self.uniform_lists.entry(key).or_default().clone()
}
pub(crate) fn task<T: 'static>(&self, key: &'static str) -> Option<Handle<T>> {
self.tasks.get(key)?.downcast_ref::<Handle<T>>().copied()
}
pub(crate) fn insert_task<T: 'static>(&mut self, key: &'static str, handle: Handle<T>) {
self.tasks.insert(key, Box::new(handle));
}
}