windjammer_ui/components/generated/
row.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3#[derive(Debug, Clone, PartialEq)]
4pub struct Row {
5    pub children: Vec<String>,
6    pub gap: String,
7    pub align: RowAlign,
8    pub justify: RowJustify,
9    pub wrap: bool,
10    pub class: String,
11}
12
13#[derive(Clone, Debug, PartialEq, Copy)]
14pub enum RowAlign {
15    Start,
16    Center,
17    End,
18    Stretch,
19}
20
21#[derive(Clone, Debug, PartialEq, Copy)]
22pub enum RowJustify {
23    Start,
24    Center,
25    End,
26    SpaceBetween,
27    SpaceAround,
28    SpaceEvenly,
29}
30
31impl Row {
32    #[inline]
33    pub fn new() -> Row {
34        Row {
35            children: Vec::new(),
36            gap: "8px".to_string(),
37            align: RowAlign::Start,
38            justify: RowJustify::Start,
39            wrap: false,
40            class: String::new(),
41        }
42    }
43    #[inline]
44    pub fn child(mut self, child: String) -> Row {
45        self.children.push(child);
46        self
47    }
48    #[inline]
49    pub fn gap(mut self, gap: String) -> Row {
50        self.gap = gap;
51        self
52    }
53    #[inline]
54    pub fn align(mut self, align: RowAlign) -> Row {
55        self.align = align;
56        self
57    }
58    #[inline]
59    pub fn justify(mut self, justify: RowJustify) -> Row {
60        self.justify = justify;
61        self
62    }
63    #[inline]
64    pub fn wrap(mut self, wrap: bool) -> Row {
65        self.wrap = wrap;
66        self
67    }
68    #[inline]
69    pub fn class(mut self, class: String) -> Row {
70        self.class = class;
71        self
72    }
73    #[inline]
74    pub fn render(&self) -> String {
75        let align_str = match self.align {
76            RowAlign::Start => "flex-start".to_string(),
77            RowAlign::Center => "center".to_string(),
78            RowAlign::End => "flex-end".to_string(),
79            RowAlign::Stretch => "stretch".to_string(),
80        };
81        let justify_str = match self.justify {
82            RowJustify::Start => "flex-start".to_string(),
83            RowJustify::Center => "center".to_string(),
84            RowJustify::End => "flex-end".to_string(),
85            RowJustify::SpaceBetween => "space-between".to_string(),
86            RowJustify::SpaceAround => "space-around".to_string(),
87            RowJustify::SpaceEvenly => "space-evenly".to_string(),
88        };
89        let wrap_str = {
90            if self.wrap {
91                "wrap".to_string()
92            } else {
93                "nowrap".to_string()
94            }
95        };
96        let mut html = String::new();
97        html.push_str("<div class=\"wj-row ");
98        html.push_str(&self.class.as_str());
99        html.push_str("\" style=\"display: flex; flex-direction: row; gap: ");
100        html.push_str(&self.gap.as_str());
101        html.push_str("; align-items: ");
102        html.push_str(&align_str);
103        html.push_str("; justify-content: ");
104        html.push_str(&justify_str);
105        html.push_str("; flex-wrap: ");
106        html.push_str(&wrap_str);
107        html.push_str(";\">");
108        for child in &self.children {
109            html.push_str(&child.as_str());
110        }
111        html.push_str("</div>");
112        html
113    }
114}