From 18190f377a556ae5d5bb855044a95ecea071432f Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 10 Sep 2021 15:09:56 +0200 Subject: [PATCH] Reimplement `Debug` for layout nodes --- src/layout/background.rs | 1 + src/layout/fixed.rs | 1 + src/layout/grid.rs | 1 + src/layout/image.rs | 1 + src/layout/mod.rs | 3 ++- src/layout/pad.rs | 1 + src/layout/par.rs | 2 ++ src/layout/stack.rs | 2 ++ src/layout/tree.rs | 10 ++++++++++ 9 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/layout/background.rs b/src/layout/background.rs index 306afd674..092822609 100644 --- a/src/layout/background.rs +++ b/src/layout/background.rs @@ -1,6 +1,7 @@ use super::*; /// A node that places a rectangular filled background behind its child. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct BackgroundNode { /// The kind of shape to use as a background. diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index 5b103f9ae..b7c58523c 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -3,6 +3,7 @@ use decorum::N64; use super::*; /// A node that can fix its child's width and height. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct FixedNode { /// The fixed width, if any. diff --git a/src/layout/grid.rs b/src/layout/grid.rs index 606821e27..35706498c 100644 --- a/src/layout/grid.rs +++ b/src/layout/grid.rs @@ -1,6 +1,7 @@ use super::*; /// A node that arranges its children in a grid. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct GridNode { /// The inline (columns) and block (rows) directions of this grid. diff --git a/src/layout/image.rs b/src/layout/image.rs index 0220da3eb..94f57167a 100644 --- a/src/layout/image.rs +++ b/src/layout/image.rs @@ -4,6 +4,7 @@ use crate::image::ImageId; use ::image::GenericImageView; /// An image node. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct ImageNode { /// The id of the image file. diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 96bd7e7e2..1ca9001d1 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -30,6 +30,7 @@ pub use shaping::*; pub use stack::*; pub use tree::*; +use std::fmt::Debug; use std::rc::Rc; use crate::font::FontStore; @@ -73,7 +74,7 @@ impl<'a> LayoutContext<'a> { } /// Layout a node. -pub trait Layout { +pub trait Layout: Debug { /// Layout the node into the given regions. fn layout( &self, diff --git a/src/layout/pad.rs b/src/layout/pad.rs index 506cb1107..d1b575a9d 100644 --- a/src/layout/pad.rs +++ b/src/layout/pad.rs @@ -1,6 +1,7 @@ use super::*; /// A node that adds padding to its child. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct PadNode { /// The amount of padding. diff --git a/src/layout/par.rs b/src/layout/par.rs index d7fbde160..dc2ce0eff 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -10,6 +10,7 @@ use crate::util::{EcoString, RangeExt, SliceExt}; type Range = std::ops::Range; /// A node that arranges its children into a paragraph. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct ParNode { /// The inline direction of this paragraph. @@ -21,6 +22,7 @@ pub struct ParNode { } /// A child of a paragraph node. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub enum ParChild { /// Spacing between other nodes. diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 211c8a7e4..4afe9c640 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -1,6 +1,7 @@ use super::*; /// A node that stacks its children. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct StackNode { /// The inline and block directions of this stack. @@ -13,6 +14,7 @@ pub struct StackNode { } /// A child of a stack node. +#[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub enum StackChild { /// Spacing between other nodes. diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 224313f65..28cbbb518 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -1,3 +1,5 @@ +use std::fmt::{self, Debug, Formatter}; + use super::*; use std::any::Any; @@ -9,6 +11,7 @@ use std::hash::{Hash, Hasher}; use fxhash::FxHasher64; /// A tree of layout nodes. +#[derive(Debug)] pub struct LayoutTree { /// Runs of pages with the same properties. pub runs: Vec, @@ -22,6 +25,7 @@ impl LayoutTree { } /// A run of pages that all have the same properties. +#[derive(Debug)] pub struct PageRun { /// The size of each page. pub size: Size, @@ -95,6 +99,12 @@ impl Layout for LayoutNode { } } +impl Debug for LayoutNode { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + self.node.fmt(f) + } +} + #[cfg(feature = "layout-cache")] impl Hash for LayoutNode { fn hash(&self, state: &mut H) {