velox_engine/element/
mod.rs1mod div;
9mod div_node;
10mod image;
11mod text;
12
13use core::cell::Cell;
14
15use crate::pod::{FrameScope, Handle, PodId, Scope};
16
17pub use div::{div, Div};
18pub use div_node::{
19 DivInteractivity, DivNode, DivRareHandlers, DivVisual, EnterFrom, TransitionSpec,
20};
21pub use image::{
22 img, img_arc, img_rotated_rgb565, img_shader, svg, svg_a4, svg_icon, svg_path, svg_str, Img,
23 SpriteSource,
24};
25pub use text::{text, Text};
26
27pub trait View: Sized + 'static {
29 fn render<'a>(&mut self, cx: &'a mut Scope<Self>) -> Element<'a>;
30}
31
32pub trait Widget<'a>: Sized {
34 fn render_once(self, cx: &'a FrameScope) -> Element<'a>;
35}
36
37pub trait IntoElement<'a>: Sized {
39 fn into_element(self, cx: &'a FrameScope) -> Element<'a>;
40
41 #[inline(always)]
43 fn into_any_element(self, cx: &'a FrameScope) -> Element<'a> {
44 self.into_element(cx)
45 }
46}
47
48impl<'a> IntoElement<'a> for Element<'a> {
49 #[inline(always)]
50 fn into_element(self, _cx: &'a FrameScope) -> Element<'a> {
51 self
52 }
53}
54
55
56impl<'a, W: Widget<'a>> IntoElement<'a> for W {
57 #[inline(always)]
58 fn into_element(self, cx: &'a FrameScope) -> Element<'a> {
59 self.render_once(cx)
60 }
61}
62
63impl<'a, V: View> IntoElement<'a> for Handle<V> {
64 #[inline(always)]
65 fn into_element(self, _cx: &'a FrameScope) -> Element<'a> {
66 Element::SubView {
67 id: self.id,
68 generation: self.generation,
69 resolved: Cell::new(None),
70 }
71 }
72}
73
74pub struct ElementNode<'a> {
76 pub element: Element<'a>,
77 pub next_sibling: Cell<Option<&'a ElementNode<'a>>>,
79}
80
81pub enum Element<'a> {
83 Div(DivNode<'a>),
85 Text(Text<'a>),
87 Img(Img<'a>),
89 SubView {
91 id: PodId,
92 generation: u16,
93 resolved: Cell<Option<&'a Element<'a>>>,
94 },
95}
96