diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-12-15 22:51:55 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-12-15 23:11:20 +0100 |
| commit | b6202b646a0d5ecced301d9bac8bfcaf977d7ee4 (patch) | |
| tree | 7d42cb50f9e66153e7e8b2217009684e25f54f42 /library/src/layout/grid.rs | |
| parent | f3980c704544a464f9729cc8bc9f97d3a7454769 (diff) | |
Reflection for castables
Diffstat (limited to 'library/src/layout/grid.rs')
| -rw-r--r-- | library/src/layout/grid.rs | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/library/src/layout/grid.rs b/library/src/layout/grid.rs index 2a6bd4ff..e70210c0 100644 --- a/library/src/layout/grid.rs +++ b/library/src/layout/grid.rs @@ -3,6 +3,8 @@ use crate::prelude::*; use super::Spacing; /// Arrange content in a grid. +/// +/// Tags: layout. #[func] #[capable(Layout)] #[derive(Debug, Hash)] @@ -85,17 +87,9 @@ pub struct TrackSizings(pub Vec<TrackSizing>); castable! { TrackSizings, - Expected: "integer, auto, relative length, fraction, or array of the latter three", - Value::Auto => Self(vec![TrackSizing::Auto]), - Value::Length(v) => Self(vec![TrackSizing::Relative(v.into())]), - Value::Ratio(v) => Self(vec![TrackSizing::Relative(v.into())]), - Value::Relative(v) => Self(vec![TrackSizing::Relative(v)]), - Value::Fraction(v) => Self(vec![TrackSizing::Fractional(v)]), - Value::Int(v) => Self(vec![ - TrackSizing::Auto; - Value::Int(v).cast::<NonZeroUsize>()?.get() - ]), - Value::Array(values) => Self(values + sizing: TrackSizing => Self(vec![sizing]), + count: NonZeroUsize => Self(vec![TrackSizing::Auto; count.get()]), + values: Array => Self(values .into_iter() .filter_map(|v| v.cast().ok()) .collect()), @@ -103,12 +97,9 @@ castable! { castable! { TrackSizing, - Expected: "auto, relative length, or fraction", - Value::Auto => Self::Auto, - Value::Length(v) => Self::Relative(v.into()), - Value::Ratio(v) => Self::Relative(v.into()), - Value::Relative(v) => Self::Relative(v), - Value::Fraction(v) => Self::Fractional(v), + _: AutoValue => Self::Auto, + v: Rel<Length> => Self::Relative(v), + v: Fr => Self::Fractional(v), } /// Performs grid layout. |
