aura-gui 0.1.0

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.
//! Contrato de los elementos: las tres fases del pipeline de GPUI.

use crate::view::any_element::AnyElement;
use crate::view::context::ElementContext;
use crate::view::text_element::Text;
use taffy::NodeId;

/// Las tres fases, en orden:
/// 1. `request_layout` registra nodos en Taffy.
/// 2. `prepaint` registra hitboxes y desplazamientos.
/// 3. `paint` emite primitivas a la escena.
pub trait Element: 'static {
    fn request_layout(&mut self, cx: &mut ElementContext) -> NodeId;
    fn prepaint(&mut self, cx: &mut ElementContext);
    fn paint(&mut self, cx: &mut ElementContext);
}

pub trait IntoElement {
    fn into_element(self) -> AnyElement;
}

impl<E: Element> IntoElement for E {
    fn into_element(self) -> AnyElement {
        AnyElement::new(self)
    }
}

impl IntoElement for AnyElement {
    fn into_element(self) -> AnyElement {
        self
    }
}

impl IntoElement for &'static str {
    fn into_element(self) -> AnyElement {
        AnyElement::new(Text::new(self))
    }
}

impl IntoElement for String {
    fn into_element(self) -> AnyElement {
        AnyElement::new(Text::new(self))
    }
}

/// Elementos que contienen hijos: `div().child("hola").child(boton)`.
pub trait ParentElement: Sized {
    fn extend_children(&mut self, children: impl IntoIterator<Item = AnyElement>);

    fn child(mut self, child: impl IntoElement) -> Self {
        self.extend_children([child.into_element()]);
        self
    }

    fn children(mut self, children: impl IntoIterator<Item = impl IntoElement>) -> Self {
        self.extend_children(children.into_iter().map(IntoElement::into_element));
        self
    }
}