From 05190d6b591dab0187edcbe8f54c1c83d9276278 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:26:40 +0000 Subject: [PATCH] Expose `transform_has_changed` and use that instead --- masonry/src/contexts.rs | 9 +++++++++ xilem/src/view/transform.rs | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/masonry/src/contexts.rs b/masonry/src/contexts.rs index 1a4d8efd4..3d9dbcfc0 100644 --- a/masonry/src/contexts.rs +++ b/masonry/src/contexts.rs @@ -236,6 +236,15 @@ impl MutateCtx<'_> { widget_children: self.widget_children.reborrow_mut(), } } + + /// Whether the (local) transform of this widget has been modified since + /// the last time this widget's transformation was resolved. + /// + /// This is exposed for Xilem, and is more likely to change or be removed + /// in major releases of Masonry. + pub fn transform_has_changed(&self) -> bool { + self.widget_state.transform_changed + } } // --- MARK: WIDGET_REF --- diff --git a/xilem/src/view/transform.rs b/xilem/src/view/transform.rs index 5af650f86..8a2e974eb 100644 --- a/xilem/src/view/transform.rs +++ b/xilem/src/view/transform.rs @@ -115,16 +115,14 @@ where ctx: &mut ViewCtx, mut element: xilem_core::Mut<'_, Self::Element>, ) { - let initial_transform = element.ctx.transform(); self.child.rebuild( &prev.child, &mut view_state.child, ctx, element.reborrow_mut(), ); - let transform_changed = element.ctx.transform() != initial_transform; - // We detect a child view changing the transform by comparing the - // resulting transform before and after the child view runs. + let transform_changed = element.ctx.transform_has_changed(); + // If the child view changed the transform, we know we're out of date. if transform_changed { // If it has changed the transform, then we know that it will only be due to effects // "below us" (that is, it will have restarted from scratch).