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.
This commit is contained in:
Jonathan Johnson 2023-11-15 13:04:28 -08:00
parent 42840b950c
commit 294b1350c4
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
3 changed files with 0 additions and 16 deletions

View file

@ -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<T> MapManagedWidget<T> 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,
}
}
}

View file

@ -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<u64> {
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<LotId>,
parent: Option<LotId>,
layout: Option<Rect<Px>>,
invalidation: u64,
last_layout_query: Option<CachedLayoutQuery>,
associated_styles: Option<Value<Styles>>,
effective_styles: Styles,

View file

@ -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 {