// Row - Horizontal layout component with gap and alignment
// Example usage:
// Row::new()
// .child(Text::new("Item 1").render())
// .child(Button::new("Click").render())
// .gap("16px")
// .align(RowAlign::Center)
// .render()
pub struct Row {
children: Vec<string>,
gap: string,
align: RowAlign,
justify: RowJustify,
wrap: bool,
class: string,
}
pub enum RowAlign {
Start,
Center,
End,
Stretch,
}
pub enum RowJustify {
Start,
Center,
End,
SpaceBetween,
SpaceAround,
SpaceEvenly,
}
impl Row {
pub fn new() -> Row {
Row {
children: Vec::new(),
gap: "8px".to_string(),
align: RowAlign::Start,
justify: RowJustify::Start,
wrap: false,
class: String::new(),
}
}
pub fn child(child: string) -> Row {
self.children.push(child)
self
}
pub fn gap(gap: string) -> Row {
self.gap = gap
self
}
pub fn align(align: RowAlign) -> Row {
self.align = align
self
}
pub fn justify(justify: RowJustify) -> Row {
self.justify = justify
self
}
pub fn wrap(wrap: bool) -> Row {
self.wrap = wrap
self
}
pub fn class(class: string) -> Row {
self.class = class
self
}
pub fn render() -> string {
let align_str = match self.align {
RowAlign::Start => "flex-start",
RowAlign::Center => "center",
RowAlign::End => "flex-end",
RowAlign::Stretch => "stretch",
}
let justify_str = match self.justify {
RowJustify::Start => "flex-start",
RowJustify::Center => "center",
RowJustify::End => "flex-end",
RowJustify::SpaceBetween => "space-between",
RowJustify::SpaceAround => "space-around",
RowJustify::SpaceEvenly => "space-evenly",
}
let wrap_str = if self.wrap { "wrap" } else { "nowrap" }
let mut html = String::new()
html.push_str("<div class=\"wj-row ")
html.push_str(self.class.as_str())
html.push_str("\" style=\"display: flex; flex-direction: row; gap: ")
html.push_str(self.gap.as_str())
html.push_str("; align-items: ")
html.push_str(align_str)
html.push_str("; justify-content: ")
html.push_str(justify_str)
html.push_str("; flex-wrap: ")
html.push_str(wrap_str)
html.push_str(";\">")
for child in self.children {
html.push_str(child.as_str())
}
html.push_str("</div>")
html
}
}