update
This commit is contained in:
parent
8208fa8899
commit
ed739d792f
35 changed files with 1675 additions and 447 deletions
131
src/ui/text.rs
131
src/ui/text.rs
|
@ -1,131 +0,0 @@
|
|||
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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue