aura-gui 0.3.5

UI nativa acelerada por GPU para escritorio, Android e iOS, en un solo crate: estilo tipo Tailwind, componentes, sombras, animaciones y agentes de IA. Reposo a cero. Licencia AGPL-3.0 o comercial.
//! Entidades de widgets que la fachada `Ui` crea una sola vez (campos de texto, listas, selectores, tareas).
//!
//! `State` guarda valores; esto guarda las entidades que tienen estado interno propio y deben conservar foco,
//! cursor, scroll y suscripciones entre frames.

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);
    }

    /// Scroll de una lista virtualizada; se conserva entre frames.
    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));
    }
}