This commit is contained in:
JMARyA 2025-01-20 08:41:20 +01:00
parent 35669c423c
commit bc27b457ea
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 80 additions and 0 deletions

View file

@ -1,5 +1,7 @@
use maud::{PreEscaped, html};
// TODO : refactor shell
/// Represents the HTML structure of a page shell, including the head, body class, and body content.
///
/// This structure is used to construct the overall HTML structure of a page, making it easier to generate consistent HTML pages dynamically.

View file

@ -44,6 +44,7 @@ pub mod prelude {
pub use super::primitives::shadow::Shadow;
pub use super::primitives::sized::Sized;
pub use super::primitives::space::{ScreenValue, SpaceBetween};
pub use super::primitives::svg::SVG;
pub use super::primitives::text::{
Code, DecorationKind, DecorationStyle, DecorationThickness, LetterSpacing, LineClamp,
LineHeight, ListStyle, NumberStyle, Paragraph, Span, Text, TextAlignment, TextContent,

View file

@ -22,6 +22,7 @@ pub mod rounded;
pub mod shadow;
pub mod sized;
pub mod space;
pub mod svg;
pub mod text;
pub mod transform;
pub mod visibility;

76
src/ui/primitives/svg.rs Normal file
View file

@ -0,0 +1,76 @@
use maud::{Markup, Render, html};
use crate::ui::{UIWidget, color::UIColor};
#[allow(non_snake_case)]
pub fn SVG<T: UIWidget + 'static>(inner: T) -> SVGWidget {
SVGWidget(Box::new(inner), None, None, None)
}
pub struct SVGWidget(
Box<dyn UIWidget>,
Option<Box<dyn UIColor>>,
Option<Box<dyn UIColor>>,
Option<u32>,
);
impl SVGWidget {
pub fn fill<C: UIColor + 'static>(mut self, color: C) -> Self {
self.1 = Some(Box::new(color));
self
}
pub fn stroke<C: UIColor + 'static>(mut self, color: C) -> Self {
self.2 = Some(Box::new(color));
self
}
pub fn stroke_width(mut self, width: u32) -> Self {
self.3 = Some(width);
self
}
}
impl Render for SVGWidget {
fn render(&self) -> Markup {
self.render_with_class("")
}
}
impl UIWidget for SVGWidget {
fn can_inherit(&self) -> bool {
false
}
fn base_class(&self) -> Vec<String> {
let mut ret = vec![];
if let Some(fill) = &self.1 {
ret.push(format!("fill-{}", fill.color_class()));
}
if let Some(stroke) = &self.2 {
ret.push(format!("stroke-{}", stroke.color_class()));
}
if let Some(stroke_width) = &self.3 {
ret.push(format!("stroke-[{stroke_width}px]"));
}
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, _: &str) -> Markup {
html! {
svg class=(self.base_class().join(" ")) {
(self.0.as_ref())
}
}
}
}