diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-10-13 18:33:10 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-10-23 20:22:47 +0200 |
| commit | 1e74f7c407e42174b631cb7477f3c88252da7e25 (patch) | |
| tree | 53c0510b6503c434c9ba470b188d9e737ce1c3cf /src/layout/tree.rs | |
| parent | 5f4dde0a6b32c7620b29af30f69591cf3995af9b (diff) | |
New `ShapeNode`
Replaces `BackgroundNode` and `FixedNode`
Diffstat (limited to 'src/layout/tree.rs')
| -rw-r--r-- | src/layout/tree.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 38ba6e85..900eb1a9 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -50,8 +50,9 @@ impl PageRun { } /// A dynamic layouting node. +#[derive(Clone)] pub struct LayoutNode { - node: Box<dyn Layout>, + node: Rc<dyn Layout>, #[cfg(feature = "layout-cache")] hash: u64, } @@ -63,7 +64,7 @@ impl LayoutNode { where T: Layout + 'static, { - Self { node: Box::new(node) } + Self { node: Rc::new(node) } } /// Create a new instance from any node that satisifies the required bounds. @@ -79,7 +80,7 @@ impl LayoutNode { state.finish() }; - Self { node: Box::new(node), hash } + Self { node: Rc::new(node), hash } } } @@ -99,10 +100,16 @@ impl Layout for LayoutNode { ctx.level -= 1; let entry = FramesEntry::new(frames.clone(), ctx.level); - debug_assert!( - entry.check(regions), - "constraints did not match regions they were created for", - ); + + #[cfg(debug_assertions)] + if !entry.check(regions) { + eprintln!("regions: {:#?}", regions); + eprintln!( + "constraints: {:#?}", + frames.iter().map(|c| c.constraints).collect::<Vec<_>>() + ); + panic!("constraints did not match regions they were created for"); + } ctx.layouts.insert(self.hash, entry); frames |
