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.
//! Fachada de una app de closure: `run_app("Título", |ui| ...)`.
//!
//! `Ui` junta lo que una pantalla necesita (tema, tamaño, entidades y estado) y ofrece constructores visuales
//! (`ui_widgets`), estado reactivo/persistente, animaciones y tareas en segundo plano (`ui_state`).
//! La closure se vuelve a ejecutar cuando cambia un `State` o un evento pide frame.

use crate::core::{EntityId, EntityMap, Handle, Size};
use crate::view::any_element::AnyElement;
use crate::view::div::div;
use crate::view::element::IntoElement;
use crate::view::render::{Component, ViewContext};
use crate::view::state::StateStore;
use crate::view::theme::Theme;
use crate::view::widget_store::WidgetStore;
use std::cell::RefCell;
use std::rc::Rc;

pub struct Ui<'a> {
    pub(crate) theme: &'a Theme,
    pub(crate) viewport: Size,
    pub(crate) entities: &'a mut EntityMap,
    pub(crate) state: &'a mut StateStore,
    pub(crate) widgets: &'a mut WidgetStore,
    pub(crate) root_id: EntityId,
    pub(crate) theme_request: &'a Rc<RefCell<Option<Theme>>>,
}

impl<'a> Ui<'a> {
    pub(crate) fn new(
        theme: &'a Theme,
        viewport: Size,
        entities: &'a mut EntityMap,
        state: &'a mut StateStore,
        widgets: &'a mut WidgetStore,
        root_id: EntityId,
        theme_request: &'a Rc<RefCell<Option<Theme>>>,
    ) -> Self {
        Self { theme, viewport, entities, state, widgets, root_id, theme_request }
    }

    /// Tema vigente (claro/oscuro, tokens, tipografía).
    pub fn theme(&self) -> &Theme {
        self.theme
    }

    /// Cambia el tema de la ventana (se aplica en el siguiente frame).
    pub fn set_theme(&mut self, theme: Theme) {
        *self.theme_request.borrow_mut() = Some(theme);
    }

    /// Tamaño lógico de la ventana.
    pub fn viewport(&self) -> Size {
        self.viewport
    }

    /// Entidades de la app, para trabajo avanzado o para convivir con vistas existentes.
    pub fn entities(&mut self) -> &mut EntityMap {
        self.entities
    }

    /// Dibuja una vista existente como hija; sirve para migrar una app por partes.
    pub fn child<V: Component>(&mut self, handle: Handle<V>) -> AnyElement {
        let (theme, viewport) = (self.theme, self.viewport);
        self.entities
            .update(handle, |view, entity| view.view(&mut ViewContext::new(theme, viewport, entity)).into_element())
            .unwrap_or_else(|| div().into_element())
    }
}