diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-11-16 10:41:30 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-11-16 10:41:30 +0100 |
| commit | 0e0f340502beada1cd9ee23857f48b91a0d11a90 (patch) | |
| tree | e4e4087260720adf4bab57edeac6a3d3cb5f14cf /src/layout/constraints.rs | |
| parent | bc118634aca5de415d211cab38c4eaa3d3cca25f (diff) | |
Revert page and inline levels
Diffstat (limited to 'src/layout/constraints.rs')
| -rw-r--r-- | src/layout/constraints.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/layout/constraints.rs b/src/layout/constraints.rs index fdcda276..36cfa582 100644 --- a/src/layout/constraints.rs +++ b/src/layout/constraints.rs @@ -1,7 +1,7 @@ use std::rc::Rc; use crate::frame::Frame; -use crate::geom::{Length, Size, Spec}; +use crate::geom::{Length, Linear, Size, Spec}; /// Constrain a frame with constraints. pub trait Constrain { @@ -68,6 +68,18 @@ impl Constraints { && verify(self.exact, current, Length::approx_eq) && verify(self.base, base, Length::approx_eq) } + + /// Set the appropriate base constraints for linear width and height sizing. + pub fn set_base_if_linear(&mut self, base: Size, sizing: Spec<Option<Linear>>) { + // The full sizes need to be equal if there is a relative component in + // the sizes. + if sizing.x.map_or(false, |l| l.is_relative()) { + self.base.x = Some(base.w); + } + if sizing.y.map_or(false, |l| l.is_relative()) { + self.base.y = Some(base.h); + } + } } /// Verify a single constraint. |
