mod div;
mod div_node;
mod image;
mod text;
use core::cell::Cell;
use crate::pod::{FrameScope, Handle, PodId, Scope};
pub use div::{div, Div};
pub use div_node::{
DivInteractivity, DivNode, DivRareHandlers, DivVisual, EnterFrom, TransitionSpec,
};
pub use image::{
img, img_arc, img_rotated_rgb565, img_shader, svg, svg_a4, svg_icon, svg_path, svg_str, Img,
SpriteSource,
};
pub use text::{text, Text};
pub trait View: Sized + 'static {
fn render<'a>(&mut self, cx: &'a mut Scope<Self>) -> Element<'a>;
}
pub trait Widget<'a>: Sized {
fn render_once(self, cx: &'a FrameScope) -> Element<'a>;
}
pub trait IntoElement<'a>: Sized {
fn into_element(self, cx: &'a FrameScope) -> Element<'a>;
#[inline(always)]
fn into_any_element(self, cx: &'a FrameScope) -> Element<'a> {
self.into_element(cx)
}
}
impl<'a> IntoElement<'a> for Element<'a> {
#[inline(always)]
fn into_element(self, _cx: &'a FrameScope) -> Element<'a> {
self
}
}
impl<'a, W: Widget<'a>> IntoElement<'a> for W {
#[inline(always)]
fn into_element(self, cx: &'a FrameScope) -> Element<'a> {
self.render_once(cx)
}
}
impl<'a, V: View> IntoElement<'a> for Handle<V> {
#[inline(always)]
fn into_element(self, _cx: &'a FrameScope) -> Element<'a> {
Element::SubView {
id: self.id,
generation: self.generation,
resolved: Cell::new(None),
}
}
}
pub struct ElementNode<'a> {
pub element: Element<'a>,
pub next_sibling: Cell<Option<&'a ElementNode<'a>>>,
}
pub enum Element<'a> {
Div(DivNode<'a>),
Text(Text<'a>),
Img(Img<'a>),
RichText(&'a crate::text_rich::RichTextSpec<'a>),
DecodedImage(&'a crate::image_pipeline::DecodedImageSpec),
Vector(&'a crate::vector_canvas::VectorDrawSpec<'a>),
SceneCanvas(&'a crate::canvas_scene::SceneCanvasSpec<'a>),
SubView {
id: PodId,
generation: u16,
resolved: Cell<Option<&'a Element<'a>>>,
},
}