summaryrefslogtreecommitdiff
path: root/src/layout/primitive.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-07 17:07:44 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-07 17:07:44 +0200
commit537545e7f8351d7677c396456e46568f5a5e2a7a (patch)
treef4c7614293246db06c7fa7496458da01b15c3b84 /src/layout/primitive.rs
parentca1256c924f3672feb76dbc2bc2e309eb4fc4cf5 (diff)
Evaluation and node-based layouting 🚀
Diffstat (limited to 'src/layout/primitive.rs')
-rw-r--r--src/layout/primitive.rs64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/layout/primitive.rs b/src/layout/primitive.rs
index f932b85b..b641b5c7 100644
--- a/src/layout/primitive.rs
+++ b/src/layout/primitive.rs
@@ -2,7 +2,7 @@
use std::fmt::{self, Display, Formatter};
-use crate::geom::{Point, Size, Vec2};
+use crate::geom::{Insets, Linear, Point, Size, Vec2};
/// Generic access to a structure's components.
pub trait Get<Index> {
@@ -126,6 +126,11 @@ impl<T> Gen2<T> {
}
}
+impl Gen2<f64> {
+ /// The instance that has both components set to zero.
+ pub const ZERO: Self = Self { main: 0.0, cross: 0.0 };
+}
+
impl<T> Get<GenAxis> for Gen2<T> {
type Component = T;
@@ -155,11 +160,6 @@ impl<T> Switch for Gen2<T> {
}
}
-impl Gen2<f64> {
- /// The instance that has both components set to zero.
- pub const ZERO: Self = Self { main: 0.0, cross: 0.0 };
-}
-
/// A generic container with two components for the two specific axes.
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
pub struct Spec2<T> {
@@ -176,6 +176,26 @@ impl<T> Spec2<T> {
}
}
+impl Spec2<f64> {
+ /// The instance that has both components set to zero.
+ pub const ZERO: Self = Self { horizontal: 0.0, vertical: 0.0 };
+
+ /// Convert to a 2D vector.
+ pub fn to_vec2(self) -> Vec2 {
+ Vec2::new(self.horizontal, self.vertical)
+ }
+
+ /// Convert to a point.
+ pub fn to_point(self) -> Point {
+ Point::new(self.horizontal, self.vertical)
+ }
+
+ /// Convert to a size.
+ pub fn to_size(self) -> Size {
+ Size::new(self.horizontal, self.vertical)
+ }
+}
+
impl<T> Get<SpecAxis> for Spec2<T> {
type Component = T;
@@ -205,26 +225,6 @@ impl<T> Switch for Spec2<T> {
}
}
-impl Spec2<f64> {
- /// The instance that has both components set to zero.
- pub const ZERO: Self = Self { horizontal: 0.0, vertical: 0.0 };
-
- /// Convert to a 2D vector.
- pub fn to_vec2(self) -> Vec2 {
- Vec2::new(self.horizontal, self.vertical)
- }
-
- /// Convert to a point.
- pub fn to_point(self) -> Point {
- Point::new(self.horizontal, self.vertical)
- }
-
- /// Convert to a size.
- pub fn to_size(self) -> Size {
- Size::new(self.horizontal, self.vertical)
- }
-}
-
/// The two generic layouting axes.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum GenAxis {
@@ -444,6 +444,18 @@ impl<T> Sides<T> {
}
}
+impl Sides<Linear> {
+ /// The absolute insets.
+ pub fn insets(self, Size { width, height }: Size) -> Insets {
+ Insets {
+ x0: -self.left.eval(width),
+ y0: -self.top.eval(height),
+ x1: -self.right.eval(width),
+ y1: -self.bottom.eval(height),
+ }
+ }
+}
+
impl<T> Get<Side> for Sides<T> {
type Component = T;