diff options
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/align.rs | 3 | ||||
| -rw-r--r-- | src/geom/dir.rs | 3 | ||||
| -rw-r--r-- | src/geom/gen.rs | 18 | ||||
| -rw-r--r-- | src/geom/mod.rs | 5 | ||||
| -rw-r--r-- | src/geom/point.rs | 4 | ||||
| -rw-r--r-- | src/geom/sides.rs | 4 | ||||
| -rw-r--r-- | src/geom/size.rs | 4 | ||||
| -rw-r--r-- | src/geom/spec.rs | 21 |
8 files changed, 44 insertions, 18 deletions
diff --git a/src/geom/align.rs b/src/geom/align.rs index 422624d8..7c4d965f 100644 --- a/src/geom/align.rs +++ b/src/geom/align.rs @@ -1,5 +1,8 @@ use super::*; +/// The alignment of a box in a container. +pub type BoxAlign = Gen<Align>; + /// Where to align something along a directed axis. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] pub enum Align { diff --git a/src/geom/dir.rs b/src/geom/dir.rs index cfcb4c09..f7ffa3e2 100644 --- a/src/geom/dir.rs +++ b/src/geom/dir.rs @@ -1,5 +1,8 @@ use super::*; +/// The directions along which content flows in a container. +pub type Flow = Gen<Dir>; + /// The four directions into which content can be laid out. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum Dir { diff --git a/src/geom/gen.rs b/src/geom/gen.rs index d877713b..11b117ea 100644 --- a/src/geom/gen.rs +++ b/src/geom/gen.rs @@ -14,6 +14,14 @@ impl<T> Gen<T> { pub fn new(main: T, cross: T) -> Self { Self { main, cross } } + + /// Create a new instance with two equal components. + pub fn uniform(value: T) -> Self + where + T: Clone, + { + Self { main: value.clone(), cross: value } + } } impl Gen<Length> { @@ -42,8 +50,8 @@ impl<T> Get<GenAxis> for Gen<T> { impl<T> Switch for Gen<T> { type Other = Spec<T>; - fn switch(self, dirs: Gen<Dir>) -> Self::Other { - match dirs.main.axis() { + fn switch(self, flow: Flow) -> Self::Other { + match flow.main.axis() { SpecAxis::Horizontal => Spec::new(self.main, self.cross), SpecAxis::Vertical => Spec::new(self.cross, self.main), } @@ -72,10 +80,10 @@ impl GenAxis { impl Switch for GenAxis { type Other = SpecAxis; - fn switch(self, dirs: Gen<Dir>) -> Self::Other { + fn switch(self, flow: Flow) -> Self::Other { match self { - Self::Main => dirs.main.axis(), - Self::Cross => dirs.cross.axis(), + Self::Main => flow.main.axis(), + Self::Cross => flow.cross.axis(), } } } diff --git a/src/geom/mod.rs b/src/geom/mod.rs index 9fdb2693..0589346e 100644 --- a/src/geom/mod.rs +++ b/src/geom/mod.rs @@ -48,6 +48,7 @@ pub trait Switch { /// The type of the other version. type Other; - /// The other version of this type based on the current directions. - fn switch(self, dirs: Gen<Dir>) -> Self::Other; + /// The other version of this type based on the current layouting + /// directions. + fn switch(self, flow: Flow) -> Self::Other; } diff --git a/src/geom/point.rs b/src/geom/point.rs index 31b84d81..10ab2d3a 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -40,8 +40,8 @@ impl Get<SpecAxis> for Point { impl Switch for Point { type Other = Gen<Length>; - fn switch(self, dirs: Gen<Dir>) -> Self::Other { - match dirs.main.axis() { + fn switch(self, flow: Flow) -> Self::Other { + match flow.main.axis() { SpecAxis::Horizontal => Gen::new(self.x, self.y), SpecAxis::Vertical => Gen::new(self.y, self.x), } diff --git a/src/geom/sides.rs b/src/geom/sides.rs index 39487ff7..292f00c4 100644 --- a/src/geom/sides.rs +++ b/src/geom/sides.rs @@ -14,12 +14,12 @@ pub struct Sides<T> { } impl<T> Sides<T> { - /// Create a new box from four sizes. + /// Create a new instance from the four components. pub fn new(left: T, top: T, right: T, bottom: T) -> Self { Self { left, top, right, bottom } } - /// Create an instance with all four components set to the same `value`. + /// Create an instance with four equal components. pub fn uniform(value: T) -> Self where T: Clone, diff --git a/src/geom/size.rs b/src/geom/size.rs index 8a3951f7..0ad0e0f8 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -48,8 +48,8 @@ impl Get<SpecAxis> for Size { impl Switch for Size { type Other = Gen<Length>; - fn switch(self, dirs: Gen<Dir>) -> Self::Other { - match dirs.main.axis() { + fn switch(self, flow: Flow) -> Self::Other { + match flow.main.axis() { SpecAxis::Horizontal => Gen::new(self.width, self.height), SpecAxis::Vertical => Gen::new(self.height, self.width), } diff --git a/src/geom/spec.rs b/src/geom/spec.rs index 8a9519bc..f259ce25 100644 --- a/src/geom/spec.rs +++ b/src/geom/spec.rs @@ -14,6 +14,17 @@ impl<T> Spec<T> { pub fn new(horizontal: T, vertical: T) -> Self { Self { horizontal, vertical } } + + /// Create a new instance with two equal components. + pub fn uniform(value: T) -> Self + where + T: Clone, + { + Self { + horizontal: value.clone(), + vertical: value, + } + } } impl Spec<Length> { @@ -55,8 +66,8 @@ impl<T> Get<SpecAxis> for Spec<T> { impl<T> Switch for Spec<T> { type Other = Gen<T>; - fn switch(self, dirs: Gen<Dir>) -> Self::Other { - match dirs.main.axis() { + fn switch(self, flow: Flow) -> Self::Other { + match flow.main.axis() { SpecAxis::Horizontal => Gen::new(self.horizontal, self.vertical), SpecAxis::Vertical => Gen::new(self.vertical, self.horizontal), } @@ -85,11 +96,11 @@ impl SpecAxis { impl Switch for SpecAxis { type Other = GenAxis; - fn switch(self, dirs: Gen<Dir>) -> Self::Other { - if self == dirs.main.axis() { + fn switch(self, flow: Flow) -> Self::Other { + if self == flow.main.axis() { GenAxis::Main } else { - debug_assert_eq!(self, dirs.cross.axis()); + debug_assert_eq!(self, flow.cross.axis()); GenAxis::Cross } } |
