From b78be1ff0bea84a68d6cf90365c152595c35f573 Mon Sep 17 00:00:00 2001
From: TO
Date: Sat, 21 Nov 2026 19:18:31 +0100
Subject: [PATCH 1/4] Lift the hovered card over a cached grid (#88)
The card under the pointer or the keyboard rises over its grid in about
0.35 s: 10 px with a gold glow, 4 px without for a greyed card, the
illustration zooming to 107 % inside it while the caption fades and the
sheet slides up over the lower half. Leaving it mid-way starts from where
it is; a wheel drops it at once; in the hand a veil lays on the other
cards. With Windows animations off the sheet shows without sliding and
the card stays put.
The grids never change on hover or focus any more: they record where
they placed their visible cards, and the page draws the lifted cards in
a deferred layer over them, asking for frames only while one moves.
Structural tests check that a hover, through its animation, draws no
grid, builds no card and computes no statistics.
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01WYQB8paBcLk67XoAUYARBK
---
crates/app/src/card.rs | 215 +++++++++++++++----
crates/app/src/card_grid.rs | 132 ++++++++----
crates/app/src/card_lift.rs | 414 ++++++++++++++++++++++++++++++++++++
crates/app/src/main.rs | 1 +
crates/app/src/motion.rs | 2 +-
crates/app/src/page.rs | 322 ++++++++++++++++++++++++----
crates/app/src/page/home.rs | 9 +-
crates/app/src/theme.rs | 9 +
docs/interface.md | 4 +-
docs/performance.md | 1 +
10 files changed, 982 insertions(+), 127 deletions(-)
create mode 100644 crates/app/src/card_lift.rs
diff --git a/crates/app/src/card.rs b/crates/app/src/card.rs
index 7e11533..f48d206 100644
--- a/crates/app/src/card.rs
+++ b/crates/app/src/card.rs
@@ -10,7 +10,7 @@ use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
use crate::text::{ordinal, thousands};
-use crate::theme::{LOGO_GOLD, ON_GOLD, surface};
+use crate::theme::{LOGO_GOLD, ON_GOLD, gold_glow, surface};
/// Width over height: the ratio the stored portraits are cropped to.
pub const ASPECT: f32 = arena_tracker_core::CARD_ASPECT as f32;
@@ -114,14 +114,54 @@ pub struct Card {
pub sheet: Vec<(&'static str, SharedString)>,
}
-/// What the grid knows of a card that the card does not: whether to show its sheet, and the
-/// focus handle that makes it reachable with the keyboard.
-#[derive(Clone, Copy, Default)]
-pub struct CardState<'a> {
- pub sheet: bool,
- pub focus: Option<&'a FocusHandle>,
+/// How far a card is lifted over its grid (#88), drawn over it while the pointer or the keyboard
+/// is on it: it rises, its illustration zooms in, its caption fades and its sheet slides up from
+/// the bottom.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Pose {
+ /// 0 at rest, 1 lifted all the way.
+ pub progress: f32,
+ /// The hand's veil on this card: 0 to 1.
+ pub veil: f32,
+ /// Off with the Windows « Show animations » setting: the sheet shows, the card stays put.
+ pub moves: bool,
}
+/// How high a card rises: less for a greyed one, which cannot be picked.
+const RISE: f32 = 10.;
+const GREYED_RISE: f32 = 4.;
+/// How much the illustration zooms in, inside the card.
+const ZOOM: f32 = 0.07;
+/// How far the sheet slides up, and the caption down.
+const SHEET_SLIDE: f32 = 14.;
+const CAPTION_SLIDE: f32 = 6.;
+const CAPTION_BOTTOM: f32 = 12.;
+/// The hand's veil on the other cards, as the mockup's `rgba(9, 11, 24, .42)`.
+const VEIL: u32 = 0x090b18;
+const VEIL_OPACITY: f32 = 0.42;
+
+impl Pose {
+ /// How many pixels the card is above its place.
+ pub fn rise(&self, card: &Card) -> f32 {
+ if !self.moves {
+ return 0.;
+ }
+ self.progress * if card.greyed() { GREYED_RISE } else { RISE }
+ }
+
+ fn zoom(&self) -> f32 {
+ if self.moves { self.progress * ZOOM } else { 0. }
+ }
+}
+
+/// The hand's veil on a card at rest in it, `veil` from 0 to 1.
+pub fn veil_color(veil: f32) -> Hsla {
+ Hsla::from(rgb(VEIL)).opacity(VEIL_OPACITY * veil)
+}
+
+/// The radius of a card, for what is drawn over one.
+pub const CARD_RADIUS: f32 = RADIUS;
+
impl Card {
/// A row without a Challenge (no Season) has no Marks.
pub fn from_row(row: &ChampionRow) -> Card {
@@ -205,36 +245,80 @@ fn sheet_lines(row: &ChampionRow) -> Vec<(&'static str, SharedString)> {
lines
}
-/// One card, as wide as its parent gives it, `ASPECT` wide over tall. Hovering only changes the
-/// border colour; the sheet covers it when `state` says so, and a focus handle makes it a tab
-/// stop with an accent border while the keyboard is on it. The caller adds its own listeners.
-pub fn card(card: &Card, state: CardState<'_>, cx: &App) -> Stateful
{
+/// One card at rest, as wide as its parent gives it, `ASPECT` wide over tall. Nothing about it
+/// changes on hover or focus, so a grid of them stays cached: the card under the pointer or the
+/// keyboard is drawn again over it, lifted (`lifted`). A focus handle makes it a tab stop. The
+/// caller adds its own listeners.
+pub fn card(card: &Card, focus: Option<&FocusHandle>, cx: &App) -> Stateful
{
+ let id = card.id;
+ let root = div().flex_1().min_w_0().aspect_ratio(ASPECT);
+ face(root, card, None, cx)
+ .id(("card", id))
+ .when_some(focus, |el, handle| el.track_focus(handle))
+ .debug_selector(|| format!("card-{id}"))
+}
+
+/// The card drawn over its grid in `pose`, `size` as its place there; the caller sets it
+/// `pose.rise` above. It has no listener: the pointer still meets the card at rest under it.
+pub fn lifted(card: &Card, pose: Pose, size: Size, cx: &App) -> Div {
+ let theme = cx.theme();
+ let progress = pose.progress;
+ let shadows = if !pose.moves || progress == 0. {
+ Vec::new()
+ } else if card.greyed() {
+ vec![drop_shadow(12., 24., -14., 0.6 * progress)]
+ } else {
+ vec![
+ drop_shadow(18., 34., -14., 0.65 * progress),
+ BoxShadow {
+ color: gold_glow(theme).opacity(progress),
+ offset: point(px(0.), px(0.)),
+ blur_radius: px(28.),
+ spread_radius: px(-8.),
+ inset: false,
+ },
+ ]
+ };
+ let id = card.id;
+ face(div().w(size.width).h(size.height), card, Some(pose), cx)
+ .shadow(shadows)
+ .debug_selector(move || format!("lifted-{id}"))
+}
+
+fn drop_shadow(y: f32, blur: f32, spread: f32, opacity: f32) -> BoxShadow {
+ BoxShadow {
+ color: hsla(0., 0., 0., opacity),
+ offset: point(px(0.), px(y)),
+ blur_radius: px(blur),
+ spread_radius: px(spread),
+ inset: false,
+ }
+}
+
+/// What a card shows, at rest (`None`) or lifted, in `root`.
+fn face(root: Div, card: &Card, pose: Option, cx: &App) -> Div {
let theme = cx.theme();
- let (border, ring, background) = (theme.border, theme.ring, surface(theme));
let greyed = card.greyed();
let id = card.id;
- div()
- .id(("card", id))
- .relative()
- .flex_1()
- .min_w_0()
- .aspect_ratio(ASPECT)
+ let progress = pose.map_or(0., |pose| pose.progress);
+ let zoom = pose.map_or(0., |pose| pose.zoom());
+ // Towards the accent as the card rises, as the hover and focus border did.
+ let border = theme.border.blend(theme.ring.opacity(progress));
+ root.relative()
.overflow_hidden()
.rounded(px(RADIUS))
.border_1()
.border_color(border)
- .bg(background)
- .hover(move |style| style.border_color(ring))
- .when_some(state.focus, |el, handle| {
- el.track_focus(handle)
- .focus_visible(move |style| style.border_color(ring))
- })
- .debug_selector(|| format!("card-{id}"))
+ .bg(surface(theme))
.children(card.portrait.as_ref().map(|path| {
+ // Zoomed in, the illustration overflows the card on every side, and is cut square:
+ // `corners` rounds it again.
img(path.clone())
.absolute()
- .inset_0()
- .size_full()
+ .left(relative(-zoom / 2.))
+ .top(relative(-zoom / 2.))
+ .w(relative(1. + zoom))
+ .h(relative(1. + zoom))
.rounded(px(INNER_RADIUS))
.object_fit(ObjectFit::Cover)
.grayscale(greyed)
@@ -251,28 +335,77 @@ pub fn card(card: &Card, state: CardState<'_>, cx: &App) -> Stateful
{
})
.child(shade())
.when(greyed, |el| el.child(reasons(id, &card.reasons)))
- .child(caption(card))
- .when(state.sheet, |el| el.child(sheet(card)))
+ .when(progress < 1., |el| {
+ let slide = if pose.is_some_and(|pose| pose.moves) {
+ CAPTION_SLIDE * progress
+ } else {
+ 0.
+ };
+ el.child(
+ caption(card)
+ .bottom(px(CAPTION_BOTTOM - slide))
+ .opacity(1. - progress),
+ )
+ })
+ .when(progress > 0., |el| {
+ let slide = if pose.is_some_and(|pose| pose.moves) {
+ SHEET_SLIDE * (1. - progress)
+ } else {
+ 0.
+ };
+ el.child(sheet(card).bottom(px(-slide)).opacity(progress))
+ })
+ .when(zoom > 0., |el| el.child(corners(theme.background)))
+ .children(pose.filter(|pose| pose.veil > 0.).map(|pose| {
+ div()
+ .absolute()
+ .inset_0()
+ .rounded(px(INNER_RADIUS))
+ .bg(veil_color(pose.veil))
+ }))
}
-/// Over the whole card, as the mockup's `.card-info`: the name, then a line per figure. Only the
-/// shown cards build it.
-fn sheet(card: &Card) -> Div {
- let id = card.id;
+/// What lies outside the card's rounded corners, in `background`: a frame whose inner edge is
+/// the card's radius, of which only the corners fall inside the card.
+fn corners(background: Hsla) -> Div {
+ let width = RADIUS;
div()
.absolute()
- .inset_0()
- .rounded(px(INNER_RADIUS))
+ .top(px(-width))
+ .left(px(-width))
+ .right(px(-width))
+ .bottom(px(-width))
+ .rounded(px(RADIUS + width))
+ .border(px(width))
+ .border_color(background)
+}
+
+/// Over the lower half of the card, as the mockup's `.sheet`: the name, then a line per figure,
+/// on a shade that darkens from its top. Only a lifted card builds it.
+fn sheet(card: &Card) -> Div {
+ let id = card.id;
+ let clear = rgba(SHEET_BG & 0xffffff00);
+ div()
+ .absolute()
+ .left_0()
+ .right_0()
+ .rounded_b(px(INNER_RADIUS))
.v_flex()
- .justify_center()
- .p(px(12.))
- .bg(rgba(SHEET_BG))
+ .justify_end()
+ .pt(px(44.))
+ .px(px(12.))
+ .pb(px(12.))
+ .bg(linear_gradient(
+ 180.,
+ linear_color_stop(clear, 0.),
+ linear_color_stop(rgba(SHEET_BG), 0.34),
+ ))
.text_size(px(12.))
.text_color(rgb(SHEET_LABEL))
.debug_selector(|| format!("sheet-{id}"))
.child(
div()
- .mb(px(10.))
+ .mb(px(6.))
.text_size(px(17.))
.font_weight(FontWeight::SEMIBOLD)
.text_color(white())
@@ -283,7 +416,7 @@ fn sheet(card: &Card) -> Div {
.h_flex()
.justify_between()
.gap(px(4.))
- .py(px(2.))
+ .py(px(1.5))
.debug_selector(|| format!("sheet-{id}-{label}"))
.child(*label)
.child(
@@ -328,7 +461,7 @@ fn caption(card: &Card) -> Div {
.absolute()
.left(px(12.))
.right(px(8.))
- .bottom(px(12.))
+ .bottom(px(CAPTION_BOTTOM))
.v_flex()
.child(
div()
diff --git a/crates/app/src/card_grid.rs b/crates/app/src/card_grid.rs
index 49fa150..61284d0 100644
--- a/crates/app/src/card_grid.rs
+++ b/crates/app/src/card_grid.rs
@@ -1,7 +1,10 @@
//! The card grid: all the cards a list shows, in rows of the same count, only the visible rows
//! built. It is its own view because it owns the scrolling and the hover of its cards, and the
-//! portraits they show (`card_images`).
+//! portraits they show (`card_images`). Its cards never change on hover or focus: the card under
+//! the pointer or the keyboard is drawn lifted over the grid (`card_lift`), from where the grid
+//! last placed it.
+use std::cell::RefCell;
use std::collections::HashMap;
use std::ops::Range;
use std::rc::Rc;
@@ -10,7 +13,7 @@ use gpui_kit::component::scroll::Scrollbar;
use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
use gpui_kit::*;
-use crate::card::{ASPECT, Card, CardState, card};
+use crate::card::{ASPECT, Card, card};
use crate::card_images::{self, CardImages};
use crate::page::PAGE_PADDING;
@@ -84,12 +87,26 @@ pub fn row_height(window_width: Pixels) -> Pixels {
px(Metrics::of(window_width).row_height())
}
-/// The card under the pointer changed: its id, or none.
+/// The card under the pointer, or the one the keyboard is on, changed: its id, or none.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CardHovered(pub Option);
-/// What makes one card reachable with the keyboard: its handle, and the subscriptions that draw
-/// the grid again when the focus comes or goes (a cached view is not drawn by the focus alone).
+/// A wheel moved the cards under a still pointer: none of them stays lifted.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub struct CardsMoved;
+
+/// Where the grid last drew a card, in the window, and the part of the window it showed of it.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Placed {
+ pub bounds: Bounds,
+ pub visible: Bounds,
+}
+
+/// The cards the grid drew last, by id: filled as its rows are laid out, read between its draws.
+pub type Placements = Rc>>;
+
+/// What makes one card reachable with the keyboard: its handle, and the subscriptions that lift
+/// it while the keyboard is on it.
struct CardFocus {
handle: FocusHandle,
_subscriptions: [Subscription; 2],
@@ -102,8 +119,10 @@ pub struct CardGrid {
/// Indices into `cards`, after the filter and the search.
shown: Vec,
scroll: UniformListScrollHandle,
- /// The card under the pointer, which shows its sheet.
+ /// The card under the pointer or the keyboard, which is lifted.
hovered: Option,
+ /// Where the visible cards were drawn last.
+ placed: Placements,
/// How far the list was scrolled when last drawn: a wheel that leaves it there (at either
/// end) moves no card from under the pointer.
drawn_scroll: Pixels,
@@ -126,6 +145,7 @@ pub struct CardGrid {
}
impl EventEmitter for CardGrid {}
+impl EventEmitter for CardGrid {}
impl CardGrid {
pub fn new() -> CardGrid {
@@ -134,6 +154,7 @@ impl CardGrid {
shown: Vec::new(),
scroll: UniformListScrollHandle::new(),
hovered: None,
+ placed: Placements::default(),
drawn_scroll: Pixels::ZERO,
focus: HashMap::new(),
focus_stale: false,
@@ -184,20 +205,27 @@ impl CardGrid {
self.focus_stale = false;
let mut previous = std::mem::take(&mut self.focus);
for card in self.cards.iter() {
- let focus = previous.remove(&card.id).unwrap_or_else(|| {
+ let id = card.id;
+ let focus = previous.remove(&id).unwrap_or_else(|| {
let handle = cx.focus_handle().tab_stop(true);
- let gained = cx.on_focus_in(&handle, window, |_, _, cx| cx.notify());
- let lost = cx.on_focus_out(&handle, window, |_, _, _, cx| cx.notify());
+ // As `:focus-visible`: a card focused by a click is already under the pointer.
+ let gained = cx.on_focus_in(&handle, window, move |grid, window, cx| {
+ if window.last_input_was_keyboard() {
+ grid.hover(Some(id), cx);
+ }
+ });
+ let lost = cx.on_focus_out(&handle, window, move |grid, _, _, cx| {
+ grid.set_hovered(id, false, cx);
+ });
CardFocus {
handle,
_subscriptions: [gained, lost],
}
});
- self.focus.insert(card.id, focus);
+ self.focus.insert(id, focus);
}
}
- /// Only a change of card draws the grid again.
fn set_hovered(&mut self, id: u32, hovered: bool, cx: &mut Context) {
let next = match (hovered, self.hovered) {
(true, _) => Some(id),
@@ -207,16 +235,14 @@ impl CardGrid {
self.hover(next, cx);
}
- /// The one change of the card under the pointer: it draws the grid again and is told
- /// (the ring lights that card's tick). True when it changed.
- fn hover(&mut self, next: Option, cx: &mut Context) -> bool {
- if next == self.hovered {
- return false;
+ /// The one change of the card under the pointer or the keyboard: it is told (the ring
+ /// lights that card's tick, the card is lifted over the grid), and the grid is not drawn
+ /// again.
+ fn hover(&mut self, next: Option, cx: &mut Context) {
+ if next != self.hovered {
+ self.hovered = next;
+ cx.emit(CardHovered(next));
}
- self.hovered = next;
- cx.emit(CardHovered(next));
- cx.notify();
- true
}
/// The card under the pointer is no longer shown (filtered out, or gone with new cards):
@@ -277,6 +303,7 @@ impl CardGrid {
pub fn release_images(&mut self, window: &mut Window, cx: &mut Context) {
// Nor is any of its cards under the pointer: the ring's tick goes out.
self.hover(None, cx);
+ self.placed.borrow_mut().clear();
let released = self
.images
.as_ref()
@@ -314,25 +341,41 @@ impl CardGrid {
.collect()
}
- #[cfg(test)]
- pub(crate) fn images(&self) -> Option<&Entity> {
+ /// The portraits its cards show, for a card drawn over it.
+ pub fn images(&self) -> Option<&Entity> {
self.images.as_ref()
}
+ /// Where its visible cards were drawn last.
+ pub fn placed(&self) -> &Placements {
+ &self.placed
+ }
+
+ /// One of its cards, shown or not.
+ pub fn card(&self, id: u32) -> Option<&Card> {
+ self.cards.iter().find(|card| card.id == id)
+ }
+
+ /// A grid as tall as its rows: the hand of a champ select.
+ pub fn is_hand(&self) -> bool {
+ self.fit_content
+ }
+
/// How far the grid is scrolled down.
#[cfg(test)]
pub(crate) fn scrolled(&self) -> Pixels {
-self.scroll.0.borrow().base_handle.offset().y
}
- fn row(
- &mut self,
- ix: usize,
- metrics: Metrics,
- window: &Window,
- cx: &mut Context,
- ) -> AnyElement {
+ fn row(&mut self, ix: usize, metrics: Metrics, cx: &mut Context) -> AnyElement {
let start = ix * metrics.columns;
+ let ids: Vec