From d3bc4ec07349a96c3863ddce63c2e52b5e7e9f2f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 11 Oct 2020 22:38:30 +0200 Subject: =?UTF-8?q?Refactor=20layouting=20base=20=F0=9F=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/fixed.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/layout/fixed.rs') 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, + /// The fixed height, if any. pub height: Option, + /// 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 { - let space = constraints.spaces[0]; + async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec { + 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 } } -- cgit v1.2.3