This commit is contained in:
JMARyA 2025-01-21 17:25:45 +01:00
parent f3880d77d2
commit fb4a142c9c
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
8 changed files with 75 additions and 242 deletions

View file

@ -14,44 +14,54 @@ pub mod components;
// Preludes
pub mod prelude {
pub use super::color::*;
pub use super::primitives::Context;
pub use super::primitives::NoBrowserAppearance;
pub use super::primitives::Nothing;
pub use super::primitives::Side;
pub use super::primitives::Size;
pub use super::primitives::animation::{Animated, Animation, Delay, Duration, Scope, Timing};
pub use super::primitives::aspect::Aspect;
pub use super::primitives::background::Background;
pub use super::primitives::background::{
Background, BackgroundClip, BackgroundGradient, BackgroundOrigin, BackgroundPosition,
BackgroundRepeat, BackgroundScrollAttachment, BackgroundSize,
};
pub use super::primitives::border::{
Border, BorderSide, BorderSize, BorderStyle, Outline, OutlineStyle, Ring,
};
pub use super::primitives::container::Container;
pub use super::primitives::cursor::{Action, Cursor, TouchAction};
pub use super::primitives::display::{
BoxDecorationBreak, BoxSizing, BreakAfter, BreakBefore, BreakInside, BreakInsideValue,
BreakValue, Clear, Display, Float, ObjectFit, Overflow,
AlignSelf, Aspect, BoxDecorationBreak, BoxSizing, BreakAfter, BreakBefore, BreakInside,
BreakInsideValue, BreakValue, Clear, Display, Float, JustifySelf, ObjectFit, Overflow,
PlaceSelf, ZIndex,
};
pub use super::primitives::div::Div;
pub use super::primitives::filter::{
Blur, Brightness, Contrast, Grayscale, HueRotate, Invert, Saturate, Sepia,
BackgroundBlendMode, BlendMode, Blur, Brightness, Contrast, Grayscale, HueRotate, Invert,
MixBlendMode, Opacity, Saturate, Sepia,
};
pub use super::primitives::flex::{
Direction, Flex, FlexBasis, FlexGrow, Justify, Order, Strategy, Wrap,
AlignContent, AlignItems, Direction, DivideStyle, DivideWidth, Flex, FlexBasis, FlexGrow,
Justify, JustifyItems, Order, Strategy, Wrap,
};
pub use super::primitives::grid::{
Columns, Grid, GridAmount, GridAutoFlow, GridAutoSize, GridElementColumn, GridElementRow,
GridElementValue,
};
pub use super::primitives::header::Header;
pub use super::primitives::height::{Height, MaxHeight, MinHeight};
pub use super::primitives::image::Image;
pub use super::primitives::image::{Image, Source, Video};
pub use super::primitives::width::{MaxWidth, MinWidth, Width};
pub use super::primitives::{Context, NoBrowserAppearance, Nothing, Side, Size, script};
// TODO :
pub use super::primitives::input::*;
pub use super::primitives::link::Link;
pub use super::primitives::list::{OrderedList, UnorderedList};
pub use super::primitives::margin::Margin;
pub use super::primitives::padding::Padding;
pub use super::primitives::position::{Position, PositionKind, Resize, Resizeable};
pub use super::primitives::position::{
ObjectPosition, Position, PositionKind, Resize, Resizeable,
};
pub use super::primitives::rounded::Rounded;
pub use super::primitives::script;
pub use super::primitives::scroll::{Overscroll, Scroll, SnapAlign, SnapType};
pub use super::primitives::shadow::Shadow;
pub use super::primitives::shadow::{DropShadow, Shadow};
pub use super::primitives::sized::Sized;
pub use super::primitives::space::{ScreenValue, SpaceBetween};
pub use super::primitives::space::{Fraction, ScreenValue, SpaceBetween};
pub use super::primitives::svg::SVG;
pub use super::primitives::table::{Caption, Header, Table, TableData, TableHead, TableRow};
pub use super::primitives::text::{
AccentColor, Code, DecorationKind, DecorationStyle, DecorationThickness, LetterSpacing,
LineClamp, LineHeight, ListStyle, NumberStyle, Paragraph, Span, Text, TextAlignment,
@ -60,11 +70,10 @@ pub mod prelude {
VerticalTextAlignment,
};
pub use super::primitives::transform::{
RenderTransformCPU, RenderTransformGPU, Rotate, Scale, Skew, Transform, TransformOrigin,
RenderTransformCPU, RenderTransformGPU, Rotate, Scale, Skew, SkewValue, Transform,
TransformOrigin,
};
pub use super::primitives::visibility::Visibility;
pub use super::primitives::width::{MaxWidth, MinWidth, Width};
pub use super::primitives::zindex::ZIndex;
pub use super::wrapper::{
_2XLScreen, Hover, LargeScreen, MediumScreen, Screen, SmallScreen, XLScreen,
};

View file

@ -23,31 +23,32 @@ pub struct AnimatedWidget {
animation: Option<Animation>,
}
macro_rules! setter {
($fnname:ident, $varname:ident, $vartype:ident, $internal_var:ident) => {
#[must_use]
pub fn $fnname(mut self, $varname: $vartype) -> Self {
self.$internal_var = $varname;
self
}
};
}
macro_rules! setter_opt {
($fnname:ident, $varname:ident, $vartype:ident, $internal_var:ident) => {
#[must_use]
pub fn $fnname(mut self, $varname: $vartype) -> Self {
self.$internal_var = Some($varname);
self
}
};
}
impl AnimatedWidget {
pub fn scope(mut self, scope: Scope) -> Self {
self.scope = scope;
self
}
pub fn timing(mut self, timing: Timing) -> Self {
self.timing = Some(timing);
self
}
pub fn delay(mut self, delay: Delay) -> Self {
self.delay = Some(delay);
self
}
pub fn duration(mut self, duration: Duration) -> Self {
self.duration = Some(duration);
self
}
pub fn animate(mut self, animation: Animation) -> Self {
self.animation = Some(animation);
self
}
setter!(scope, scope, Scope, scope);
setter_opt!(timing, timing, Timing, timing);
setter_opt!(delay, delay, Delay, delay);
setter_opt!(duration, duration, Duration, duration);
setter_opt!(animate, animation, Animation, animation);
}
impl Render for AnimatedWidget {

View file

@ -1,73 +0,0 @@
use maud::{Markup, Render, html};
use crate::ui::UIWidget;
pub struct Aspect {
kind: u8,
inner: Box<dyn UIWidget>,
}
impl Aspect {
pub fn auto<T: UIWidget + 'static>(inner: T) -> Self {
Self {
kind: 0,
inner: Box::new(inner),
}
}
pub fn square<T: UIWidget + 'static>(inner: T) -> Self {
Self {
kind: 1,
inner: Box::new(inner),
}
}
pub fn video<T: UIWidget + 'static>(inner: T) -> Self {
Self {
kind: 2,
inner: Box::new(inner),
}
}
}
impl Render for Aspect {
fn render(&self) -> Markup {
self.render_with_class("")
}
}
impl UIWidget for Aspect {
fn can_inherit(&self) -> bool {
true
}
fn base_class(&self) -> Vec<String> {
let class = match self.kind {
0 => "aspect-auto",
1 => "aspect-square",
2 => "aspect-video",
_ => "",
};
vec![class.to_string()]
}
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() {
html! {
(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())
}
}
}
}
}

