update
This commit is contained in:
parent
8208fa8899
commit
ed739d792f
35 changed files with 1675 additions and 447 deletions
|
@ -1,78 +0,0 @@
|
|||
use super::UIWidget;
|
||||
use maud::{Markup, Render, html};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn Flex<T: UIWidget + 'static>(inner: T) -> FlexWidget {
|
||||
FlexWidget(Box::new(inner), vec![], false)
|
||||
}
|
||||
|
||||
pub enum Justify {
|
||||
Center,
|
||||
Between,
|
||||
}
|
||||
|
||||
pub struct FlexWidget(Box<dyn UIWidget>, Vec<String>, bool);
|
||||
|
||||
impl Render for FlexWidget {
|
||||
fn render(&self) -> Markup {
|
||||
self.render_with_class("")
|
||||
}
|
||||
}
|
||||
|
||||
impl FlexWidget {
|
||||
pub fn full_center(mut self) -> Self {
|
||||
self.1.push("items-center".to_owned());
|
||||
self.1.push("justify-center".to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn group(mut self) -> Self {
|
||||
self.2 = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn justify(mut self, value: Justify) -> Self {
|
||||
let class = match value {
|
||||
Justify::Center => "justify-center".to_owned(),
|
||||
Justify::Between => "justify-between".to_owned(),
|
||||
};
|
||||
|
||||
self.1.push(class);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn space_x(mut self, x: u32) -> Self {
|
||||
self.1.push(format!("space-x-{x}"));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn items_center(mut self) -> Self {
|
||||
self.1.push("items-center".to_owned());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn gap(mut self, amount: u32) -> Self {
|
||||
self.1.push(format!("gap-{amount}"));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl UIWidget for FlexWidget {
|
||||
fn can_inherit(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn render_with_class(&self, class: &str) -> Markup {
|
||||
if self.0.as_ref().can_inherit() && !self.2 {
|
||||
self.0
|
||||
.as_ref()
|
||||
.render_with_class(&format!("flex {} {class}", self.1.join(" ")))
|
||||
} else {
|
||||
html! {
|
||||
div class=(format!("flex {} {class}", self.1.join(" "))) {
|
||||
(self.0.as_ref())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue