diff options
| author | Martin Haug <mhaug@live.de> | 2021-06-08 11:05:09 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-09 22:44:40 +0200 |
| commit | 29cfef0a6dfef5820bda339d327638e285aaf4d3 (patch) | |
| tree | 7a2e16b4c97d4259da1eb63deaa716b620feb4df /src/geom | |
| parent | 73fa2eda2c23bd3baeb9e22b99eb0bfb183fc638 (diff) | |
Add a grid layouter
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/gridu.rs | 73 | ||||
| -rw-r--r-- | src/geom/mod.rs | 2 |
2 files changed, 75 insertions, 0 deletions
diff --git a/src/geom/gridu.rs b/src/geom/gridu.rs new file mode 100644 index 00000000..70fc17e4 --- /dev/null +++ b/src/geom/gridu.rs @@ -0,0 +1,73 @@ +use super::*; + +/// An enum with the length that a grid cell may have. +#[derive(Copy, Clone, PartialEq, Hash)] +pub enum TrackSizing { + /// A length stated in absolute values and fractions of the parent's size. + Linear(Linear), + /// A length that is the fraction of the remaining free space in the parent. + Fractional(Fractional), + /// The cell will fit its contents. + Auto, +} + +impl TrackSizing { + pub fn is_zero(&self) -> bool { + match self { + Self::Linear(l) => l.is_zero(), + Self::Fractional(f) => f.is_zero(), + Self::Auto => false, + } + } + + pub fn preliminary_length(&self, resolve: Length) -> Length { + match self { + Self::Linear(l) => l.resolve(resolve), + _ => resolve, + } + } +} + +impl Display for TrackSizing { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Self::Linear(x) => <Linear as Display>::fmt(x, f), + Self::Fractional(x) => <Fractional as Display>::fmt(x, f), + Self::Auto => write!(f, "auto"), + } + } +} + +impl Debug for TrackSizing { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Self::Linear(x) => <Linear as Debug>::fmt(x, f), + Self::Fractional(x) => <Fractional as Debug>::fmt(x, f), + Self::Auto => write!(f, "auto"), + } + } +} + +impl From<Length> for TrackSizing { + fn from(abs: Length) -> Self { + Self::Linear(abs.into()) + } +} + +impl From<Relative> for TrackSizing { + fn from(rel: Relative) -> Self { + Self::Linear(rel.into()) + } +} + +impl From<Linear> for TrackSizing { + fn from(lin: Linear) -> Self { + Self::Linear(lin) + } +} + +impl From<Fractional> for TrackSizing { + fn from(fr: Fractional) -> Self { + Self::Fractional(fr) + } +} diff --git a/src/geom/mod.rs b/src/geom/mod.rs index ce8a7276..fdc3980e 100644 --- a/src/geom/mod.rs +++ b/src/geom/mod.rs @@ -7,6 +7,7 @@ mod angle; mod dir; mod fr; mod gen; +mod gridu; mod length; mod linear; mod path; @@ -21,6 +22,7 @@ pub use angle::*; pub use dir::*; pub use fr::*; pub use gen::*; +pub use gridu::*; pub use length::*; pub use linear::*; pub use path::*; |