View file

@ -312,3 +312,23 @@ impl AlignSelf {
constructor!(Stretch, "self-stretch");
constructor!(Baseline, "self-baseline");
}
string_class_widget!(Aspect);
impl Aspect {
constructor!(Auto, "aspect-auto");
constructor!(Square, "aspect-square");
constructor!(Video, "aspect-video");
}
string_class_widget!(ZIndex);
impl ZIndex {
constructor!(Auto, "z-auto");
constructor!(Zero, "z-0");
constructor!(One, "z-10");
constructor!(Two, "z-20");
constructor!(Three, "z-30");
constructor!(Four, "z-40");
constructor!(Five, "z-50");
}

View file

@ -1,40 +0,0 @@
use maud::{Markup, Render, html};
use crate::ui::UIWidget;
#[allow(non_snake_case)]
pub fn Header<T: UIWidget + 'static>(inner: T) -> HeaderWidget {
HeaderWidget(Box::new(inner))
}
pub struct HeaderWidget(Box<dyn UIWidget>);
impl Render for HeaderWidget {
fn render(&self) -> Markup {
self.render_with_class("")
}
}
impl UIWidget for HeaderWidget {
fn can_inherit(&self) -> bool {
true
}
fn base_class(&self) -> Vec<String> {
vec![]
}
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 {
html! {
header class=(class) {
(self.0.as_ref())
}
}
}
}

View file

@ -2,7 +2,6 @@ use super::UIWidget;
use maud::{Markup, PreEscaped, Render, html};
pub mod animation;
pub mod aspect;
pub mod background;
pub mod border;
pub mod container;
@ -12,7 +11,6 @@ pub mod div;
pub mod filter;
pub mod flex;
pub mod grid;
pub mod header;
pub mod height;
pub mod image;
pub mod input;
@ -32,7 +30,6 @@ pub mod text;
pub mod transform;
pub mod visibility;
pub mod width;
pub mod zindex;
#[allow(non_snake_case)]
#[must_use]

View file

@ -202,3 +202,4 @@ macro_rules! element_widget {
element_widget!(TableRow, TableRowWidget, tr);
element_widget!(TableHead, TableHeadWidget, th);
element_widget!(TableData, TableDataWidget, td);
element_widget!(Header, HeaderWidget, header);

View file

@ -1,82 +0,0 @@
use maud::{Markup, Render, html};
use crate::ui::UIWidget;
pub struct ZIndex(Box<dyn UIWidget>, u8);
impl Render for ZIndex {
fn render(&self) -> Markup {
self.render_with_class("")
}
}
impl ZIndex {
pub fn auto<T: UIWidget + 'static>(inner: T) -> Self {
Self(Box::new(inner), 0)
}
pub fn zero<T: UIWidget + 'static>(inner: T) -> Self {
Self(Box::new(inner), 1)
}
pub fn one<T: UIWidget + 'static>(inner: T) -> Self {
Self(Box::new(inner), 2)
}
pub fn two<T: UIWidget + 'static>(inner: T) -> Self {
Self(Box::new(inner), 3)
}
pub fn three<T: UIWidget + 'static>(inner: T) -> Self {
Self(Box::new(inner), 4)
}
pub fn four<T: UIWidget + 'static>(inner: T) -> Self {
Self(Box::new(inner), 5)
}
pub fn five<T: UIWidget + 'static>(inner: T) -> Self {
Self(Box::new(inner), 6)
}
}
impl UIWidget for ZIndex {
fn can_inherit(&self) -> bool {
true
}
fn base_class(&self) -> Vec<String> {
let class = match self.1 {
0 => "z-auto",
1 => "z-0",
2 => "z-10",
3 => "z-20",
4 => "z-30",
5 => "z-40",
6 => "z-50",
_ => "z-auto",
};
vec![class.to_string()]
}
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())
}
}
}
}
}