diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-10 12:40:11 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-10 12:40:11 +0200 |
| commit | 42500d5ed85539c5ab04dd3544beaf802da29be9 (patch) | |
| tree | 235726f22c0d62bbccbbe03784fe7a0dd2691f6f /src/layout/primitive.rs | |
| parent | 13230db68c3cb2842f23f95fc1b47fd989e6277d (diff) | |
Refactor stack ♻
Diffstat (limited to 'src/layout/primitive.rs')
| -rw-r--r-- | src/layout/primitive.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/layout/primitive.rs b/src/layout/primitive.rs index b641b5c7..30bd9363 100644 --- a/src/layout/primitive.rs +++ b/src/layout/primitive.rs @@ -1,6 +1,7 @@ //! Layouting primitives. use std::fmt::{self, Display, Formatter}; +use std::ops::Range; use crate::geom::{Insets, Linear, Point, Size, Vec2}; @@ -314,6 +315,15 @@ pub enum GenAlign { } impl GenAlign { + /// Returns the position of this alignment in the given length. + pub fn apply(self, range: Range<f64>) -> f64 { + match self { + Self::Start => range.start, + Self::Center => (range.start + range.end) / 2.0, + Self::End => range.end, + } + } + /// The inverse alignment. pub fn inv(self) -> Self { match self { |
