From 6a4823461f491aef63451f097ddfe5602e0b2157 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 10 Jul 2021 20:01:18 +0200 Subject: Reference-count complex values Rename some nodes types --- src/layout/background.rs | 4 ++-- src/layout/fixed.rs | 4 ++-- src/layout/grid.rs | 8 ++++---- src/layout/image.rs | 2 +- src/layout/mod.rs | 30 +++++++++++++++--------------- src/layout/pad.rs | 4 ++-- src/layout/par.rs | 6 +++--- src/layout/stack.rs | 4 ++-- 8 files changed, 31 insertions(+), 31 deletions(-) (limited to 'src/layout') diff --git a/src/layout/background.rs b/src/layout/background.rs index 867783bf..76ce431b 100644 --- a/src/layout/background.rs +++ b/src/layout/background.rs @@ -9,7 +9,7 @@ pub struct BackgroundNode { /// Background color / texture. pub fill: Paint, /// The child node to be filled. - pub child: AnyNode, + pub child: LayoutNode, } /// The kind of shape to use as a background. @@ -45,7 +45,7 @@ impl Layout for BackgroundNode { } } -impl From for AnyNode { +impl From for LayoutNode { fn from(background: BackgroundNode) -> Self { Self::new(background) } diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index dfcd4038..9fa2af8a 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -9,7 +9,7 @@ pub struct FixedNode { /// The fixed height, if any. pub height: Option, /// The child node whose size to fix. - pub child: AnyNode, + pub child: LayoutNode, } impl Layout for FixedNode { @@ -47,7 +47,7 @@ impl Layout for FixedNode { } } -impl From for AnyNode { +impl From for LayoutNode { fn from(fixed: FixedNode) -> Self { Self::new(fixed) } diff --git a/src/layout/grid.rs b/src/layout/grid.rs index 06b6596c..bccdf381 100644 --- a/src/layout/grid.rs +++ b/src/layout/grid.rs @@ -14,7 +14,7 @@ pub struct GridNode { /// Defines sizing of gutter rows and columns between content. pub gutter: Gen>, /// The nodes to be arranged in a grid. - pub children: Vec, + pub children: Vec, } /// Defines how to size a grid cell along an axis. @@ -45,7 +45,7 @@ impl Layout for GridNode { } } -impl From for AnyNode { +impl From for LayoutNode { fn from(grid: GridNode) -> Self { Self::new(grid) } @@ -64,7 +64,7 @@ struct GridLayouter<'a> { /// The row tracks including gutter tracks. rows: Vec, /// The children of the grid. - children: &'a [AnyNode], + children: &'a [LayoutNode], /// The region to layout into. regions: Regions, /// Resolved column sizes. @@ -517,7 +517,7 @@ impl<'a> GridLayouter<'a> { /// Get the node in the cell in column `x` and row `y`. /// /// Returns `None` if it's a gutter cell. - fn cell(&self, x: usize, y: usize) -> Option<&'a AnyNode> { + fn cell(&self, x: usize, y: usize) -> Option<&'a LayoutNode> { assert!(x < self.cols.len()); assert!(y < self.rows.len()); diff --git a/src/layout/image.rs b/src/layout/image.rs index 9ea9db55..07d7799c 100644 --- a/src/layout/image.rs +++ b/src/layout/image.rs @@ -59,7 +59,7 @@ impl Layout for ImageNode { } } -impl From for AnyNode { +impl From for LayoutNode { fn from(image: ImageNode) -> Self { Self::new(image) } diff --git a/src/layout/mod.rs b/src/layout/mod.rs index a07ccdc5..523d1a92 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -71,7 +71,7 @@ pub struct PageRun { pub size: Size, /// The layout node that produces the actual pages (typically a /// [`StackNode`]). - pub child: AnyNode, + pub child: LayoutNode, } impl PageRun { @@ -86,14 +86,14 @@ impl PageRun { } } -/// A wrapper around a dynamic layouting node. -pub struct AnyNode { +/// A dynamic layouting node. +pub struct LayoutNode { node: Box, #[cfg(feature = "layout-cache")] hash: u64, } -impl AnyNode { +impl LayoutNode { /// Create a new instance from any node that satisifies the required bounds. #[cfg(feature = "layout-cache")] pub fn new(node: T) -> Self @@ -120,7 +120,7 @@ impl AnyNode { } } -impl Layout for AnyNode { +impl Layout for LayoutNode { fn layout( &self, ctx: &mut LayoutContext, @@ -143,7 +143,13 @@ impl Layout for AnyNode { } } -impl Clone for AnyNode { +impl Debug for LayoutNode { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + self.node.fmt(f) + } +} + +impl Clone for LayoutNode { fn clone(&self) -> Self { Self { node: self.node.dyn_clone(), @@ -153,27 +159,21 @@ impl Clone for AnyNode { } } -impl Eq for AnyNode {} +impl Eq for LayoutNode {} -impl PartialEq for AnyNode { +impl PartialEq for LayoutNode { fn eq(&self, other: &Self) -> bool { self.node.dyn_eq(other.node.as_ref()) } } #[cfg(feature = "layout-cache")] -impl Hash for AnyNode { +impl Hash for LayoutNode { fn hash(&self, state: &mut H) { state.write_u64(self.hash); } } -impl Debug for AnyNode { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - self.node.fmt(f) - } -} - trait Bounds: Layout + Debug + 'static { fn as_any(&self) -> &dyn Any; fn dyn_eq(&self, other: &dyn Bounds) -> bool; diff --git a/src/layout/pad.rs b/src/layout/pad.rs index 3770c754..619bee41 100644 --- a/src/layout/pad.rs +++ b/src/layout/pad.rs @@ -7,7 +7,7 @@ pub struct PadNode { /// The amount of padding. pub padding: Sides, /// The child node whose sides to pad. - pub child: AnyNode, + pub child: LayoutNode, } impl Layout for PadNode { @@ -61,7 +61,7 @@ fn solve(padding: Sides, size: Size) -> Size { ) } -impl From for AnyNode { +impl From for LayoutNode { fn from(pad: PadNode) -> Self { Self::new(pad) } diff --git a/src/layout/par.rs b/src/layout/par.rs index bd744201..72b3edfb 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -5,8 +5,8 @@ use unicode_bidi::{BidiInfo, Level}; use xi_unicode::LineBreakIterator; use super::*; -use crate::exec::FontState; use crate::eco::EcoString; +use crate::exec::FontState; use crate::util::{RangeExt, SliceExt}; type Range = std::ops::Range; @@ -32,7 +32,7 @@ pub enum ParChild { /// A run of text and how to align it in its line. Text(EcoString, Align, Rc), /// Any child node and how to align it in its line. - Any(AnyNode, Align), + Any(LayoutNode, Align), } impl Layout for ParNode { @@ -89,7 +89,7 @@ impl ParNode { } } -impl From for AnyNode { +impl From for LayoutNode { fn from(par: ParNode) -> Self { Self::new(par) } diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 516a2284..ed053dd7 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -26,7 +26,7 @@ pub enum StackChild { /// Spacing between other nodes. Spacing(Length), /// Any child node and how to align it in the stack. - Any(AnyNode, Gen), + Any(LayoutNode, Gen), } impl Layout for StackNode { @@ -39,7 +39,7 @@ impl Layout for StackNode { } } -impl From for AnyNode { +impl From for LayoutNode { fn from(stack: StackNode) -> Self { Self::new(stack) } -- cgit v1.2.3