1use std::cell::RefCell;
2
3#[derive(Debug, Clone)]
4pub enum Shape {
5 Rectangle,
6 Text { text: String, font_size: f32 },
7}
8
9#[derive(Debug, Clone, Default)]
10pub enum RenderContent {
11 #[default]
12 Empty,
13 Text(String),
14 Image(String),
15 Shape(Shape),
16}
17
18#[derive(Debug, Clone, Default)]
19pub enum Metrics {
20 #[default]
21 Auto,
23 Fixed(f32, f32),
25}
26
27#[derive(Debug, Clone, Default)]
28pub struct Position {
29 x: f32,
30 y: f32,
31}
32
33impl Position {
34 pub fn new(x: f32, y: f32) -> Self {
35 Position { x, y }
36 }
37
38 pub fn x(&self) -> f32 {
39 self.x
40 }
41
42 pub fn y(&self) -> f32 {
43 self.y
44 }
45}
46
47#[derive(Debug, Clone, Default)]
48pub struct RenderObject {
49 pub content: RenderContent,
50 pub position: Position,
51 pub metrics: Metrics,
52 pub children: RefCell<Vec<RenderObject>>,
53}
54
55impl RenderObject {
56 pub fn new(content: RenderContent, position: Position, metrics: Metrics) -> Self {
57 RenderObject {
58 content,
59 position,
60 metrics,
61 children: Vec::new().into(),
62 }
63 }
64
65 pub fn set_children(&self, children: Vec<RenderObject>) {
66 self.children.replace(children);
67 }
68}