From aae67bd572ad86f4c57e364daa51a9dc883b8913 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 3 Jan 2021 00:12:09 +0100 Subject: =?UTF-8?q?Move=20and=20rename=20many=20things=20=F0=9F=9A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/node.rs | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'src/layout/node.rs') 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(inner: T) -> Self + pub fn any(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); +pub struct NodeAny(Box); -impl Dynamic { +impl NodeAny { /// Create a new instance from any node that satisifies the required bounds. - pub fn new(inner: T) -> Self + pub fn new(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 for LayoutNode { - fn from(dynamic: Dynamic) -> Self { - Self::Dyn(dynamic) +impl From for Node { + fn from(dynamic: NodeAny) -> Self { + Self::Any(dynamic) } } -- cgit v1.2.3