update
This commit is contained in:
parent
8208fa8899
commit
ed739d792f
35 changed files with 1675 additions and 447 deletions
151
src/ui/primitives/space.rs
Normal file
151
src/ui/primitives/space.rs
Normal file
|
@ -0,0 +1,151 @@
|
|||
use crate::ui::UIWidget;
|
||||
use maud::{Markup, Render, html};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
/// Controlling the space between child elements.
|
||||
pub fn SpaceBetween<T: UIWidget + 'static>(inner: T) -> SpaceBetweenWidget {
|
||||
SpaceBetweenWidget(Box::new(inner), None, None)
|
||||
}
|
||||
|
||||
pub struct SpaceBetweenWidget(Box<dyn UIWidget>, Option<ScreenValue>, Option<ScreenValue>);
|
||||
|
||||
impl Render for SpaceBetweenWidget {
|
||||
fn render(&self) -> Markup {
|
||||
self.render_with_class("")
|
||||
}
|
||||
}
|
||||
|
||||
impl SpaceBetweenWidget {
|
||||
pub fn x(mut self, x: ScreenValue) -> Self {
|
||||
self.1 = Some(x);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn y(mut self, y: ScreenValue) -> Self {
|
||||
self.2 = Some(y);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl UIWidget for SpaceBetweenWidget {
|
||||
fn can_inherit(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn base_class(&self) -> Vec<String> {
|
||||
let mut ret = Vec::new();
|
||||
|
||||
if let Some(x) = &self.1 {
|
||||
ret.push(format!("space-x-{}", x.to_string()));
|
||||
}
|
||||
|
||||
if let Some(y) = &self.2 {
|
||||
ret.push(format!("space-y-{}", y.to_string()));
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
fn extended_class(&self) -> Vec<String> {
|
||||
let mut c = self.base_class();
|
||||
c.extend_from_slice(&self.0.extended_class());
|
||||
c
|
||||
}
|
||||
|
||||
fn render_with_class(&self, class: &str) -> Markup {
|
||||
if self.0.as_ref().can_inherit() {
|
||||
self.0
|
||||
.as_ref()
|
||||
.render_with_class(&format!("{} {class}", self.base_class().join(" ")))
|
||||
} else {
|
||||
html! {
|
||||
div class=(format!("{} {class}", self.base_class().join(" "))) {
|
||||
(self.0.as_ref())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub enum ScreenValue {
|
||||
_0,
|
||||
_0p5,
|
||||
_1,
|
||||
_1p5,
|
||||
_2,
|
||||
_2p5,
|
||||
_3,
|
||||
_3p5,
|
||||
_4,
|
||||
_5,
|
||||
_6,
|
||||
_7,
|
||||
_8,
|
||||
_9,
|
||||
_10,
|
||||
_11,
|
||||
_12,
|
||||
_14,
|
||||
_16,
|
||||
_20,
|
||||
_24,
|
||||
_28,
|
||||
_32,
|
||||
_36,
|
||||
_40,
|
||||
_44,
|
||||
_48,
|
||||
_52,
|
||||
_56,
|
||||
_60,
|
||||
_64,
|
||||
_72,
|
||||
_80,
|
||||
_90,
|
||||
px,
|
||||
reverse,
|
||||
}
|
||||
|
||||
impl ScreenValue {
|
||||
pub fn to_string(&self) -> &str {
|
||||
match self {
|
||||
ScreenValue::_0 => "0",
|
||||
ScreenValue::_0p5 => "0.5",
|
||||
ScreenValue::_1 => "1",
|
||||
ScreenValue::_1p5 => "1.5",
|
||||
ScreenValue::_2 => "2",
|
||||
ScreenValue::_2p5 => "2.5",
|
||||
ScreenValue::_3 => "3",
|
||||
ScreenValue::_3p5 => "3.5",
|
||||
ScreenValue::_4 => "4",
|
||||
ScreenValue::_5 => "5",
|
||||
ScreenValue::_6 => "6",
|
||||
ScreenValue::_7 => "7",
|
||||
ScreenValue::_8 => "8",
|
||||
ScreenValue::_9 => "9",
|
||||
ScreenValue::_10 => "10",
|
||||
ScreenValue::_11 => "11",
|
||||
ScreenValue::_12 => "12",
|
||||
ScreenValue::_14 => "14",
|
||||
ScreenValue::_16 => "16",
|
||||
ScreenValue::_20 => "20",
|
||||
ScreenValue::_24 => "24",
|
||||
ScreenValue::_28 => "28",
|
||||
ScreenValue::_32 => "32",
|
||||
ScreenValue::_36 => "36",
|
||||
ScreenValue::_40 => "40",
|
||||
ScreenValue::_44 => "44",
|
||||
ScreenValue::_48 => "48",
|
||||
ScreenValue::_52 => "52",
|
||||
ScreenValue::_56 => "56",
|
||||
ScreenValue::_60 => "60",
|
||||
ScreenValue::_64 => "64",
|
||||
ScreenValue::_72 => "72",
|
||||
ScreenValue::_80 => "80",
|
||||
ScreenValue::_90 => "90",
|
||||
ScreenValue::px => "px",
|
||||
ScreenValue::reverse => "reverse",
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue