93 lines
2 KiB
Rust
93 lines
2 KiB
Rust
use crate::ui::UIWidget;
|
|
use maud::{Markup, Render, html};
|
|
|
|
pub struct PaddingInfo {
|
|
pub right: Option<u32>,
|
|
}
|
|
|
|
#[allow(non_snake_case)]
|
|
pub fn Padding<T: UIWidget + 'static>(inner: T) -> PaddingWidget {
|
|
PaddingWidget {
|
|
inner: Box::new(inner),
|
|
right: None,
|
|
y: None,
|
|
x: None,
|
|
}
|
|
}
|
|
|
|
pub struct PaddingWidget {
|
|
pub inner: Box<dyn UIWidget>,
|
|
pub right: Option<u32>,
|
|
pub y: Option<u32>,
|
|
pub x: Option<u32>,
|
|
}
|
|
|
|
impl PaddingWidget {
|
|
#[must_use]
|
|
pub const fn right(mut self, right: u32) -> Self {
|
|
self.right = Some(right);
|
|
self
|
|
}
|
|
|
|
#[must_use]
|
|
pub const fn y(mut self, y: u32) -> Self {
|
|
self.y = Some(y);
|
|
self
|
|
}
|
|
|
|
#[must_use]
|
|
pub const fn x(mut self, x: u32) -> Self {
|
|
self.x = Some(x);
|
|
self
|
|
}
|
|
}
|
|
|
|
impl Render for PaddingWidget {
|
|
fn render(&self) -> Markup {
|
|
self.render_with_class("")
|
|
}
|
|
}
|
|
|
|
impl UIWidget for PaddingWidget {
|
|
fn can_inherit(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
fn base_class(&self) -> Vec<String> {
|
|
let mut our_class = Vec::new();
|
|
|
|
if let Some(r) = self.right {
|
|
our_class.push(format!("pr-{r}"));
|
|
}
|
|
|
|
if let Some(y) = self.y {
|
|
our_class.push(format!("py-{y}"));
|
|
}
|
|
|
|
if let Some(x) = self.x {
|
|
our_class.push(format!("px-{x}"));
|
|
}
|
|
|
|
our_class
|
|
}
|
|
|
|
fn extended_class(&self) -> Vec<String> {
|
|
let mut c = self.base_class();
|
|
c.extend_from_slice(&self.inner.extended_class());
|
|
c
|
|
}
|
|
|
|
fn render_with_class(&self, class: &str) -> Markup {
|
|
if self.inner.as_ref().can_inherit() {
|
|
self.inner
|
|
.as_ref()
|
|
.render_with_class(&format!("{} {class}", self.base_class().join(" ")))
|
|
} else {
|
|
html! {
|
|
div class=(format!("{} {class}", self.base_class().join(" "))) {
|
|
(self.inner.as_ref())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|