diff options
| author | Martin <mhaug@live.de> | 2021-06-18 13:00:36 +0200 |
|---|---|---|
| committer | Martin <mhaug@live.de> | 2021-06-18 13:00:36 +0200 |
| commit | 7db78d83bedf62adea0d715c9a2a179ce23a1a48 (patch) | |
| tree | 71c1db7fe3fae60390e46e18148c5b252b811c48 /src/layout/mod.rs | |
| parent | 2a30c20f0e2c3b51d3b2746a60e15008f1aa2619 (diff) | |
Levels
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 15c80017..28e83da9 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -32,7 +32,7 @@ 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> { - tree.layout(&mut LayoutContext { loader, cache }) + tree.layout(&mut LayoutContext { loader, cache, level: 0 }) } /// A tree of layout nodes. @@ -98,19 +98,23 @@ impl Layout for AnyNode { ctx: &mut LayoutContext, regions: &Regions, ) -> Vec<Constrained<Frame>> { - ctx.cache + ctx.level += 1; + let frames = ctx + .cache .layout .frames .get(&self.hash) .and_then(|x| x.check(regions.clone())) .unwrap_or_else(|| { let frames = self.node.layout(ctx, regions); - ctx.cache - .layout - .frames - .insert(self.hash, FramesEntry { frames: frames.clone() }); + ctx.cache.layout.frames.insert(self.hash, FramesEntry { + frames: frames.clone(), + level: ctx.level - 1, + }); frames - }) + }); + ctx.level -= 1; + frames } } @@ -184,6 +188,8 @@ 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. + pub level: usize, } /// A sequence of regions to layout into. |
