summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/constraints.rs12
-rw-r--r--src/layout/regions.rs30
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