diff options
| author | Martin <mhaug@live.de> | 2021-06-18 13:01:55 +0200 |
|---|---|---|
| committer | Martin <mhaug@live.de> | 2021-06-18 13:01:55 +0200 |
| commit | 80a9b300d1acb8821ac0600aad3d2135ad9587bd (patch) | |
| tree | 6626ba8891fa4db4e3a1cb13f7f4b27fc05989bf /src/layout/mod.rs | |
| parent | 7db78d83bedf62adea0d715c9a2a179ce23a1a48 (diff) | |
Ref count the frames
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 28e83da9..f1ae3e2a 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -23,6 +23,7 @@ pub use stack::*; use std::any::Any; use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher}; +use std::rc::Rc; use fxhash::FxHasher64; @@ -31,7 +32,7 @@ use crate::geom::*; use crate::loading::Loader; /// Layout a tree into a collection of frames. -pub fn layout(loader: &mut dyn Loader, cache: &mut Cache, tree: &Tree) -> Vec<Frame> { +pub fn layout(loader: &mut dyn Loader, cache: &mut Cache, tree: &Tree) -> Vec<Rc<Frame>> { tree.layout(&mut LayoutContext { loader, cache, level: 0 }) } @@ -44,7 +45,7 @@ pub struct Tree { impl Tree { /// Layout the tree into a collection of frames. - pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<Frame> { + pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<Rc<Frame>> { self.runs.iter().flat_map(|run| run.layout(ctx)).collect() } } @@ -61,7 +62,7 @@ pub struct PageRun { impl PageRun { /// Layout the page run. - pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<Frame> { + pub fn layout(&self, ctx: &mut LayoutContext) -> Vec<Rc<Frame>> { // When one of the lengths is infinite the page fits its content along // that axis. let Size { width, height } = self.size; @@ -97,7 +98,7 @@ impl Layout for AnyNode { &self, ctx: &mut LayoutContext, regions: &Regions, - ) -> Vec<Constrained<Frame>> { + ) -> Vec<Constrained<Rc<Frame>>> { ctx.level += 1; let frames = ctx .cache @@ -179,7 +180,7 @@ pub trait Layout { &self, ctx: &mut LayoutContext, regions: &Regions, - ) -> Vec<Constrained<Frame>>; + ) -> Vec<Constrained<Rc<Frame>>>; } /// The context for layouting. @@ -188,7 +189,7 @@ pub struct LayoutContext<'a> { pub loader: &'a mut dyn Loader, /// A cache for loaded fonts and artifacts from past layouting. pub cache: &'a mut Cache, - /// How deeply nested is the current layout tree position. + /// How deeply nested the current layout tree position is. pub level: usize, } |
