diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-12-13 23:59:01 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-12-13 23:59:01 +0100 |
| commit | 665b4d2aca81af48b8e0eaca4e709ef2e7825844 (patch) | |
| tree | 4ada33f607455f14b6a170fe4b7fbe173056567b /src/size.rs | |
| parent | 971ff3a2dcff1e68bf7e19017113469aad5a30c2 (diff) | |
More consistent library code and functions 🎄
Diffstat (limited to 'src/size.rs')
| -rw-r--r-- | src/size.rs | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/size.rs b/src/size.rs index 420b815b..412b657d 100644 --- a/src/size.rs +++ b/src/size.rs @@ -11,7 +11,7 @@ use crate::layout::prelude::*; #[derive(Copy, Clone, PartialEq, PartialOrd)] pub struct Size { /// The size in typographic points (1/72 inches). - points: f32, + pub points: f32, } impl Size { @@ -117,6 +117,22 @@ impl Size2D { /// Create a 2D-size with `x` and `y` set to the same value `s`. pub fn with_all(s: Size) -> Size2D { Size2D { x: s, y: s } } + /// Get the specificed component. + pub fn get(self, axis: SpecificAxis) -> Size { + match axis { + Horizontal => self.x, + Vertical => self.y, + } + } + + /// Get the specificed component mutably. + pub fn get_mut(&mut self, axis: SpecificAxis) -> &mut Size { + match axis { + Horizontal => &mut self.x, + Vertical => &mut self.y, + } + } + /// Access the primary size of this specialized 2D-size. pub fn get_primary(self, axes: LayoutAxes) -> Size { if axes.primary.axis() == Horizontal { self.x } else { self.y } @@ -242,20 +258,15 @@ impl SizeBox { SizeBox { left: value, top: value, right: value, bottom: value } } - /// Get a mutable reference to the value for the specified axis and + /// Get a mutable reference to the value for the specified direction and /// alignment. Center alignment will be treated the same as origin /// alignment. - pub fn get_mut(&mut self, - axes: LayoutAxes, - axis: GenericAxis, - alignment: Alignment, - ) -> &mut Size { - let mut normalized = axes.get_generic(axis); + pub fn get_mut(&mut self, mut direction: Direction, alignment: Alignment) -> &mut Size { if alignment == End { - normalized = normalized.inv(); + direction = direction.inv(); } - match normalized { + match direction { LeftToRight => &mut self.left, RightToLeft => &mut self.right, TopToBottom => &mut self.top, |
