summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-26 00:08:08 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-26 00:08:08 +0200
commit56cbf96fe2b3b82d34b2e69a49bcb7b0c0267f6a (patch)
treed3507c4cb6bb9cc8f269293758036e7172a5ef21 /src
parent88d3be258114d631f6e1381e756ff9bb8aba6b0e (diff)
Move incremental test into separate function
Diffstat (limited to 'src')
-rw-r--r--src/layout/tree.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/layout/tree.rs b/src/layout/tree.rs
index 258f1ccc..77b01ad2 100644
--- a/src/layout/tree.rs
+++ b/src/layout/tree.rs
@@ -51,6 +51,15 @@ pub struct LayoutNode {
impl LayoutNode {
/// Create a new instance from any node that satisifies the required bounds.
+ #[cfg(not(feature = "layout-cache"))]
+ pub fn new<T>(node: T) -> Self
+ where
+ T: Layout + Debug + Clone + Eq + PartialEq + 'static,
+ {
+ Self { node: Box::new(node) }
+ }
+
+ /// Create a new instance from any node that satisifies the required bounds.
#[cfg(feature = "layout-cache")]
pub fn new<T>(node: T) -> Self
where
@@ -65,15 +74,6 @@ impl LayoutNode {
Self { node: Box::new(node), hash }
}
-
- /// Create a new instance from any node that satisifies the required bounds.
- #[cfg(not(feature = "layout-cache"))]
- pub fn new<T>(node: T) -> Self
- where
- T: Layout + Debug + Clone + Eq + PartialEq + 'static,
- {
- Self { node: Box::new(node) }
- }
}
impl Layout for LayoutNode {
@@ -82,20 +82,17 @@ impl Layout for LayoutNode {
ctx: &mut LayoutContext,
regions: &Regions,
) -> Vec<Constrained<Rc<Frame>>> {
+ #[cfg(not(feature = "layout-cache"))]
+ return self.node.layout(ctx, regions);
+
#[cfg(feature = "layout-cache")]
- {
+ ctx.layouts.get(self.hash, regions.clone()).unwrap_or_else(|| {
ctx.level += 1;
- let frames = ctx.layouts.get(self.hash, regions.clone()).unwrap_or_else(|| {
- let frames = self.node.layout(ctx, regions);
- ctx.layouts.insert(self.hash, frames.clone(), ctx.level - 1);
- frames
- });
+ let frames = self.node.layout(ctx, regions);
ctx.level -= 1;
+ ctx.layouts.insert(self.hash, frames.clone(), ctx.level);
frames
- }
-
- #[cfg(not(feature = "layout-cache"))]
- self.node.layout(ctx, regions)
+ })
}
}