Keep the ring's shapes on scroll, free a hidden splash, keep the hover's grid (#84)
CI / core (pull_request) Successful in 1m42s
CI / core (push) Successful in 1m40s

From the second review of PR #94:
- The ring's fixed shapes are made at the origin and moved where it is
  painted: a scroll that moves the ring tessellates nothing.
- The banner's splash is neither decoded nor held while the banner is
  scrolled out of view, and is given back, from the atlas too.
- The tick follows the grid that lit it: another grid saying none of its
  cards is under the pointer, or « Autres champions » folding, leaves it.

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 #94.
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-21 17:53:46 +01:00
1 parent 4fb8b37509
commit 411d139a75
4 files changed
+146 -13

No files matched your search

+115 -4
View File
@@ -179,6 +179,8 @@ pub struct Page {
banner: home::BannerContent,
/// The banner's ring: a cached view.
ring: Entity<Ring>,
/// The grid whose card lit the ring's tick.
lit_by: Option<EntityId>,
/// The banner's illustration, its own: given back while the banner is not shown.
banner_art: Entity<BannerArt>,
/// The home's own filter and search: never persisted, « Tous » at each launch.
@@ -419,6 +421,7 @@ impl Page {
home_computed: None,
banner: home::BannerContent::default(),
ring,
lit_by: None,
banner_art,
home_filter: StateFilter::All,
home_search: ChampionSearch::new(""),
@@ -1008,16 +1011,30 @@ impl Page {
/// Lights the ring's tick of the card under the pointer in `grid`.
fn light_on_hover(grid: &Entity<CardGrid>, cx: &mut Context<Self>) -> Subscription {
cx.subscribe(grid, |this, _, CardHovered(id): &CardHovered, cx| {
this.ring.update(cx, |ring, cx| ring.set_lit(*id, cx));
cx.subscribe(grid, |this, grid, CardHovered(id): &CardHovered, cx| {
this.light(grid.entity_id(), *id, cx);
})
}
/// A new grid for « Autres champions », whose hover lights the ring as the others do.
/// The card under the pointer in `grid` changed to `id`. The tick follows the grid that lit
/// it: another grid saying that none of its cards is under the pointer (the pointer went from
/// it to this one, or it was folded) leaves the tick lit.
fn light(&mut self, grid: EntityId, id: Option<u32>, cx: &mut Context<Self>) {
match id {
Some(_) => self.lit_by = Some(grid),
None if self.lit_by == Some(grid) => self.lit_by = None,
None => return,
}
self.ring.update(cx, |ring, cx| ring.set_lit(id, cx));
}
/// A new grid for « Autres champions », whose hover lights the ring as the others do. The
/// one it replaces puts out the tick it lit.
fn new_others_grid(&mut self, cx: &mut Context<Self>) {
let replaced = self.others_grid.entity_id();
self.others_grid = cx.new(|_| CardGrid::new());
self.others_hover = Self::light_on_hover(&self.others_grid, cx);
self.ring.update(cx, |ring, cx| ring.set_lit(None, cx));
self.light(replaced, None, cx);
}
/// Computes the cards' order again: for when the home statistics (the champ select's during
@@ -4790,4 +4807,98 @@ mod tests {
cx.condition(&page, |p, _| p.stats.is_some()).await;
assert!(!banner(&page, &mut window).title.text.is_empty());
}
#[gpui::test]
fn scrolling_the_home_moves_the_ring_as_it_is_and_gives_back_a_splash_out_of_view(
cx: &mut TestAppContext,
) {
let dir = TestDir::new("banner-scrolled");
let (page, cx) = open_page_in_season(cx);
let cx = &mut { cx };
show(
&page,
cx,
banner_statistics(rows_with_splashes(dir.path()), vec![2, 1], None),
);
cx.simulate_resize(size(px(600.), px(340.)));
draw_loaded(cx);
assert_eq!(held_splashes(&page, cx), ["Ahri.50.30.jpg"]);
let splash = loaded_splashes(&page, cx);
let ring = page.read_with(cx, |p, _| p.ring.clone());
let tessellations =
|cx: &mut VisualTestContext| ring.read_with(cx, |ring, _| ring.tessellations.get());
let shapes = tessellations(cx);
let scroll = |cx: &mut VisualTestContext, by: f32| {
let at = center(cx, "banner");
cx.simulate_event(ScrollEvent {
position: at,
delta: ScrollDelta::Pixels(point(px(0.), px(by))),
..Default::default()
});
draw(cx);
};
// The ring moves with the column, as it is.
let top = cx.debug_bounds("ring").unwrap().top();
scroll(cx, -30.);
assert!(cx.debug_bounds("ring").unwrap().top() < top);
assert_eq!(tessellations(cx), shapes);
// Down to the grid: the banner is out of view, and so is its splash, from the atlas too.
scroll(cx, -2000.);
assert!(held_splashes(&page, cx).is_empty());
assert!(!in_atlas(cx, &splash[0]));
// Back up: it comes back.
let at = center(cx, "card-1");
cx.simulate_event(ScrollEvent {
position: at,
delta: ScrollDelta::Pixels(point(px(0.), px(4000.))),
..Default::default()
});
draw_loaded(cx);
assert_eq!(held_splashes(&page, cx), ["Ahri.50.30.jpg"]);
}
#[gpui::test]
async fn the_tick_stays_with_the_grid_that_lit_it(cx: &mut TestAppContext) {
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
let cx = &mut window;
cx.simulate_resize(size(px(1280.), px(1300.)));
draw(cx);
click_others(cx);
let lit = |cx: &mut VisualTestContext| page.read_with(cx, |p, cx| p.ring.read(cx).lit());
let hover = |cx: &mut VisualTestContext, id: &'static str| {
let at = center(cx, id);
cx.simulate_mouse_move(at, None, Modifiers::none());
draw(cx);
};
// From an Anvil champion straight to a card of « Autres champions », and back.
hover(cx, "card-233");
assert_eq!(lit(cx), Some(233));
hover(cx, "card-103");
assert_eq!(lit(cx), Some(103));
hover(cx, "card-233");
assert_eq!(lit(cx), Some(233));
// Folding « Autres champions » under a still pointer leaves the Anvil champion's tick
// lit: the grid it replaces only puts out a tick it lit.
page.update(cx, |page, cx| page.toggle_others(cx));
draw(cx);
assert!(!others_open(&page, cx));
assert_eq!(lit(cx), Some(233));
// A key press ends every hover for GPUI until the pointer moves (the card's sheet goes
// too): the tick follows the card.
cx.update(|window, cx| {
let focus = page.read(cx).others_focus.clone();
focus.focus(window, cx);
});
activate(cx, "enter");
assert!(others_open(&page, cx));
assert_eq!(lit(cx), None);
hover(cx, "card-233");
assert_eq!(lit(cx), Some(233));
}
}
+7
View File
@@ -538,6 +538,13 @@ fn banner_art(
let image = canvas(
|_, _, _| {},
move |bounds, _, window, cx| {
// Scrolled entirely out of the column (a low window): nothing to show, so nothing
// decoded nor held, and it comes back with the banner.
let visible = bounds.intersect(&window.content_mask().bounds);
if visible.size.width <= Pixels::ZERO || visible.size.height <= Pixels::ZERO {
art.update(cx, |art, cx| art.release(window, cx));
return;
}
let Some((image, focus)) = art.update(cx, |art, cx| art.image(&splash, cx)) else {
return;
};
+23 -8
View File
@@ -132,15 +132,20 @@ impl Frame {
/// The ring's fixed shapes for one size and one set of ticks: tessellated once, painted again as
/// they are when only the lit tick changes.
struct Geometry {
bounds: Bounds<Pixels>,
/// The size it was made for: it is made at the origin, and moved where the ring is painted,
/// so a scroll that moves the ring does not make it again.
size: Size<Pixels>,
/// One path per state of tick.
ticks: Vec<(ChampionState, Path<Pixels>)>,
crown: Option<Path<Pixels>>,
}
impl Geometry {
fn new(bounds: Bounds<Pixels>, ticks: &[Tick]) -> Geometry {
let frame = Frame::of(bounds);
fn new(size: Size<Pixels>, ticks: &[Tick]) -> Geometry {
let frame = Frame::of(Bounds {
origin: Point::default(),
size,
});
let count = ticks.len();
let states = [
ChampionState::Completed,
@@ -168,13 +173,23 @@ impl Geometry {
.collect();
crown.add_polygon(&points, true);
Geometry {
bounds,
size,
ticks,
crown: crown.build().ok(),
}
}
}
/// A copy of `path`, made at the origin, moved `by`.
fn moved(path: &Path<Pixels>, by: Point<Pixels>) -> Path<Pixels> {
let mut path = path.clone();
path.bounds.origin += by;
for vertex in &mut path.vertices {
vertex.xy_position += by;
}
path
}
pub struct Ring {
ticks: Rc<[Tick]>,
/// The champion whose card is under the pointer.
@@ -267,20 +282,20 @@ impl Render for Ring {
let disc_bounds = Bounds::centered_at(centre, size(radius * 2., radius * 2.));
window.paint_quad(fill(disc_bounds, disc).corner_radii(radius));
let mut geometry = geometry.borrow_mut();
if geometry.as_ref().is_none_or(|g| g.bounds != bounds) {
if geometry.as_ref().is_none_or(|g| g.size != bounds.size) {
#[cfg(test)]
tessellations.set(tessellations.get() + 1);
*geometry = Some(Geometry::new(bounds, &ticks));
*geometry = Some(Geometry::new(bounds.size, &ticks));
}
let Some(geometry) = geometry.as_ref() else {
return;
};
for (state, path) in &geometry.ticks {
let color = colors.iter().find(|(s, _)| s == state).map(|(_, c)| *c);
window.paint_path(path.clone(), color.unwrap_or(crown));
window.paint_path(moved(path, bounds.origin), color.unwrap_or(crown));
}
if let Some(path) = &geometry.crown {
window.paint_path(path.clone(), crown);
window.paint_path(moved(path, bounds.origin), crown);
}
// Only the lit tick is tessellated when the pointer changes card.
if let Some((index, state)) = lit {