Cache the table, prepare a screen when shown, keep the header still (#86)
CI / core (pull_request) Successful in 1m38s
CI / core (push) Successful in 1m39s

From the review of PR #96: the champion table becomes a cached view, so
the veil's frames no longer draw it; the screen arriving is prepared
only once shown, so a switch undone under the veil prepares nothing;
turning the Windows setting off drops the animation waiting as soon as
Windows says so; the Season and Format selectors move to the title row
of « Statistiques », under the veil, so the header keeps its height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WYQB8paBcLk67XoAUYARBK
This commit was merged in pull request #96.
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-21 18:51:42 +01:00
1 parent d7f5e23aea
commit c2d6296723
6 files changed
+143 -48

No files matched your search

+9
View File
@@ -49,6 +49,9 @@ pub struct ChampionTable {
/// The clicked champion's id: it stays selected through sorting and reloads.
selected: Option<u32>,
scroll: UniformListScrollHandle,
/// Guards the cache in tests.
#[cfg(test)]
pub(crate) renders: usize,
}
impl ChampionTable {
@@ -59,6 +62,8 @@ impl ChampionTable {
sort: None,
selected: None,
scroll: UniformListScrollHandle::new(),
#[cfg(test)]
renders: 0,
}
}
@@ -228,6 +233,10 @@ fn cell_text(row: &ChampionRow, key: SortKey) -> String {
impl Render for ChampionTable {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
#[cfg(test)]
{
self.renders += 1;
}
let theme = cx.theme();
let (background, border, radius, muted) = (
theme.table,
+12 -2
View File
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant};
use gpui_kit::base::apply_system_reduce_motion;
use gpui_kit::base::async_util::{Sender, unbounded};
use gpui_kit::{App, Window};
use gpui_kit::{App, Global, Window};
use windows::Win32::Foundation::{HWND, LPARAM, LRESULT, WPARAM};
use windows::Win32::UI::Shell::{DefSubclassProc, RemoveWindowSubclass, SetWindowSubclass};
use windows::Win32::UI::WindowsAndMessaging::{
@@ -170,12 +170,22 @@ pub(crate) fn follow_windows_setting(window: &Window, cx: &mut App) {
}
cx.spawn(async move |cx| {
while rx.recv().await.is_ok() {
cx.update(apply_system_reduce_motion);
cx.update(|cx| {
apply_system_reduce_motion(cx);
cx.set_global(AnimationSetting);
});
}
})
.detach();
}
/// Set again each time the Windows setting is read again, for the page to observe: turned off,
/// nothing animates any more and nothing waits.
#[derive(Default)]
pub(crate) struct AnimationSetting;
impl Global for AnimationSetting {}
/// The tray's subclass is 0.
const SETTING_SUBCLASS: usize = 1;
+89 -34
View File
@@ -30,7 +30,7 @@ use crate::card::Card;
use crate::card_grid::{CardGrid, CardHovered};
use crate::card_order::card_order;
use crate::champion_table::ChampionTable;
use crate::motion::{Deferred, Fade, FadePhase, MatchEnd};
use crate::motion::{AnimationSetting, Deferred, Fade, FadePhase, MatchEnd};
use crate::ring::{self, Ring, Tick};
use crate::text::{CLIENT_ABSENT, official_differs, sync_line};
use crate::worker::{
@@ -310,6 +310,13 @@ impl Page {
let subscriptions = vec![
Self::light_on_hover(&home_grid, cx),
Self::light_on_hover(&anvil_grid, cx),
// The Windows setting turned off: a transition running ends, and nothing waits.
cx.observe_global_in::<AnimationSetting>(window, |this, window, cx| {
if cx.reduce_motion() {
this.deferred.abandon();
this.end_fade(window, cx);
}
}),
// Minimised or hidden in the notification area, the window draws nothing: a
// transition ends at once, and an animation waits for it to show again.
cx.observe_window_visibility(window, |this, visibility, window, cx| {
@@ -673,12 +680,6 @@ impl Page {
}
if self.tab != tab {
self.tab = tab;
// The tab left was not kept up to date.
self.refresh_table(cx);
if self.home_cards_stale {
self.prepare_home_cards(cx);
}
self.refresh_home(cx);
if cx.reduce_motion() || !window.is_visible() {
// Nothing to see: the end state at once.
self.end_fade(window, cx);
@@ -703,6 +704,13 @@ impl Page {
return;
}
self.shown_tab = self.tab;
// The screen arriving was not kept up to date while hidden, and is prepared only now: a
// switch undone under the veil prepares nothing.
self.refresh_table(cx);
if self.home_cards_stale {
self.prepare_home_cards(cx);
}
self.refresh_home(cx);
if self.shown_tab == Tab::Statistics {
// The home grid is not shown: its portraits are given back, and come back with the
// grid.
@@ -737,10 +745,6 @@ impl Page {
let Some(fade) = &self.fade else {
return;
};
// The Windows setting was turned off meanwhile: the end state at once.
if cx.reduce_motion() {
return self.end_fade(window, cx);
}
let now = cx.background_executor().now();
if fade.finished(now) {
match fade.phase() {
@@ -1257,7 +1261,7 @@ impl Page {
/// One card per champion, in the cards' order, for when the statistics or the sort change.
/// While the home is not shown the next switch to it does (`home_cards_stale`).
fn prepare_home_cards(&mut self, cx: &mut Context<Self>) {
if self.tab != Tab::Challenge {
if self.shown_tab != Tab::Challenge {
self.home_cards_stale = true;
return;
}
@@ -1396,7 +1400,7 @@ impl Page {
/// Rebuilds the Statistics tab's rows; while it is not shown, the next switch does.
fn refresh_table(&mut self, cx: &mut Context<Self>) {
if self.tab != Tab::Statistics {
if self.shown_tab != Tab::Statistics {
return;
}
let rows = self.stats.iter().flat_map(|s| &s.rows);
@@ -1414,7 +1418,7 @@ impl Page {
/// Recomputes which cards the home shows from its own filter and search, with the total
/// untouched; while the home is not shown, the next switch does.
fn refresh_home(&mut self, cx: &mut Context<Self>) {
if self.tab != Tab::Challenge || self.in_champ_select() {
if self.shown_tab != Tab::Challenge || self.in_champ_select() {
return;
}
// The cards are the rows in the cards' order: a card's index is its position.
@@ -1575,11 +1579,7 @@ impl Render for Page {
.whitespace_nowrap()
.text_color(muted)
.child("Non mis à jour")
}))
// The Season and Format only exist where they are analysed.
.when(self.tab == Tab::Statistics, |group| {
group.children(self.statistics_selectors())
}),
})),
)
.child(
div().h_flex().items_center().gap_3().flex_shrink_0().child(
@@ -2263,6 +2263,7 @@ mod tests {
// Another Format on the Statistics tab: the home keeps its Challenge.
recompute(&mut window, &|page| {
page.tab = Tab::Statistics;
page.shown_tab = Tab::Statistics;
page.format = Some(Format::Arena3x6);
});
let (season, apart, same) = home(&mut window);
@@ -2878,6 +2879,14 @@ mod tests {
page.read_with(cx, |page, _| page.shown_tab)
}
/// Turns the Windows « Show animations » setting on or off, as its window message does.
fn animations(cx: &mut VisualTestContext, on: bool) {
cx.update(|_, cx| {
cx.set_reduce_motion(!on);
cx.set_global(crate::motion::AnimationSetting);
});
}
/// Asks for a tab, without waiting for its transition.
fn start_switch(page: &Entity<Page>, cx: &mut VisualTestContext, tab: Tab) {
cx.update(|window, cx| page.update(cx, |page, cx| page.set_tab(tab, window, cx)));
@@ -2921,13 +2930,13 @@ mod tests {
draw(cx);
// The Windows « Show animations » setting is off.
cx.update(|_, cx| cx.set_reduce_motion(true));
animations(cx, false);
start_switch(&page, cx, Tab::Statistics);
assert_eq!(shown_tab(&page, cx), Tab::Statistics);
assert!(page.read_with(cx, |page, _| page.fade.is_none()));
assert_at_rest(cx);
cx.update(|_, cx| cx.set_reduce_motion(false));
animations(cx, true);
cx.simulate_visibility_change(WindowVisibility::Hidden);
start_switch(&page, cx, Tab::Challenge);
assert_eq!(shown_tab(&page, cx), Tab::Challenge);
@@ -2979,8 +2988,15 @@ mod tests {
let cx = &mut { cx };
show(&page, cx, statistics(0, 170, champions(170)));
draw(cx);
let (grid, ring) =
page.read_with(cx, |page, _| (page.home_grid.clone(), page.ring.clone()));
let (grid, ring, table) = page.read_with(cx, |page, _| {
(
page.home_grid.clone(),
page.ring.clone(),
page.table.clone(),
)
});
let table_renders =
|cx: &mut VisualTestContext| table.read_with(cx, |table, _| table.renders);
let generation = page.read_with(cx, |page, _| page.stats_generation);
let built = |cx: &mut VisualTestContext| {
let ring = ring.read_with(cx, |ring, _| ring.renders);
@@ -2997,17 +3013,31 @@ mod tests {
}
assert_eq!(shown_tab(&page, cx), Tab::Statistics);
assert_eq!(built(cx), home, "the cards were built again");
// (The charts arriving play their own short entry, as after any switch.)
// « Statistiques » arrives: its table is drawn once, not at each frame of the veil. (The
// charts arriving play their own short entry, as after any switch.)
let arrived = table_renders(cx);
for _ in 0..8 {
frame_after(cx, 40);
}
assert_eq!(veil(&page, cx), 0.);
assert_eq!(
table_renders(cx),
arrived,
"the table was drawn at each frame"
);
// Back to « Défi »: the grid and the ring are drawn once, then not again.
// Back to « Défi »: the table leaves without being drawn again; the grid and the ring
// are drawn once, then not again.
start_switch(&page, cx, Tab::Challenge);
for _ in 0..5 {
for _ in 0..4 {
frame_after(cx, 30);
}
assert_eq!(
table_renders(cx),
arrived,
"the table was drawn at each frame"
);
frame_after(cx, 30);
assert_eq!(shown_tab(&page, cx), Tab::Challenge);
let back = built(cx);
for _ in 0..8 {
@@ -3022,6 +3052,25 @@ mod tests {
assert!(!page.read_with(cx, |page, _| page.stats_job.running()));
}
#[gpui::test]
fn a_switch_undone_under_the_veil_prepares_nothing(cx: &mut TestAppContext) {
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
show(&page, cx, statistics(0, 5, champions(5)));
draw(cx);
let table = page.read_with(cx, |page, _| page.table.clone());
start_switch(&page, cx, Tab::Statistics);
frame_after(cx, 60);
switch_tab(&page, cx, Tab::Challenge);
assert_eq!(shown_tab(&page, cx), Tab::Challenge);
// « Statistiques » was never shown: its rows were neither copied nor sorted.
assert!(table.read_with(cx, |table, _| table.names()).is_empty());
switch_tab(&page, cx, Tab::Statistics);
assert_eq!(table.read_with(cx, |table, _| table.names()).len(), 5);
}
fn animate(page: &Entity<Page>, cx: &mut VisualTestContext, end: MatchEnd) {
cx.update(|window, cx| page.update(cx, |page, cx| page.animate(end, window, cx)));
}
@@ -3100,17 +3149,24 @@ mod tests {
fn without_animations_nothing_waits_nor_plays(cx: &mut TestAppContext) {
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
// One waits while the window is hidden, then the setting is turned off.
animations(cx, false);
animate(&page, cx, MatchEnd::Mark);
cx.simulate_visibility_change(WindowVisibility::Hidden);
animate(&page, cx, MatchEnd::Completion);
cx.update(|_, cx| cx.set_reduce_motion(true));
animate(&page, cx, MatchEnd::Nothing);
cx.simulate_visibility_change(WindowVisibility::Visible);
animate(&page, cx, MatchEnd::Mark);
assert_eq!(played(&page, cx), []);
// Turned on again, it does not bring back the one that waited.
cx.update(|_, cx| cx.set_reduce_motion(false));
}
#[gpui::test]
fn the_setting_turned_off_drops_the_animation_waiting(cx: &mut TestAppContext) {
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
switch_tab(&page, cx, Tab::Statistics);
animate(&page, cx, MatchEnd::Completion);
// Off then on again, with nothing asked for meanwhile.
animations(cx, false);
animations(cx, true);
switch_tab(&page, cx, Tab::Challenge);
assert_eq!(played(&page, cx), []);
}
@@ -3123,8 +3179,7 @@ mod tests {
draw(cx);
start_switch(&page, cx, Tab::Statistics);
frame_after(cx, 30);
cx.update(|_, cx| cx.set_reduce_motion(true));
frame_after(cx, 16);
animations(cx, false);
assert_eq!(shown_tab(&page, cx), Tab::Statistics);
assert!(page.read_with(cx, |page, _| page.fade.is_none()));
assert_at_rest(cx);
+30 -9
View File
@@ -6,6 +6,7 @@ use gpui_kit::component::input::Input;
use gpui_kit::component::select::Select;
use gpui_kit::component::tab::{Tab, TabBar};
use gpui_kit::component::{ActiveTheme as _, StyledExt as _, Theme};
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
use super::{Page, shown};
@@ -304,14 +305,28 @@ impl Page {
let selected = options.iter().position(|(_, f)| *f == self.filter);
let challenge = self.stats.as_ref().and_then(|s| s.challenge.as_ref());
let mut content = Vec::new();
if shown("statistics-title") {
content.push(
heading(cx)
.text_3xl()
.child("Statistiques")
.into_any_element(),
);
}
// The Season and Format only exist where they are analysed: with the title, under the
// transition's veil, so the header does not change while the screen leaving is visible.
content.push(
div()
.h_flex()
.flex_wrap()
.items_center()
.justify_between()
.gap_3()
.when(shown("statistics-title"), |row| {
row.child(heading(cx).text_3xl().child("Statistiques"))
})
.child(
div()
.h_flex()
.items_center()
.gap_3()
.min_w_0()
.children(self.statistics_selectors()),
)
.into_any_element(),
);
if shown("tiles")
&& let Some(c) = challenge
{
@@ -357,7 +372,13 @@ impl Page {
div()
.flex_1()
.min_h(px(240.))
.child(self.table.clone())
// A cached view, laid out by the space the page gives it: the veil of a
// transition, which draws the page again at each frame, does not draw it.
.child(
self.table
.clone()
.cached(StyleRefinement::default().size_full()),
)
.into_any_element(),
);
}