diff options
Diffstat (limited to 'src/layout/node.rs')
| -rw-r--r-- | src/layout/node.rs | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/layout/node.rs b/src/layout/node.rs index 44767898..c945ee19 100644 --- a/src/layout/node.rs +++ b/src/layout/node.rs @@ -1,91 +1,89 @@ -//! Layout nodes. - use std::any::Any; use std::fmt::{self, Debug, Formatter}; use super::*; -/// A self-contained, styled layout node. +/// A self-contained layout node. #[derive(Clone, PartialEq)] -pub enum LayoutNode { - /// A spacing node. - Spacing(Spacing), +pub enum Node { /// A text node. - Text(Text), - /// A dynamic that can implement custom layouting behaviour. - Dyn(Dynamic), + Text(NodeText), + /// A spacing node. + Spacing(NodeSpacing), + /// A dynamic node that can implement custom layouting behaviour. + Any(NodeAny), } -impl LayoutNode { +impl Node { /// Create a new dynamic node. - pub fn dynamic<T>(inner: T) -> Self + pub fn any<T>(any: T) -> Self where T: Layout + Debug + Clone + PartialEq + 'static, { - Self::Dyn(Dynamic::new(inner)) + Self::Any(NodeAny::new(any)) } } -impl Layout for LayoutNode { +impl Layout for Node { fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted { match self { Self::Spacing(spacing) => spacing.layout(ctx, areas), Self::Text(text) => text.layout(ctx, areas), - Self::Dyn(dynamic) => dynamic.layout(ctx, areas), + Self::Any(any) => any.layout(ctx, areas), } } } -impl Debug for LayoutNode { +impl Debug for Node { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { Self::Spacing(spacing) => spacing.fmt(f), Self::Text(text) => text.fmt(f), - Self::Dyn(dynamic) => dynamic.fmt(f), + Self::Any(any) => any.fmt(f), } } } /// A wrapper around a dynamic layouting node. -pub struct Dynamic(Box<dyn Bounds>); +pub struct NodeAny(Box<dyn Bounds>); -impl Dynamic { +impl NodeAny { /// Create a new instance from any node that satisifies the required bounds. - pub fn new<T>(inner: T) -> Self + pub fn new<T>(any: T) -> Self where T: Layout + Debug + Clone + PartialEq + 'static, { - Self(Box::new(inner)) + Self(Box::new(any)) } } -impl Layout for Dynamic { +impl Layout for NodeAny { fn layout(&self, ctx: &mut LayoutContext, areas: &Areas) -> Layouted { self.0.layout(ctx, areas) } } -impl Clone for Dynamic { +impl Clone for NodeAny { fn clone(&self) -> Self { Self(self.0.dyn_clone()) } } -impl PartialEq for Dynamic { +impl PartialEq for NodeAny { fn eq(&self, other: &Self) -> bool { self.0.dyn_eq(other.0.as_ref()) } } -impl Debug for Dynamic { +impl Debug for NodeAny { fn fmt(&self, f: &mut Formatter) -> fmt::Result { self.0.fmt(f) } } -impl From<Dynamic> for LayoutNode { - fn from(dynamic: Dynamic) -> Self { - Self::Dyn(dynamic) +impl From<NodeAny> for Node { + fn from(dynamic: NodeAny) -> Self { + Self::Any(dynamic) } } |
