mirror of
https://github.com/typst/typst
synced 2025-05-13 20:46:23 +08:00
Reimplement Debug
for layout nodes
This commit is contained in:
parent
b0b4607725
commit
18190f377a
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -10,6 +10,7 @@ use crate::util::{EcoString, RangeExt, SliceExt};
|
||||
type Range = std::ops::Range<usize>;
|
||||
|
||||
/// 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.
|
||||
|
@ -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.
|
||||
|
@ -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<PageRun>,
|
||||
@ -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<H: Hasher>(&self, state: &mut H) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user