diff options
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/gen.rs | 40 | ||||
| -rw-r--r-- | src/geom/gridu.rs | 73 | ||||
| -rw-r--r-- | src/geom/mod.rs | 14 | ||||
| -rw-r--r-- | src/geom/point.rs | 19 | ||||
| -rw-r--r-- | src/geom/size.rs | 19 | ||||
| -rw-r--r-- | src/geom/spec.rs | 27 |
6 files changed, 42 insertions, 150 deletions
diff --git a/src/geom/gen.rs b/src/geom/gen.rs index c530ff2b..075b7377 100644 --- a/src/geom/gen.rs +++ b/src/geom/gen.rs @@ -22,6 +22,14 @@ impl<T> Gen<T> { { Self { cross: value.clone(), main: value } } + + /// Convert to the specific representation. + pub fn to_spec(self, main: SpecAxis) -> Spec<T> { + match main { + SpecAxis::Horizontal => Spec::new(self.main, self.cross), + SpecAxis::Vertical => Spec::new(self.cross, self.main), + } + } } impl Gen<Length> { @@ -32,6 +40,16 @@ impl Gen<Length> { cross: Length::zero(), } } + + /// Convert to a point. + pub fn to_point(self, main: SpecAxis) -> Point { + self.to_spec(main).to_point() + } + + /// Convert to a size. + pub fn to_size(self, main: SpecAxis) -> Size { + self.to_spec(main).to_size() + } } impl<T> Get<GenAxis> for Gen<T> { @@ -52,17 +70,6 @@ impl<T> Get<GenAxis> for Gen<T> { } } -impl<T> Switch for Gen<T> { - type Other = Spec<T>; - - fn switch(self, main: SpecAxis) -> Self::Other { - match main { - SpecAxis::Horizontal => Spec::new(self.main, self.cross), - SpecAxis::Vertical => Spec::new(self.cross, self.main), - } - } -} - impl<T: Debug> Debug for Gen<T> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "Gen({:?}, {:?})", self.main, self.cross) @@ -88,17 +95,6 @@ impl GenAxis { } } -impl Switch for GenAxis { - type Other = SpecAxis; - - fn switch(self, main: SpecAxis) -> Self::Other { - match self { - Self::Main => main, - Self::Cross => main.other(), - } - } -} - impl Display for GenAxis { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.pad(match self { diff --git a/src/geom/gridu.rs b/src/geom/gridu.rs deleted file mode 100644 index 70fc17e4..00000000 --- a/src/geom/gridu.rs +++ /dev/null @@ -1,73 +0,0 @@ -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 fdc3980e..25344f0e 100644 --- a/src/geom/mod.rs +++ b/src/geom/mod.rs @@ -7,7 +7,6 @@ mod angle; mod dir; mod fr; mod gen; -mod gridu; mod length; mod linear; mod path; @@ -22,7 +21,6 @@ pub use angle::*; pub use dir::*; pub use fr::*; pub use gen::*; -pub use gridu::*; pub use length::*; pub use linear::*; pub use path::*; @@ -48,15 +46,3 @@ pub trait Get<Index> { /// Borrow the component for the specified index mutably. fn get_mut(&mut self, index: Index) -> &mut Self::Component; } - -/// Switch between the specific and generic representations of a type. -/// -/// The generic representation deals with main and cross axes while the specific -/// representation deals with horizontal and vertical axes. -pub trait Switch { - /// The type of the other version. - type Other; - - /// The other version of this type based on the current main axis. - fn switch(self, main: SpecAxis) -> Self::Other; -} diff --git a/src/geom/point.rs b/src/geom/point.rs index babbdfef..8982dcea 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -26,6 +26,14 @@ impl Point { pub fn splat(value: Length) -> Self { Self { x: value, y: value } } + + /// Convert to the generic representation. + pub fn to_gen(self, main: SpecAxis) -> Gen<Length> { + match main { + SpecAxis::Horizontal => Gen::new(self.y, self.x), + SpecAxis::Vertical => Gen::new(self.x, self.y), + } + } } impl Get<SpecAxis> for Point { @@ -46,17 +54,6 @@ impl Get<SpecAxis> for Point { } } -impl Switch for Point { - type Other = Gen<Length>; - - fn switch(self, main: SpecAxis) -> Self::Other { - match main { - SpecAxis::Horizontal => Gen::new(self.y, self.x), - SpecAxis::Vertical => Gen::new(self.x, self.y), - } - } -} - impl Debug for Point { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "Point({:?}, {:?})", self.x, self.y) diff --git a/src/geom/size.rs b/src/geom/size.rs index e20c24af..b859cb80 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -49,6 +49,14 @@ impl Size { pub fn to_point(self) -> Point { Point::new(self.width, self.height) } + + /// Convert to the generic representation. + pub fn to_gen(self, main: SpecAxis) -> Gen<Length> { + match main { + SpecAxis::Horizontal => Gen::new(self.height, self.width), + SpecAxis::Vertical => Gen::new(self.width, self.height), + } + } } impl Get<SpecAxis> for Size { @@ -69,17 +77,6 @@ impl Get<SpecAxis> for Size { } } -impl Switch for Size { - type Other = Gen<Length>; - - fn switch(self, main: SpecAxis) -> Self::Other { - match main { - SpecAxis::Horizontal => Gen::new(self.height, self.width), - SpecAxis::Vertical => Gen::new(self.width, self.height), - } - } -} - impl Debug for Size { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "Size({:?}, {:?})", self.width, self.height) diff --git a/src/geom/spec.rs b/src/geom/spec.rs index 713f0a16..e7a2d056 100644 --- a/src/geom/spec.rs +++ b/src/geom/spec.rs @@ -25,6 +25,14 @@ impl<T> Spec<T> { vertical: value, } } + + /// Convert to the generic representation. + pub fn to_gen(self, main: SpecAxis) -> Gen<T> { + match main { + SpecAxis::Horizontal => Gen::new(self.vertical, self.horizontal), + SpecAxis::Vertical => Gen::new(self.horizontal, self.vertical), + } + } } impl Spec<Length> { @@ -65,17 +73,6 @@ impl<T> Get<SpecAxis> for Spec<T> { } } -impl<T> Switch for Spec<T> { - type Other = Gen<T>; - - fn switch(self, main: SpecAxis) -> Self::Other { - match main { - SpecAxis::Horizontal => Gen::new(self.vertical, self.horizontal), - SpecAxis::Vertical => Gen::new(self.horizontal, self.vertical), - } - } -} - impl<T: Debug> Debug for Spec<T> { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "Spec({:?}, {:?})", self.horizontal, self.vertical) @@ -101,14 +98,6 @@ impl SpecAxis { } } -impl Switch for SpecAxis { - type Other = GenAxis; - - fn switch(self, main: SpecAxis) -> Self::Other { - if self == main { GenAxis::Main } else { GenAxis::Cross } - } -} - impl Display for SpecAxis { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.pad(match self { |
