131 lines
2.9 KiB
Rust
131 lines
2.9 KiB
Rust
use super::UIWidget;
|
|
use maud::{Markup, Render, html};
|
|
|
|
#[allow(non_snake_case)]
|
|
pub fn Text(txt: &str) -> TextWidget {
|
|
TextWidget {
|
|
inner: None,
|
|
txt: txt.to_string(),
|
|
font: String::new(),
|
|
color: String::new(),
|
|
size: String::new(),
|
|
span: false,
|
|
}
|
|
}
|
|
|
|
#[allow(non_snake_case)]
|
|
pub fn Paragraph<T: UIWidget + 'static>(inner: T) -> TextWidget {
|
|
TextWidget {
|
|
inner: Some(Box::new(inner)),
|
|
font: String::new(),
|
|
color: String::new(),
|
|
txt: String::new(),
|
|
size: String::new(),
|
|
span: false,
|
|
}
|
|
}
|
|
|
|
#[allow(non_snake_case)]
|
|
pub fn Span(txt: &str) -> TextWidget {
|
|
TextWidget {
|
|
inner: None,
|
|
txt: txt.to_string(),
|
|
font: String::new(),
|
|
color: String::new(),
|
|
size: String::new(),
|
|
span: true,
|
|
}
|
|
}
|
|
|
|
pub struct TextWidget {
|
|
inner: Option<Box<dyn UIWidget>>,
|
|
txt: String,
|
|
font: String,
|
|
color: String,
|
|
size: String,
|
|
span: bool,
|
|
}
|
|
|
|
impl TextWidget {
|
|
pub fn semibold(mut self) -> Self {
|
|
self.font = "font-semibold".to_owned();
|
|
self
|
|
}
|
|
|
|
pub fn bold(mut self) -> Self {
|
|
self.font = "font-bold".to_owned();
|
|
self
|
|
}
|
|
|
|
pub fn medium(mut self) -> Self {
|
|
self.font = "font-medium".to_owned();
|
|
self
|
|
}
|
|
|
|
pub fn _2xl(mut self) -> Self {
|
|
self.size = "text-2xl".to_owned();
|
|
self
|
|
}
|
|
|
|
pub fn xl(mut self) -> Self {
|
|
self.size = "text-xl".to_owned();
|
|
self
|
|
}
|
|
|
|
pub fn sm(mut self) -> Self {
|
|
self.size = "text-sm".to_owned();
|
|
self
|
|
}
|
|
|
|
pub fn gray(mut self, i: u32) -> Self {
|
|
self.color = format!("text-gray-{}", i);
|
|
self
|
|
}
|
|
|
|
pub fn slate(mut self, i: u32) -> Self {
|
|
self.color = format!("text-slate-{}", i);
|
|
self
|
|
}
|
|
|
|
pub fn white(mut self) -> Self {
|
|
self.color = "text-white".to_owned();
|
|
self
|
|
}
|
|
}
|
|
|
|
impl Render for TextWidget {
|
|
fn render(&self) -> Markup {
|
|
self.render_with_class("")
|
|
}
|
|
}
|
|
|
|
impl UIWidget for TextWidget {
|
|
fn can_inherit(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
fn render_with_class(&self, class: &str) -> Markup {
|
|
let our_class = format!("{} {} {}", self.color, self.font, self.size);
|
|
if let Some(inner) = &self.inner {
|
|
if self.span {
|
|
html! {
|
|
span class=(format!("{} {}", class, our_class)) { (inner) }
|
|
}
|
|
} else {
|
|
html! {
|
|
p class=(format!("{} {}", class, our_class)) { (inner) }
|
|
}
|
|
}
|
|
} else {
|
|
if self.span {
|
|
html! {
|
|
span class=(format!("{} {}", class, our_class)) { (self.txt) }
|
|
}
|
|
} else {
|
|
html! {
|
|
p class=(format!("{} {}", class, our_class)) { (self.txt) }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|