diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-11-16 11:10:53 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-11-16 11:10:53 +0100 |
| commit | ac4d501945e9b63f6b5f11c4c1a2ec0738d0b058 (patch) | |
| tree | f5edb15b151ea22a3ad436950e2f637449f2fe21 /src/layout/mod.rs | |
| parent | 261ef9e33a8548d4b7aa53e69e71866648982ae8 (diff) | |
Move generalization/specialization methods 🚚
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 2bafd792..442747b5 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -199,10 +199,30 @@ pub struct LayoutAxes { } impl LayoutAxes { + /// Returns the generalized version of a `Size2D` dependent on + /// the layouting axes, that is: + /// - The x coordinate describes the primary axis instead of the horizontal one. + /// - The y coordinate describes the secondary axis instead of the vertical one. + pub fn generalize(&self, space: Size2D) -> Size2D { + if self.primary.axis.is_horizontal() { + space + } else { + Size2D { x: space.y, y: space.x } + } + } + + /// Returns the specialized version of this generalized Size2D. + /// (Inverse to `generalized`). + pub fn specialize(&self, space: Size2D) -> Size2D { + // In fact, generalized is its own inverse. For reasons of clarity + // at the call site, we still have this second function. + self.generalize(space) + } + /// The position of the anchor specified by the two aligned axes /// in the given generalized space. - pub fn anchor(&self, area: Size2D) -> Size2D { - Size2D::new(self.primary.anchor(area.x), self.secondary.anchor(area.y)) + pub fn anchor(&self, space: Size2D) -> Size2D { + Size2D::new(self.primary.anchor(space.x), self.secondary.anchor(space.y)) } } |
