From 294b1350c4bc15112461b0e90eabacb78f3e4843 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Wed, 15 Nov 2023 13:04:28 -0800 Subject: [PATCH] Fixing button animations being "slow" The issue was that my last set of changes were causing the animations to restart, causing the animation to keep being extended to another 150ms. I think the only way for this to work is to switch to an event mechanism to notify widgets once they've been invalidated. This event could include a parameter stating whether it was a direct invalidation or an invalidation due to another widget in the hierarchy. Button doesn't really care about the rest of the hierarchy, it only cares about its own state, and the cache key was including too many changes. --- src/context.rs | 4 ---- src/tree.rs | 8 -------- src/widget.rs | 4 ---- 3 files changed, 16 deletions(-) diff --git a/src/context.rs b/src/context.rs index 0cb8ae0..1146fdd 100644 --- a/src/context.rs +++ b/src/context.rs @@ -776,7 +776,6 @@ impl<'context, 'window> WidgetContext<'context, 'window> { cache: WidgetCacheKey { theme_mode, enabled, - invalidation: current_node.invalidation(), }, cursor, current_node, @@ -826,7 +825,6 @@ impl<'context, 'window> WidgetContext<'context, 'window> { cache: WidgetCacheKey { theme_mode, enabled: current_node.enabled(&self.handle()), - invalidation: current_node.invalidation(), }, current_node, redraw_status: self.redraw_status, @@ -1263,7 +1261,6 @@ impl MapManagedWidget for ManagedWidget { pub struct WidgetCacheKey { theme_mode: ThemeMode, enabled: bool, - invalidation: u64, } impl Default for WidgetCacheKey { @@ -1271,7 +1268,6 @@ impl Default for WidgetCacheKey { Self { theme_mode: ThemeMode::default().inverse(), enabled: false, - invalidation: u64::MAX, } } } diff --git a/src/tree.rs b/src/tree.rs index 462fbf7..afdf43f 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -45,7 +45,6 @@ impl Tree { effective_styles, theme: None, theme_mode: None, - invalidation: 0, }); data.nodes_by_id.insert(id, node_id); if widget.is_default() { @@ -282,11 +281,6 @@ impl Tree { data.widget_from_node(id, self) } - pub(crate) fn invalidation(&self, id: LotId) -> Option { - let data = self.data.lock().ignore_poison(); - data.nodes.get(id).map(|node| node.invalidation) - } - pub(crate) fn is_enabled(&self, mut id: LotId, context: &WindowHandle) -> bool { let data = self.data.lock().ignore_poison(); loop { @@ -513,7 +507,6 @@ impl TreeData { let mut node = &mut self.nodes[id]; while node.layout.is_some() { node.layout = None; - node.invalidation += 1; node.last_layout_query = None; let (true, Some(parent)) = (include_hierarchy, node.parent) else { @@ -585,7 +578,6 @@ struct Node { children: Vec, parent: Option, layout: Option>, - invalidation: u64, last_layout_query: Option, associated_styles: Option>, effective_styles: Styles, diff --git a/src/widget.rs b/src/widget.rs index 4673918..c063c23 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -1186,10 +1186,6 @@ impl ManagedWidget { self.tree.is_enabled(self.node_id, handle) } - pub(crate) fn invalidation(&self) -> u64 { - self.tree.invalidation(self.node_id).expect("missing node") - } - /// Returns true if this widget is currently the hovered widget. #[must_use] pub fn hovered(&self) -> bool {