Replies: 4 comments
-
Building on this a little more... I think it's more complex than my first glance. I'd also want to support CSS Functions which interoperate with the types and units. This is my vision, for such an addition: let font_size: CssUnit = Em(1.04);
let icon_aspect_ratio: CssUnit = Scalar(1.15);
let icon_style = css!(
r#"
& {
height: ${icon_height};
width: ${icon_width};
}
"#,
icon_height = max!(Px(24), calc!(font_size * 2)),
icon_width = max!(Px(24), calc!(font_size * 2.0 * icon_aspect_ratio)),
); Where Alternatively, This is opposed to |
Beta Was this translation helpful? Give feedback.
-
I am not sure why one would specify font size like However, it does make sense to implement this syntax for things like To create such a syntax, we have to have a type that implements all units and calculations: // Yew requires PartialEq for a type to be passed in a Properties type,
// however, I am not sure how to implement PartialEq for `f64` here.
// Decimal seems unnecessarily heavy for this purpose.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Size {
Px(f64),
Em(f64),
Rem(f64),
// I think Size should contain Calc.
// so something that accepts a Size type can accept both calc(15px * 2) and 30px.
Calc(Calculation),
// ...
// what to do with `--var-font-size`?
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Calculation {
Add {
left: Box<Size>,
right: Box<Size>,
}
// ...
} It may also make sense to have functions to create Size types than using enum variants directly, so
I am in favour of this syntax than In addition, // Instead of
let size = max!(Vh(30), Px(15), Percent(20));
// We can have
let size = Vh(30)
.max(Px(15))
.max(Percent(20)); This does mean that we will be providing many implementations of |
Beta Was this translation helpful? Give feedback.
-
Thanks, I like this feedback and it drives a clearer vision. I'll start working on an external crate and we can talk about integration when the time comes. P.S. Yes, |
Beta Was this translation helpful? Give feedback.
-
Update: I've began working on this crate: https://github.com/simbleau/cssugar |
Beta Was this translation helpful? Give feedback.
-
I think there's a lot of ergonomics that could be gained through support of units and values.
The goals of stylist aren't entirely explained, so I'm not sure if you would be opposed to ergonomic values and unit types in stylist, such that someone could do more intricate styling.
Example of a unit:
This would allow someone to, with stylist, do the following:
The benefits of having support for rgb, rgba, em, etc.. built in would be a massive gain in ergonomics for dynamic sizing, especially media queries.
What are your thoughts?
This is meant to be an open discussion, and I would take over the implementation. I can either make this another crate or we can put this in stylist.
Beta Was this translation helpful? Give feedback.
All reactions