1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
use crate::prelude::*;
// doesn't work in safari
crate::macros::easy_enum! {aspect-ratio auto [float]}
#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum Dimension {
Auto,
Initial,
Inherit,
Unset,
Some(Unit),
}
#[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)]
pub enum DimensionExtremity {
Auto,
Initial,
Inherit,
Unset,
Some(Unit),
None,
MaxContent,
MinContent,
}
#[rustfmt::skip]
impl std::fmt::Display for Dimension {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Auto => "auto".fmt(f),
Self::Initial => "initial".fmt(f),
Self::Inherit => "inherit".fmt(f),
Self::Unset => "unset".fmt(f),
Self::Some(unit) => unit.fmt(f),
}
}
}
#[rustfmt::skip]
impl std::fmt::Display for DimensionExtremity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Auto => "auto".fmt(f),
Self::Initial => "initial".fmt(f),
Self::Inherit => "inherit".fmt(f),
Self::Unset => "unset".fmt(f),
Self::Some(unit) => unit.fmt(f),
Self::None => "none".fmt(f),
Self::MaxContent => "max-content".fmt(f),
Self::MinContent => "min-content".fmt(f),
}
}
}
#[rustfmt::skip]
#[macro_export]
#[doc(hidden)]
macro_rules! __dimension {
($kind:ident, auto) => {$crate::Property::$kind($crate::Dimension::Auto)};
($kind:ident, initial) => {$crate::Property::$kind($crate::Dimension::Initial)};
($kind:ident, inherit) => {$crate::Property::$kind($crate::Dimension::Inherit)};
($kind:ident, unset) => {$crate::Property::$kind($crate::Dimension::Unset)};
($kind:ident, $($val:tt)+) => {$crate::Property::$kind($crate::Dimension::Some($crate::unit!($($val)+)))};
}
#[macro_export] macro_rules! width { ($($tt:tt)+) => {$crate::__dimension_extremity!(Width, $($tt)+)} }
#[macro_export] macro_rules! height { ($($tt:tt)+) => {$crate::__dimension_extremity!(Height, $($tt)+)} }
#[rustfmt::skip]
#[macro_export]
#[doc(hidden)]
macro_rules! __dimension_extremity {
($kind:ident, auto) => {$crate::Property::$kind($crate::DimensionExtremity::Auto)};
($kind:ident, initial) => {$crate::Property::$kind($crate::DimensionExtremity::Initial)};
($kind:ident, inherit) => {$crate::Property::$kind($crate::DimensionExtremity::Inherit)};
($kind:ident, unset) => {$crate::Property::$kind($crate::DimensionExtremity::Unset)};
($kind:ident, none) => {$crate::Property::$kind($crate::DimensionExtremity::None)};
($kind:ident, max-content) => {$crate::Property::$kind($crate::DimensionExtremity::MaxContent)};
($kind:ident, min-content) => {$crate::Property::$kind($crate::DimensionExtremity::MinContent)};
($kind:ident, $($val:tt)+) => {$crate::Property::$kind($crate::DimensionExtremity::Some($crate::unit!($($val)+)))};
}
#[macro_export] macro_rules! min_width { ($($tt:tt)+) => { $crate::__dimension_extremity!(MinWidth, $($tt)+)} }
#[macro_export] macro_rules! max_width { ($($tt:tt)+) => { $crate::__dimension_extremity!(MaxWidth, $($tt)+)} }
#[macro_export] macro_rules! min_height { ($($tt:tt)+) => { $crate::__dimension_extremity!(MinHeight, $($tt)+)} }
#[macro_export] macro_rules! max_height { ($($tt:tt)+) => { $crate::__dimension_extremity!(MaxHeight, $($tt)+)} }
/*
pub mod property_exploration {
use super::*;
use num_traits::cast::AsPrimitive;
use dyn_partial_eq::DynPartialEq;
pub trait DynHash {
fn dyn_hash(&self, state: &mut dyn std::hash::Hasher);
}
#[dyn_partial_eq::dyn_partial_eq]
pub trait Property: dyn_clone::DynClone + DynHash + std::fmt::Display {
fn discriminant(&self) -> PropertyDiscriminant;
}
pub trait PropertyExt: Property + Sized + 'static {
fn boxed(self) -> Box<dyn Property> { Box::new(self) }
}
impl<P: Property + Sized + 'static> PropertyExt for P {}
impl<T: std::hash::Hash + ?Sized> DynHash for T {
fn dyn_hash(&self, mut state: &mut dyn std::hash::Hasher) { self.hash(&mut state); }
}
impl std::hash::Hash for dyn Property {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.discriminant().hash(state);
self.dyn_hash(state);
}
}
impl Eq for Box<dyn Property> {}
impl PartialOrd for Box<dyn Property> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { Some(self.discriminant().cmp(&other.discriminant())) }
}
impl Ord for Box<dyn Property> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.discriminant().cmp(&other.discriminant()) }
}
impl Clone for Box<dyn Property> {
fn clone(&self) -> Self { dyn_clone::clone(self) }
}
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash, Clone, Debug)]
pub enum PropertyDiscriminant {
Width,
Height,
}
pub mod width {
use super::*;
#[derive(Clone, PartialEq, Eq, Hash, Debug, DynPartialEq)]
pub struct Width(DimensionExtremity);
impl Property for Width { fn discriminant(&self) -> PropertyDiscriminant { PropertyDiscriminant::Width } }
impl std::fmt::Display for Width {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"width:".fmt(f)?;
self.0.fmt(f)
}
}
pub fn auto() -> Width { Width(DimensionExtremity::Auto) }
pub fn frac(val: impl AsPrimitive<f32>) -> Width { Width(DimensionExtremity::Some(Unit::pct(val.as_() * 100.))) }
pub fn px(val: impl AsPrimitive<f32>) -> Width { Width(DimensionExtremity::Some(Unit::px(val))) }
}
pub mod height {
use super::*;
#[derive(Clone, PartialEq, Eq, Hash, Debug, DynPartialEq)]
pub struct Height(DimensionExtremity);
impl Property for Height { fn discriminant(&self) -> PropertyDiscriminant { PropertyDiscriminant::Height } }
impl std::fmt::Display for Height {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"height:".fmt(f)?;
self.0.fmt(f)
}
}
pub fn auto() -> Height { Height(DimensionExtremity::Auto) }
pub fn frac(val: impl AsPrimitive<f32>) -> Height { Height(DimensionExtremity::Some(Unit::pct(val.as_() * 100.))) }
pub fn px(val: impl AsPrimitive<f32>) -> Height { Height(DimensionExtremity::Some(Unit::px(val))) }
}
macro_rules! props {
($($prop:expr),* $(,)?) => { vec![$($prop.boxed()),*] };
}
fn foo() {
use std::hash::Hasher;
use std::hash::Hash;
let some_prop = props![width::px(150), height::frac(0.4)];
let mut some_prop_clone = some_prop.clone();
some_prop_clone.sort();
let mut hasher = std::collections::hash_map::DefaultHasher::new();
for x in &some_prop_clone {
x.hash(&mut hasher);
}
let hash_res = hasher.finish();
}
}
*/
/*
pub mod width {
use super::*;
use num_traits::cast::AsPrimitive;
pub fn auto() -> crate::Property { crate::Property::Width(DimensionExtremity::Auto) }
pub fn initial() -> crate::Property { crate::Property::Width(DimensionExtremity::Initial) }
pub fn inherit() -> crate::Property { crate::Property::Width(DimensionExtremity::Inherit) }
pub fn unset() -> crate::Property { crate::Property::Width(DimensionExtremity::Unset) }
pub fn none() -> crate::Property { crate::Property::Width(DimensionExtremity::None) }
pub fn max_content() -> crate::Property { crate::Property::Width(DimensionExtremity::MaxContent) }
pub fn min_content() -> crate::Property { crate::Property::Width(DimensionExtremity::MinContent) }
pub fn frac(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::pct(val.as_() * 100.))) }
pub fn px(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::px(val))) }
pub fn em(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::em(val))) }
pub fn rem(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::rem(val))) }
pub fn vw(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::vw(val))) }
pub fn vh(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::vh(val))) }
pub fn vmin(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::vmin(val))) }
pub fn vmax(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::vmax(val))) }
pub fn fr(val: impl AsPrimitive<f32>) -> crate::Property { crate::Property::Width(DimensionExtremity::Some(Unit::fr(val))) }
}
*/