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/node.rs | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'src/layout/node.rs') diff --git a/src/layout/node.rs b/src/layout/node.rs index 0adbb145..31213b9d 100644 --- a/src/layout/node.rs +++ b/src/layout/node.rs @@ -18,33 +18,29 @@ pub enum LayoutNode { } impl LayoutNode { - /// Create a new model node form a type implementing `DynNode`. + /// Create a new dynamic node. pub fn dynamic(inner: T) -> Self { Self::Dyn(Dynamic::new(inner)) } } -impl Debug for LayoutNode { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { +#[async_trait(?Send)] +impl Layout for LayoutNode { + async fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Vec { match self { - Self::Spacing(spacing) => spacing.fmt(f), - Self::Text(text) => text.fmt(f), - Self::Dyn(boxed) => boxed.fmt(f), + Self::Spacing(spacing) => spacing.layout(ctx, areas).await, + Self::Text(text) => text.layout(ctx, areas).await, + Self::Dyn(boxed) => boxed.layout(ctx, areas).await, } } } -#[async_trait(?Send)] -impl Layout for LayoutNode { - async fn layout( - &self, - ctx: &mut LayoutContext, - constraints: LayoutConstraints, - ) -> Vec { +impl Debug for LayoutNode { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { - Self::Spacing(spacing) => spacing.layout(ctx, constraints).await, - Self::Text(text) => text.layout(ctx, constraints).await, - Self::Dyn(boxed) => boxed.layout(ctx, constraints).await, + Self::Spacing(spacing) => spacing.fmt(f), + Self::Text(text) => text.fmt(f), + Self::Dyn(boxed) => boxed.fmt(f), } } } @@ -80,6 +76,12 @@ impl Debug for Dynamic { } } +impl From for LayoutNode { + fn from(dynamic: Dynamic) -> Self { + Self::Dyn(dynamic) + } +} + impl Clone for Dynamic { fn clone(&self) -> Self { Self(self.0.dyn_clone()) @@ -92,12 +94,6 @@ impl PartialEq for Dynamic { } } -impl From for LayoutNode { - fn from(dynamic: Dynamic) -> Self { - Self::Dyn(dynamic) - } -} - /// A dynamic node, which can implement custom layouting behaviour. /// /// This trait just combines the requirements for types to qualify as dynamic -- cgit v1.2.3