diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-25 20:51:16 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-25 20:51:16 +0100 |
| commit | 393d74f9bb0d4c71a69108d5be261103c39f47f3 (patch) | |
| tree | a1d4219de2d8fbec1a16ac3760a95e0b7c9529c5 /src/layout | |
| parent | 304d9dd1107504f3925c2593dd279ea6616defab (diff) | |
Layout improvements
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/constraints.rs | 12 | ||||
| -rw-r--r-- | src/layout/regions.rs | 30 |
2 files changed, 28 insertions, 14 deletions
diff --git a/src/layout/constraints.rs b/src/layout/constraints.rs index 36cfa582..b72254d7 100644 --- a/src/layout/constraints.rs +++ b/src/layout/constraints.rs @@ -1,5 +1,6 @@ use std::rc::Rc; +use super::Regions; use crate::frame::Frame; use crate::geom::{Length, Linear, Size, Spec}; @@ -59,6 +60,17 @@ impl Constraints { } } + /// Create tight constraints for a region. + pub fn tight(regions: &Regions) -> Self { + Self { + min: Spec::default(), + max: Spec::default(), + exact: regions.current.to_spec().map(Some), + base: regions.base.to_spec().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 { diff --git a/src/layout/regions.rs b/src/layout/regions.rs index 39297914..0ef92543 100644 --- a/src/layout/regions.rs +++ b/src/layout/regions.rs @@ -1,4 +1,4 @@ -use crate::geom::{Size, Spec}; +use crate::geom::{Length, Size, Spec}; /// A sequence of regions to layout into. #[derive(Debug, Clone)] @@ -13,9 +13,6 @@ pub struct Regions { pub last: Option<Size>, /// Whether nodes should expand to fill the regions instead of shrinking to /// fit the content. - /// - /// This property is only handled by nodes that have the ability to control - /// their own size. pub expand: Spec<bool>, } @@ -52,13 +49,26 @@ impl Regions { regions } - /// Whether `current` is a fully sized (untouched) copy of the last region. + /// Whether the current region is full and a region break is called for. + pub fn is_full(&self) -> bool { + Length::zero().fits(self.current.h) && !self.in_last() + } + + /// Whether `current` is the last usable region. /// /// If this is true, calling `next()` will have no effect. - pub fn in_full_last(&self) -> bool { + pub fn in_last(&self) -> bool { self.backlog.len() == 0 && self.last.map_or(true, |size| self.current == size) } + /// Advance to the next region if there is any. + pub fn next(&mut self) { + if let Some(size) = self.backlog.next().or(self.last) { + self.current = size; + self.base = size; + } + } + /// An iterator that returns pairs of `(current, base)` that are equivalent /// to what would be produced by calling [`next()`](Self::next) repeatedly /// until all regions are exhausted. @@ -69,14 +79,6 @@ impl Regions { first.chain(backlog.chain(last).map(|&s| (s, s))) } - /// Advance to the next region if there is any. - pub fn next(&mut self) { - if let Some(size) = self.backlog.next().or(self.last) { - self.current = size; - self.base = size; - } - } - /// Mutate all contained sizes in place. pub fn mutate<F>(&mut self, mut f: F) where |
