diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-19 15:31:29 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-19 15:52:15 +0200 |
| commit | a6f260ca39f70f82617eca87855789413715f47d (patch) | |
| tree | 08141ae619bd21e0544d21433bce759aebc7ba83 /src/geom | |
| parent | fdab7158c91c52a4ace211c804fdd8e9110f56de (diff) | |
Refactor layouting a bit
Notably:
- Handle aspect ratio in fixed node
- Inline constraint inflation into pad node
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/size.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/geom/size.rs b/src/geom/size.rs index 7967dbdc..c191a80c 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -30,6 +30,14 @@ impl Size { Self { width: value, height: value } } + /// Limit width and height at that of another size. + pub fn cap(self, limit: Self) -> Self { + Self { + width: self.width.min(limit.width), + height: self.height.min(limit.height), + } + } + /// Whether the other size fits into this one (smaller width and height). pub fn fits(self, other: Self) -> bool { self.width.fits(other.width) && self.height.fits(other.height) @@ -62,13 +70,6 @@ impl Size { SpecAxis::Vertical => Gen::new(self.width, self.height), } } - - /// Find the largest contained size that satisfies the given `aspect` ratio. - pub fn with_aspect(self, aspect: f64) -> Self { - let width = self.width.min(aspect * self.height); - let height = width / aspect; - Size::new(width, height) - } } impl Get<SpecAxis> for Size { |
