diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-10-11 22:38:30 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-10-11 22:38:30 +0200 |
| commit | d3bc4ec07349a96c3863ddce63c2e52b5e7e9f2f (patch) | |
| tree | 09c582973b58f05f9248d88f0020bf1dda262aa5 /src/layout/fixed.rs | |
| parent | f04ad0ffa5f34bb7fd97e5c94c7547f96904220c (diff) | |
Refactor layouting base 🪁
Diffstat (limited to 'src/layout/fixed.rs')
| -rw-r--r-- | src/layout/fixed.rs | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index 93947305..78a512e6 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -4,34 +4,25 @@ use crate::geom::Linear; /// A node that can fix its child's width and height. #[derive(Debug, Clone, PartialEq)] pub struct Fixed { + /// The fixed width, if any. pub width: Option<Linear>, + /// The fixed height, if any. pub height: Option<Linear>, + /// The child node whose size to fix. pub child: LayoutNode, } #[async_trait(?Send)] impl Layout for Fixed { - async fn layout( - &self, - ctx: &mut LayoutContext, - constraints: LayoutConstraints, - ) -> Vec<Layouted> { - let space = constraints.spaces[0]; + async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec<Layouted> { + let Area { rem, full } = areas.current; let size = Size::new( - self.width - .map(|w| w.eval(space.base.width)) - .unwrap_or(space.size.width), - self.height - .map(|h| h.eval(space.base.height)) - .unwrap_or(space.size.height), + self.width.map(|w| w.eval(full.width)).unwrap_or(rem.width), + self.height.map(|h| h.eval(full.height)).unwrap_or(rem.height), ); - self.child - .layout(ctx, LayoutConstraints { - spaces: vec![LayoutSpace { base: size, size }], - repeat: false, - }) - .await + let areas = Areas::once(size); + self.child.layout(ctx, &areas).await } } |
