diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-02-22 12:42:02 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-02-22 12:42:02 +0100 |
| commit | 2bf32c51bceb2f3a8b7ebea3d7c7d6d96757591b (patch) | |
| tree | 3524388a7394dd35ccef10b89a7a034e6ae1ab60 /src/layout/constraints.rs | |
| parent | c7e52f20483971a39f54c56700b31980f744a410 (diff) | |
Remove layout cache
Diffstat (limited to 'src/layout/constraints.rs')
| -rw-r--r-- | src/layout/constraints.rs | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/src/layout/constraints.rs b/src/layout/constraints.rs deleted file mode 100644 index 3bdbc4bc..00000000 --- a/src/layout/constraints.rs +++ /dev/null @@ -1,88 +0,0 @@ -use std::sync::Arc; - -use super::Regions; -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<Arc<Frame>>; -} - -impl Constrain for Frame { - fn constrain(self, cts: Constraints) -> Constrained<Arc<Frame>> { - Constrained::new(Arc::new(self), cts) - } -} - -/// Carries an item that is only valid in certain regions and the constraints -/// that describe these regions. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub struct Constrained<T> { - /// The item that is only valid if the constraints are fullfilled. - pub item: T, - /// Constraints on regions in which the item is valid. - 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 { - /// The minimum available length in the region. - pub min: Spec<Option<Length>>, - /// The maximum available length in the region. - pub max: Spec<Option<Length>>, - /// The available length in the region. - pub exact: Spec<Option<Length>>, - /// The base length of the region used for relative length resolution. - pub base: Spec<Option<Length>>, - /// The expand settings of the region. - pub expand: Spec<bool>, -} - -impl Constraints { - /// Create a new region constraint. - pub fn new(expand: Spec<bool>) -> Self { - Self { - min: Spec::default(), - max: Spec::default(), - exact: Spec::default(), - base: Spec::default(), - expand, - } - } - - /// Create tight constraints for a region. - pub fn tight(regions: &Regions) -> Self { - Self { - min: Spec::default(), - max: Spec::default(), - exact: regions.current.map(Some), - base: regions.base.map(Some), - expand: regions.expand, - } - } - - /// Check whether the constraints are fullfilled in a region with the given - /// properties. - pub fn check(&self, current: Size, base: Size, expand: Spec<bool>) -> bool { - self.expand == expand - && verify(self.min, current, |m, c| c.fits(m)) - && verify(self.max, current, |m, c| m.fits(c)) - && verify(self.exact, current, Length::approx_eq) - && verify(self.base, base, Length::approx_eq) - } -} - -/// Verify a single constraint. -fn verify(spec: Spec<Option<Length>>, size: Size, f: fn(Length, Length) -> bool) -> bool { - spec.zip(size).all(|&(opt, s)| opt.map_or(true, |m| f(m, s))) -} |
