stacking: Don't animate focus changes when scrolling
This commit is contained in:
parent
67bea79da2
commit
f655f58aa2
1 changed files with 34 additions and 18 deletions
|
|
@ -688,6 +688,13 @@ where
|
||||||
let state = tree.state.downcast_mut::<State>();
|
let state = tree.state.downcast_mut::<State>();
|
||||||
state.cleanup_old_animations();
|
state.cleanup_old_animations();
|
||||||
|
|
||||||
|
let mut bounds = layout.bounds();
|
||||||
|
let content_bounds = layout.children().fold(Size::new(0., 0.), |a, b| Size {
|
||||||
|
width: a.width + b.bounds().width,
|
||||||
|
height: b.bounds().height,
|
||||||
|
});
|
||||||
|
let scrolling = content_bounds.width.floor() > bounds.width;
|
||||||
|
|
||||||
let current_state = self.elements[2..self.elements.len() - 3]
|
let current_state = self.elements[2..self.elements.len() - 3]
|
||||||
.iter()
|
.iter()
|
||||||
.zip(layout.children().skip(2))
|
.zip(layout.children().skip(2))
|
||||||
|
|
@ -704,30 +711,39 @@ where
|
||||||
.symmetric_difference(&last_state.keys().collect::<HashSet<_>>())
|
.symmetric_difference(&last_state.keys().collect::<HashSet<_>>())
|
||||||
.next()
|
.next()
|
||||||
.is_some();
|
.is_some();
|
||||||
if unknown_keys
|
|
||||||
|| current_state.iter().any(|(a_id, a_bounds)| {
|
enum Difference {
|
||||||
let Some(b_bounds) = last_state.get(a_id) else { return true };
|
NewOrRemoved,
|
||||||
a_bounds != b_bounds
|
Movement,
|
||||||
|
Focus,
|
||||||
|
}
|
||||||
|
|
||||||
|
let changes = if unknown_keys {
|
||||||
|
Some(Difference::NewOrRemoved)
|
||||||
|
} else {
|
||||||
|
current_state.iter().filter_map(|(a_id, a_bounds)| {
|
||||||
|
let Some(b_bounds) = last_state.get(a_id) else { return Some(Difference::Movement) };
|
||||||
|
(a_bounds != b_bounds).then(|| if a_bounds.position() != b_bounds.position() { Difference::Movement } else { Difference::Focus })
|
||||||
|
}).fold(None, |a, b| match (a, b) {
|
||||||
|
(None | Some(Difference::Movement), x) => Some(x),
|
||||||
|
(a, _) => a,
|
||||||
})
|
})
|
||||||
{
|
};
|
||||||
// new tab_animation
|
|
||||||
state.tab_animations.push_back(TabAnimationState {
|
if unknown_keys || changes.is_some() {
|
||||||
previous_bounds: last_state.clone(),
|
if !scrolling || !matches!(changes, Some(Difference::Focus)) {
|
||||||
next_bounds: current_state.clone(),
|
// new tab_animation
|
||||||
start_time: Instant::now(),
|
state.tab_animations.push_back(TabAnimationState {
|
||||||
});
|
previous_bounds: last_state.clone(),
|
||||||
|
next_bounds: current_state.clone(),
|
||||||
|
start_time: Instant::now(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// update last_state
|
// update last_state
|
||||||
*last_state = current_state;
|
*last_state = current_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bounds = layout.bounds();
|
|
||||||
let content_bounds = layout.children().fold(Size::new(0., 0.), |a, b| Size {
|
|
||||||
width: a.width + b.bounds().width,
|
|
||||||
height: b.bounds().height,
|
|
||||||
});
|
|
||||||
let scrolling = content_bounds.width.floor() > bounds.width;
|
|
||||||
|
|
||||||
if scrolling {
|
if scrolling {
|
||||||
bounds.x += 30.;
|
bounds.x += 30.;
|
||||||
bounds.width -= 64.;
|
bounds.width -= 64.;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue