summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-10 20:01:18 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-10 23:10:17 +0200
commit6a4823461f491aef63451f097ddfe5602e0b2157 (patch)
treead11b0ad169d030942d950573c729d50f7b3291b /src/layout
parent36b3067c19c8743032a44f888ee48702b88d135b (diff)
Reference-count complex values
Rename some nodes types
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/background.rs4
-rw-r--r--src/layout/fixed.rs4
-rw-r--r--src/layout/grid.rs8
-rw-r--r--src/layout/image.rs2
-rw-r--r--src/layout/mod.rs30
-rw-r--r--src/layout/pad.rs4
-rw-r--r--src/layout/par.rs6
-rw-r--r--src/layout/stack.rs4
8 files changed, 31 insertions, 31 deletions
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<BackgroundNode> for AnyNode {
+impl From<BackgroundNode> 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<Linear>,
/// 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<FixedNode> for AnyNode {
+impl From<FixedNode> 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<Vec<TrackSizing>>,
/// The nodes to be arranged in a grid.
- pub children: Vec<AnyNode>,
+ pub children: Vec<LayoutNode>,
}
/// Defines how to size a grid cell along an axis.
@@ -45,7 +45,7 @@ impl Layout for GridNode {
}
}
-impl From<GridNode> for AnyNode {
+impl From<GridNode> 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<TrackSizing>,
/// 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<ImageNode> for AnyNode {
+impl From<ImageNode> 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<dyn Bounds>,
#[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<T>(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<H: Hasher>(&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<Linear>,
/// 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<Linear>, size: Size) -> Size {
)
}
-impl From<PadNode> for AnyNode {
+impl From<PadNode> 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<usize>;
@@ -32,7 +32,7 @@ pub enum ParChild {
/// A run of text and how to align it in its line.
Text(EcoString, Align, Rc<FontState>),
/// 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<ParNode> for AnyNode {
+impl From<ParNode> 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<Align>),
+ Any(LayoutNode, Gen<Align>),
}
impl Layout for StackNode {
@@ -39,7 +39,7 @@ impl Layout for StackNode {
}
}
-impl From<StackNode> for AnyNode {
+impl From<StackNode> for LayoutNode {
fn from(stack: StackNode) -> Self {
Self::new(stack)
}