diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-05-17 15:23:04 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-05-17 15:23:04 +0200 |
| commit | 24c4a746bc68874f2d1b0d1b726596930acaadcf (patch) | |
| tree | 8288a78ab53c4d07952f0975ff5166068d4f4526 /src/layout/fixed.rs | |
| parent | 1003d320d40aa46a0a3fba49b09425ead1b4b584 (diff) | |
Move aspect ratio into stack
Diffstat (limited to 'src/layout/fixed.rs')
| -rw-r--r-- | src/layout/fixed.rs | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index 5905fa95..a42eab5a 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -7,10 +7,6 @@ pub struct FixedNode { pub width: Option<Linear>, /// The fixed height, if any. pub height: Option<Linear>, - /// The fixed aspect ratio between width and height, if any. - /// - /// The resulting frame will satisfy `width = aspect * height`. - pub aspect: Option<f64>, /// The child node whose size to fix. pub child: AnyNode, } @@ -18,21 +14,13 @@ pub struct FixedNode { impl Layout for FixedNode { fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Frame> { let Areas { current, full, .. } = areas; - - let full = Size::new( - self.width.map(|w| w.resolve(full.width)).unwrap_or(current.width), - self.height.map(|h| h.resolve(full.height)).unwrap_or(current.height), + let size = Size::new( + self.width.map_or(current.width, |w| w.resolve(full.width)), + self.height.map_or(current.height, |h| h.resolve(full.height)), ); - let mut size = full; - if let Some(aspect) = self.aspect { - // Shrink the size to ensure that the aspect ratio can be satisfied. - let width = size.width.min(aspect * size.height); - size = Size::new(width, width / aspect); - } - let fixed = Spec::new(self.width.is_some(), self.height.is_some()); - let areas = Areas::once(size, full, fixed).with_aspect(self.aspect); + let areas = Areas::once(size, size, fixed); self.child.layout(ctx, &areas) } } |
