summaryrefslogtreecommitdiff
path: root/src/layout/node.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/layout/node.rs')
-rw-r--r--src/layout/node.rs40
1 files changed, 18 insertions, 22 deletions
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<T: DynNode>(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<Layouted> {
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<Layouted> {
+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<Dynamic> 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<Dynamic> 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