mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Reimplement Debug
for layout nodes
This commit is contained in:
parent
b0b4607725
commit
18190f377a
@ -1,6 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A node that places a rectangular filled background behind its child.
|
/// A node that places a rectangular filled background behind its child.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub struct BackgroundNode {
|
pub struct BackgroundNode {
|
||||||
/// The kind of shape to use as a background.
|
/// The kind of shape to use as a background.
|
||||||
|
@ -3,6 +3,7 @@ use decorum::N64;
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A node that can fix its child's width and height.
|
/// A node that can fix its child's width and height.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub struct FixedNode {
|
pub struct FixedNode {
|
||||||
/// The fixed width, if any.
|
/// The fixed width, if any.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A node that arranges its children in a grid.
|
/// A node that arranges its children in a grid.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub struct GridNode {
|
pub struct GridNode {
|
||||||
/// The inline (columns) and block (rows) directions of this grid.
|
/// The inline (columns) and block (rows) directions of this grid.
|
||||||
|
@ -4,6 +4,7 @@ use crate::image::ImageId;
|
|||||||
use ::image::GenericImageView;
|
use ::image::GenericImageView;
|
||||||
|
|
||||||
/// An image node.
|
/// An image node.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub struct ImageNode {
|
pub struct ImageNode {
|
||||||
/// The id of the image file.
|
/// The id of the image file.
|
||||||
|
@ -30,6 +30,7 @@ pub use shaping::*;
|
|||||||
pub use stack::*;
|
pub use stack::*;
|
||||||
pub use tree::*;
|
pub use tree::*;
|
||||||
|
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::font::FontStore;
|
use crate::font::FontStore;
|
||||||
@ -73,7 +74,7 @@ impl<'a> LayoutContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Layout a node.
|
/// Layout a node.
|
||||||
pub trait Layout {
|
pub trait Layout: Debug {
|
||||||
/// Layout the node into the given regions.
|
/// Layout the node into the given regions.
|
||||||
fn layout(
|
fn layout(
|
||||||
&self,
|
&self,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A node that adds padding to its child.
|
/// A node that adds padding to its child.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub struct PadNode {
|
pub struct PadNode {
|
||||||
/// The amount of padding.
|
/// The amount of padding.
|
||||||
|
@ -10,6 +10,7 @@ use crate::util::{EcoString, RangeExt, SliceExt};
|
|||||||
type Range = std::ops::Range<usize>;
|
type Range = std::ops::Range<usize>;
|
||||||
|
|
||||||
/// A node that arranges its children into a paragraph.
|
/// A node that arranges its children into a paragraph.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub struct ParNode {
|
pub struct ParNode {
|
||||||
/// The inline direction of this paragraph.
|
/// The inline direction of this paragraph.
|
||||||
@ -21,6 +22,7 @@ pub struct ParNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A child of a paragraph node.
|
/// A child of a paragraph node.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub enum ParChild {
|
pub enum ParChild {
|
||||||
/// Spacing between other nodes.
|
/// Spacing between other nodes.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// A node that stacks its children.
|
/// A node that stacks its children.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub struct StackNode {
|
pub struct StackNode {
|
||||||
/// The inline and block directions of this stack.
|
/// The inline and block directions of this stack.
|
||||||
@ -13,6 +14,7 @@ pub struct StackNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A child of a stack node.
|
/// A child of a stack node.
|
||||||
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
#[cfg_attr(feature = "layout-cache", derive(Hash))]
|
||||||
pub enum StackChild {
|
pub enum StackChild {
|
||||||
/// Spacing between other nodes.
|
/// Spacing between other nodes.
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::{self, Debug, Formatter};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
@ -9,6 +11,7 @@ use std::hash::{Hash, Hasher};
|
|||||||
use fxhash::FxHasher64;
|
use fxhash::FxHasher64;
|
||||||
|
|
||||||
/// A tree of layout nodes.
|
/// A tree of layout nodes.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct LayoutTree {
|
pub struct LayoutTree {
|
||||||
/// Runs of pages with the same properties.
|
/// Runs of pages with the same properties.
|
||||||
pub runs: Vec<PageRun>,
|
pub runs: Vec<PageRun>,
|
||||||
@ -22,6 +25,7 @@ impl LayoutTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A run of pages that all have the same properties.
|
/// A run of pages that all have the same properties.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct PageRun {
|
pub struct PageRun {
|
||||||
/// The size of each page.
|
/// The size of each page.
|
||||||
pub size: Size,
|
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")]
|
#[cfg(feature = "layout-cache")]
|
||||||
impl Hash for LayoutNode {
|
impl Hash for LayoutNode {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user