diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-10-31 15:52:16 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-10-31 15:52:35 +0100 |
| commit | 5b344b663a3d224134923eea0d67ebf44c069b07 (patch) | |
| tree | 34a5fb464a38b9d4cb11294379b3ddf351dfce21 /src/layout/constraints.rs | |
| parent | feff013abb17f31bc5305fe77fe67cf615c19ff2 (diff) | |
Reorganize modules
Instead of separating functionality into layout and library, everything lives in the library now. This way, related things live side by side and there are no duplicate file names in the two directories.
Diffstat (limited to 'src/layout/constraints.rs')
| -rw-r--r-- | src/layout/constraints.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/layout/constraints.rs b/src/layout/constraints.rs index 11f4e5c2..fdcda276 100644 --- a/src/layout/constraints.rs +++ b/src/layout/constraints.rs @@ -1,4 +1,19 @@ -use super::*; +use std::rc::Rc; + +use crate::frame::Frame; +use crate::geom::{Length, Size, Spec}; + +/// Constrain a frame with constraints. +pub trait Constrain { + /// Reference-count the frame and wrap it with constraints. + fn constrain(self, cts: Constraints) -> Constrained<Rc<Frame>>; +} + +impl Constrain for Frame { + fn constrain(self, cts: Constraints) -> Constrained<Rc<Frame>> { + Constrained::new(Rc::new(self), cts) + } +} /// Carries an item that is only valid in certain regions and the constraints /// that describe these regions. @@ -10,6 +25,13 @@ pub struct Constrained<T> { pub cts: Constraints, } +impl<T> Constrained<T> { + /// Constrain an item with constraints. + pub fn new(item: T, cts: Constraints) -> Self { + Self { item, cts } + } +} + /// Describe regions that match them. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Constraints { |
