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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WYQB8paBcLk67XoAUYARBK
This commit is contained in:
1 parent
c2d6296723
commit
b78be1ff0b
10 files changed
+982
-127
No files matched your search
+174
-41
@@ -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<Div> {
|
||||
/// 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<Div> {
|
||||
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<Pixels>, 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<Pose>, 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<Div> {
|
||||
})
|
||||
.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()
|
||||
|
||||
+90
-42
@@ -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<u32>);
|
||||
|
||||
/// 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<Pixels>,
|
||||
pub visible: Bounds<Pixels>,
|
||||
}
|
||||
|
||||
/// The cards the grid drew last, by id: filled as its rows are laid out, read between its draws.
|
||||
pub type Placements = Rc<RefCell<HashMap<u32, Placed>>>;
|
||||
|
||||
/// 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<usize>,
|
||||
scroll: UniformListScrollHandle,
|
||||
/// The card under the pointer, which shows its sheet.
|
||||
/// The card under the pointer or the keyboard, which is lifted.
|
||||
hovered: Option<u32>,
|
||||
/// 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<CardHovered> for CardGrid {}
|
||||
impl EventEmitter<CardsMoved> 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<Self>) {
|
||||
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<u32>, cx: &mut Context<Self>) -> 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<u32>, cx: &mut Context<Self>) {
|
||||
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<Self>) {
|
||||
// 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<CardImages>> {
|
||||
/// The portraits its cards show, for a card drawn over it.
|
||||
pub fn images(&self) -> Option<&Entity<CardImages>> {
|
||||
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<Self>,
|
||||
) -> AnyElement {
|
||||
fn row(&mut self, ix: usize, metrics: Metrics, cx: &mut Context<Self>) -> AnyElement {
|
||||
let start = ix * metrics.columns;
|
||||
let ids: Vec<Option<u32>> = (start..start + metrics.columns)
|
||||
.map(|slot| {
|
||||
let card = self.shown.get(slot).and_then(|&c| self.cards.get(c))?;
|
||||
Some(card.id)
|
||||
})
|
||||
.collect();
|
||||
let placed = self.placed.clone();
|
||||
let row = div()
|
||||
.h_flex()
|
||||
.items_start()
|
||||
@@ -340,7 +383,17 @@ impl CardGrid {
|
||||
.h(px(metrics.card_height + metrics.gap))
|
||||
.pb(px(metrics.gap))
|
||||
.pr(Scrollbar::width())
|
||||
.gap(px(metrics.gap));
|
||||
.gap(px(metrics.gap))
|
||||
// Only a row painted is laid out here, not one `uniform_list` merely measures.
|
||||
.on_children_prepainted(move |bounds, window, _| {
|
||||
let visible = window.content_mask().bounds;
|
||||
let mut placed = placed.borrow_mut();
|
||||
for (id, bounds) in ids.iter().zip(bounds) {
|
||||
if let Some(id) = id {
|
||||
placed.insert(*id, Placed { bounds, visible });
|
||||
}
|
||||
}
|
||||
});
|
||||
let slots = (start..start + metrics.columns).map(|slot| {
|
||||
// A stale index shows nothing rather than panicking.
|
||||
match self.shown.get(slot).and_then(|&c| self.cards.get(c)) {
|
||||
@@ -350,14 +403,8 @@ impl CardGrid {
|
||||
self.card_builds += 1;
|
||||
}
|
||||
let focus = self.focus.get(&data.id).map(|focus| &focus.handle);
|
||||
// The sheet shows on the card under the pointer and on the one the
|
||||
// keyboard is on, as `:focus-visible` does.
|
||||
let sheet = self.hovered == Some(data.id)
|
||||
|| focus.is_some_and(|handle| {
|
||||
handle.is_focused(window) && window.last_input_was_keyboard()
|
||||
});
|
||||
let id = data.id;
|
||||
card(data, CardState { sheet, focus }, cx)
|
||||
card(data, focus, cx)
|
||||
.on_hover(cx.listener(move |grid, hovered: &bool, _, cx| {
|
||||
grid.set_hovered(id, *hovered, cx)
|
||||
}))
|
||||
@@ -389,6 +436,7 @@ impl CardGrid {
|
||||
let moved = grid.fit_content || grid.scrolled_to() != grid.drawn_scroll;
|
||||
if moved {
|
||||
grid.hover(None, cx);
|
||||
cx.emit(CardsMoved);
|
||||
}
|
||||
}))
|
||||
.on_action(cx.listener(|grid, _: &NextCard, window, cx| grid.move_focus(1, window, cx)))
|
||||
@@ -408,6 +456,8 @@ impl Render for CardGrid {
|
||||
self.sync_focus(window, cx);
|
||||
}
|
||||
self.drawn_scroll = self.scrolled_to();
|
||||
// Only the rows drawn now place their cards.
|
||||
self.placed.borrow_mut().clear();
|
||||
let images = (self.images)
|
||||
.get_or_insert_with(|| CardImages::new(cx))
|
||||
.clone();
|
||||
@@ -426,9 +476,7 @@ impl Render for CardGrid {
|
||||
let rows = self.shown.len().div_ceil(metrics.columns);
|
||||
if self.fit_content {
|
||||
// The same rows and cards (sheet, hover, keyboard focus), all built, as a column.
|
||||
let rows: Vec<_> = (0..rows)
|
||||
.map(|ix| self.row(ix, metrics, window, cx))
|
||||
.collect();
|
||||
let rows: Vec<_> = (0..rows).map(|ix| self.row(ix, metrics, cx)).collect();
|
||||
return self
|
||||
.with_cards_behaviour(div().v_flex().w_full(), images, cx)
|
||||
.children(rows)
|
||||
@@ -440,9 +488,9 @@ impl Render for CardGrid {
|
||||
uniform_list(
|
||||
"cards",
|
||||
rows,
|
||||
cx.processor(move |grid, range: Range<usize>, window, cx| {
|
||||
cx.processor(move |grid, range: Range<usize>, _, cx| {
|
||||
range
|
||||
.map(|ix| grid.row(ix, metrics, window, cx))
|
||||
.map(|ix| grid.row(ix, metrics, cx))
|
||||
.collect::<Vec<_>>()
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,414 @@
|
||||
//! The lift of the card under the pointer or the keyboard (#88): which cards are lifted, and how
|
||||
//! far, in each grid. A card rises when the pointer or the keyboard comes to it and settles back
|
||||
//! when it leaves, each time from where it is; in the hand, a veil lays on the other cards.
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use gpui_kit::component::ActiveTheme as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::card::{CARD_RADIUS, Card, Pose, lifted, veil_color};
|
||||
use crate::card_grid::Placements;
|
||||
use crate::card_images::CardImages;
|
||||
use crate::motion::ease_out;
|
||||
|
||||
/// How long a card takes to rise all the way, or to settle back.
|
||||
const RISE: Duration = Duration::from_millis(350);
|
||||
/// How long the hand's veil takes to lay on its cards, or to lift.
|
||||
const VEIL: Duration = Duration::from_millis(300);
|
||||
|
||||
/// A value moving to `to`, from where it was when asked to.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct Tween {
|
||||
from: f32,
|
||||
to: f32,
|
||||
start: Instant,
|
||||
duration: Duration,
|
||||
}
|
||||
|
||||
impl Tween {
|
||||
fn value(&self, now: Instant) -> f32 {
|
||||
self.from + (self.to - self.from) * ease_out(self.progress(now))
|
||||
}
|
||||
|
||||
fn progress(&self, now: Instant) -> f32 {
|
||||
if self.duration.is_zero() {
|
||||
return 1.;
|
||||
}
|
||||
let elapsed = now.saturating_duration_since(self.start);
|
||||
(elapsed.as_secs_f32() / self.duration.as_secs_f32()).min(1.)
|
||||
}
|
||||
|
||||
fn done(&self, now: Instant) -> bool {
|
||||
self.progress(now) >= 1.
|
||||
}
|
||||
|
||||
/// Towards `to` from where it is now, over the part of `full` that is left to go.
|
||||
fn toward(&self, to: f32, full: Duration, now: Instant) -> Tween {
|
||||
let from = self.value(now);
|
||||
Tween {
|
||||
from,
|
||||
to,
|
||||
start: now,
|
||||
duration: full.mul_f32((to - from).abs()),
|
||||
}
|
||||
}
|
||||
|
||||
fn rest(value: f32, now: Instant) -> Tween {
|
||||
Tween {
|
||||
from: value,
|
||||
to: value,
|
||||
start: now,
|
||||
duration: Duration::ZERO,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A card lifted, or settling back, over grid `G`, with what draws it, `C`.
|
||||
struct Entry<G, C> {
|
||||
grid: G,
|
||||
id: u32,
|
||||
card: C,
|
||||
lift: Tween,
|
||||
}
|
||||
|
||||
/// A card as it is drawn now: `progress` is 0 at rest and 1 lifted all the way.
|
||||
pub(crate) struct Lifted<'a, C> {
|
||||
pub card: &'a C,
|
||||
pub progress: f32,
|
||||
}
|
||||
|
||||
pub(crate) struct Lifts<G, C> {
|
||||
/// In paint order: the card rising last.
|
||||
cards: Vec<Entry<G, C>>,
|
||||
/// The veil of each hand, while it is not lifted.
|
||||
veils: Vec<(G, Tween)>,
|
||||
}
|
||||
|
||||
impl<G: Copy + PartialEq, C> Lifts<G, C> {
|
||||
pub fn new() -> Self {
|
||||
Lifts {
|
||||
cards: Vec::new(),
|
||||
veils: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The card under the pointer or the keyboard in `grid` is now `card`, or none: it rises,
|
||||
/// and the one it replaces in that grid settles back.
|
||||
/// In a hand (`veiled`), a veil lays on its other cards while one is lifted.
|
||||
pub fn hover(&mut self, grid: G, card: Option<(u32, C)>, veiled: bool, now: Instant) {
|
||||
let id = card.as_ref().map(|(id, _)| *id);
|
||||
if veiled {
|
||||
let to = if id.is_some() { 1. } else { 0. };
|
||||
match self.veils.iter_mut().find(|(hand, _)| *hand == grid) {
|
||||
Some((_, veil)) if veil.to != to => *veil = veil.toward(to, VEIL, now),
|
||||
Some(_) => {}
|
||||
None => self
|
||||
.veils
|
||||
.push((grid, Tween::rest(0., now).toward(to, VEIL, now))),
|
||||
}
|
||||
}
|
||||
for entry in self.cards.iter_mut() {
|
||||
if entry.grid == grid && Some(entry.id) != id && entry.lift.to != 0. {
|
||||
entry.lift = entry.lift.toward(0., RISE, now);
|
||||
}
|
||||
}
|
||||
if let Some((id, card)) = card {
|
||||
// A card settling back rises again from where it is, drawn over the others.
|
||||
let settling =
|
||||
(self.cards.iter()).position(|entry| entry.grid == grid && entry.id == id);
|
||||
let lift = match settling.map(|ix| self.cards.remove(ix)) {
|
||||
Some(entry) if entry.lift.to == 1. => entry.lift,
|
||||
Some(entry) => entry.lift.toward(1., RISE, now),
|
||||
None => Tween::rest(0., now).toward(1., RISE, now),
|
||||
};
|
||||
self.cards.push(Entry {
|
||||
grid,
|
||||
id,
|
||||
card,
|
||||
lift,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// The cards of `grid` moved under a still pointer (a wheel): none stays lifted, nor does
|
||||
/// its veil, at once.
|
||||
pub fn drop_grid(&mut self, grid: G) {
|
||||
self.cards.retain(|entry| entry.grid != grid);
|
||||
self.veils.retain(|(hand, _)| *hand != grid);
|
||||
}
|
||||
|
||||
/// No card lifted any more, at once: the grids are no longer shown.
|
||||
pub fn clear(&mut self) {
|
||||
self.cards.clear();
|
||||
self.veils.clear();
|
||||
}
|
||||
|
||||
/// Every card and veil where it was going, at once: nothing to animate.
|
||||
pub fn finish(&mut self, now: Instant) {
|
||||
for entry in self.cards.iter_mut() {
|
||||
entry.lift = Tween::rest(entry.lift.to, now);
|
||||
}
|
||||
for (_, veil) in self.veils.iter_mut() {
|
||||
*veil = Tween::rest(veil.to, now);
|
||||
}
|
||||
self.tidy(now);
|
||||
}
|
||||
|
||||
/// Forgets the cards back at rest: they are the grid's own again.
|
||||
pub fn tidy(&mut self, now: Instant) {
|
||||
self.cards
|
||||
.retain(|entry| !(entry.lift.to == 0. && entry.lift.done(now)));
|
||||
self.veils
|
||||
.retain(|(_, veil)| !(veil.to == 0. && veil.done(now)));
|
||||
}
|
||||
|
||||
/// Whether a card still moves.
|
||||
pub fn animating(&self, now: Instant) -> bool {
|
||||
self.cards.iter().any(|entry| !entry.lift.done(now))
|
||||
|| self.veils.iter().any(|(_, veil)| !veil.done(now))
|
||||
}
|
||||
|
||||
/// How far the veil lays on the cards of `grid`, 0 to 1.
|
||||
pub fn veil(&self, grid: G, now: Instant) -> f32 {
|
||||
(self.veils.iter())
|
||||
.find(|(hand, _)| *hand == grid)
|
||||
.map_or(0., |(_, veil)| veil.value(now))
|
||||
}
|
||||
|
||||
/// The cards of `grid` to draw over it, in paint order.
|
||||
pub fn lifted(&self, grid: G, now: Instant) -> impl Iterator<Item = Lifted<'_, C>> {
|
||||
self.cards
|
||||
.iter()
|
||||
.filter(move |entry| entry.grid == grid)
|
||||
.map(move |entry| Lifted {
|
||||
card: &entry.card,
|
||||
progress: entry.lift.value(now),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws the lifted cards of a grid over it, `lifted` in paint order with how far each is, and
|
||||
/// the hand's `veil` over the others, where the grid last placed them: the grid is not drawn
|
||||
/// again, and the pointer still meets its cards. Painted after the rest of the page, so a card
|
||||
/// rises over what is above it; a card the grid shows only in part stays cut where it is.
|
||||
pub(crate) fn layer(
|
||||
placed: Placements,
|
||||
images: Option<Entity<CardImages>>,
|
||||
lifted_cards: Vec<(Rc<Card>, f32)>,
|
||||
veil: f32,
|
||||
moves: bool,
|
||||
) -> AnyElement {
|
||||
deferred(
|
||||
canvas(
|
||||
move |_, window, cx| {
|
||||
let placed = placed.borrow();
|
||||
let background = cx.theme().background;
|
||||
let mut layers = Vec::new();
|
||||
if veil > 0. {
|
||||
for (id, place) in placed.iter() {
|
||||
if !lifted_cards.iter().any(|(card, _)| card.id == *id) {
|
||||
layers.push(Layer::Quad(place.bounds, veil_color(veil), place.visible));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (card, progress) in &lifted_cards {
|
||||
let Some(place) = placed.get(&card.id) else {
|
||||
continue;
|
||||
};
|
||||
let pose = Pose {
|
||||
progress: *progress,
|
||||
// Settling back, it goes under the veil of the cards at rest.
|
||||
veil: veil * (1. - progress),
|
||||
moves,
|
||||
};
|
||||
// Its place in the grid, where the card at rest is not to be seen.
|
||||
layers.push(Layer::Quad(place.bounds, background, place.visible));
|
||||
let whole = place.visible.intersect(&place.bounds) == place.bounds;
|
||||
let mask = (!whole).then_some(ContentMask {
|
||||
bounds: place.visible,
|
||||
});
|
||||
let mut element = self::lifted(card, pose, place.bounds.size, cx);
|
||||
if let Some(images) = &images {
|
||||
element = element.image_cache(images.clone());
|
||||
}
|
||||
let mut element = element.into_any_element();
|
||||
let origin = place.bounds.origin - point(px(0.), px(pose.rise(card)));
|
||||
window.with_content_mask(mask, |window| {
|
||||
element.prepaint_as_root(origin, place.bounds.size.into(), window, cx)
|
||||
});
|
||||
layers.push(Layer::Card(element, mask));
|
||||
}
|
||||
layers
|
||||
},
|
||||
|_, layers, window, cx| {
|
||||
for layer in layers {
|
||||
match layer {
|
||||
Layer::Quad(bounds, color, visible) => {
|
||||
let mask = ContentMask { bounds: visible };
|
||||
window.with_content_mask(Some(mask), |window| {
|
||||
window.paint_quad(fill(bounds, color).corner_radii(px(CARD_RADIUS)))
|
||||
});
|
||||
}
|
||||
Layer::Card(mut element, mask) => {
|
||||
window.with_content_mask(mask, |window| element.paint(window, cx));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.absolute(),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
|
||||
/// What the layer paints, in order.
|
||||
enum Layer {
|
||||
/// A rounded quad over a card's place, cut to what the grid shows of it.
|
||||
Quad(Bounds<Pixels>, Hsla, Bounds<Pixels>),
|
||||
Card(AnyElement, Option<ContentMask<Pixels>>),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use super::Lifts;
|
||||
|
||||
const GRID: u32 = 1;
|
||||
|
||||
fn at(start: Instant, ms: u64) -> Instant {
|
||||
start + Duration::from_millis(ms)
|
||||
}
|
||||
|
||||
/// A card whose drawing is its id.
|
||||
fn on(id: u32) -> Option<(u32, u32)> {
|
||||
Some((id, id))
|
||||
}
|
||||
|
||||
fn progress(lifts: &Lifts<u32, u32>, id: u32, now: Instant) -> Option<f32> {
|
||||
lifts
|
||||
.lifted(GRID, now)
|
||||
.find(|lifted| *lifted.card == id)
|
||||
.map(|lifted| lifted.progress)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_hovered_card_rises_in_350_ms_and_settles_back_in_as_long_once_left() {
|
||||
let start = Instant::now();
|
||||
let mut lifts = Lifts::new();
|
||||
lifts.hover(GRID, on(7), false, start);
|
||||
assert_eq!(progress(&lifts, 7, start), Some(0.));
|
||||
let half = progress(&lifts, 7, at(start, 175)).unwrap();
|
||||
// Fast at first, then settling, as the reference's cubic-bezier(.2, .8, .2, 1).
|
||||
assert!(half > 0.5 && half < 1., "{half}");
|
||||
assert_eq!(progress(&lifts, 7, at(start, 350)), Some(1.));
|
||||
assert!(lifts.animating(at(start, 349)));
|
||||
assert!(!lifts.animating(at(start, 350)));
|
||||
|
||||
lifts.hover(GRID, None, false, at(start, 400));
|
||||
assert_eq!(progress(&lifts, 7, at(start, 400)), Some(1.));
|
||||
assert!(progress(&lifts, 7, at(start, 600)).unwrap() > 0.);
|
||||
assert_eq!(progress(&lifts, 7, at(start, 750)), Some(0.));
|
||||
// Back at rest, the card is the grid's own again.
|
||||
lifts.tidy(at(start, 750));
|
||||
assert_eq!(progress(&lifts, 7, at(start, 750)), None);
|
||||
assert!(!lifts.animating(at(start, 750)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_card_left_or_taken_back_during_its_animation_starts_from_where_it_is() {
|
||||
let start = Instant::now();
|
||||
let mut lifts = Lifts::new();
|
||||
lifts.hover(GRID, on(7), false, start);
|
||||
let midway = progress(&lifts, 7, at(start, 100)).unwrap();
|
||||
|
||||
// Left on its way up: it settles from there, with no jump, and sooner than from the top.
|
||||
lifts.hover(GRID, None, false, at(start, 100));
|
||||
assert_eq!(progress(&lifts, 7, at(start, 100)), Some(midway));
|
||||
let back = at(start, 100 + (350. * midway).ceil() as u64);
|
||||
assert_eq!(progress(&lifts, 7, back), Some(0.));
|
||||
|
||||
// Taken back on its way down: it rises again from there, still one card.
|
||||
lifts.hover(GRID, on(7), false, at(start, 200));
|
||||
lifts.hover(GRID, None, false, at(start, 200));
|
||||
lifts.hover(GRID, on(7), false, at(start, 200));
|
||||
let low = progress(&lifts, 7, at(start, 200)).unwrap();
|
||||
assert!(low > 0. && low < midway, "{low}");
|
||||
assert_eq!(lifts.lifted(GRID, at(start, 200)).count(), 1);
|
||||
assert_eq!(progress(&lifts, 7, at(start, 550)), Some(1.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_card_rising_is_drawn_over_the_one_settling_and_each_grid_keeps_its_own() {
|
||||
let start = Instant::now();
|
||||
let mut lifts = Lifts::new();
|
||||
lifts.hover(GRID, on(7), false, start);
|
||||
lifts.hover(GRID, on(8), false, at(start, 350));
|
||||
lifts.hover(GRID, on(7), false, at(start, 400));
|
||||
let order: Vec<_> = (lifts.lifted(GRID, at(start, 400)))
|
||||
.map(|lifted| *lifted.card)
|
||||
.collect();
|
||||
assert_eq!(order, [8, 7]);
|
||||
|
||||
// Another grid saying none of its cards is under the pointer leaves this one's.
|
||||
lifts.hover(2, None, false, at(start, 400));
|
||||
lifts.hover(2, on(9), false, at(start, 400));
|
||||
assert_eq!(progress(&lifts, 7, at(start, 750)), Some(1.));
|
||||
assert_eq!(lifts.lifted(2, at(start, 400)).count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn in_the_hand_a_veil_lays_on_the_other_cards_while_one_is_lifted() {
|
||||
let start = Instant::now();
|
||||
let mut lifts = Lifts::new();
|
||||
lifts.hover(GRID, on(7), true, start);
|
||||
assert_eq!(lifts.veil(GRID, start), 0.);
|
||||
assert!(lifts.veil(GRID, at(start, 150)) > 0.);
|
||||
assert_eq!(lifts.veil(GRID, at(start, 300)), 1.);
|
||||
assert!(lifts.animating(at(start, 340)));
|
||||
|
||||
// From card to card, it stays.
|
||||
lifts.hover(GRID, on(8), true, at(start, 400));
|
||||
assert_eq!(lifts.veil(GRID, at(start, 500)), 1.);
|
||||
|
||||
lifts.hover(GRID, None, true, at(start, 800));
|
||||
assert!(lifts.veil(GRID, at(start, 900)) > 0.);
|
||||
assert_eq!(lifts.veil(GRID, at(start, 1100)), 0.);
|
||||
|
||||
// Elsewhere than in the hand, none.
|
||||
lifts.hover(2, on(9), false, at(start, 1200));
|
||||
assert_eq!(lifts.veil(2, at(start, 1600)), 0.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wheel_over_a_grid_drops_its_cards_at_once() {
|
||||
let start = Instant::now();
|
||||
let mut lifts = Lifts::new();
|
||||
lifts.hover(GRID, on(7), true, start);
|
||||
lifts.hover(2, on(9), false, start);
|
||||
lifts.drop_grid(GRID);
|
||||
assert_eq!(lifts.lifted(GRID, start).count(), 0);
|
||||
assert_eq!(lifts.veil(GRID, start), 0.);
|
||||
assert_eq!(lifts.lifted(2, start).count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finishing_shows_the_end_state_at_once_and_nothing_moves_any_more() {
|
||||
let start = Instant::now();
|
||||
let mut lifts = Lifts::new();
|
||||
lifts.hover(GRID, on(7), true, start);
|
||||
lifts.hover(GRID, on(8), true, at(start, 100));
|
||||
lifts.finish(at(start, 100));
|
||||
assert!(!lifts.animating(at(start, 100)));
|
||||
assert_eq!(progress(&lifts, 8, at(start, 100)), Some(1.));
|
||||
// The card left is back at rest, and the grid's own again.
|
||||
assert_eq!(progress(&lifts, 7, at(start, 100)), None);
|
||||
assert_eq!(lifts.veil(GRID, at(start, 100)), 1.);
|
||||
|
||||
lifts.clear();
|
||||
assert_eq!(lifts.lifted(GRID, start).count(), 0);
|
||||
assert_eq!(lifts.veil(GRID, start), 0.);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ mod banner_art;
|
||||
mod card;
|
||||
mod card_grid;
|
||||
mod card_images;
|
||||
mod card_lift;
|
||||
mod card_order;
|
||||
mod champion_table;
|
||||
mod motion;
|
||||
|
||||
@@ -147,7 +147,7 @@ fn ease_in(t: f32) -> f32 {
|
||||
}
|
||||
|
||||
/// Close to the reference's `cubic-bezier(.2, .8, .2, 1)`.
|
||||
fn ease_out(t: f32) -> f32 {
|
||||
pub(crate) fn ease_out(t: f32) -> f32 {
|
||||
1. - (1. - t).powi(3)
|
||||
}
|
||||
|
||||
|
||||
+284
-38
@@ -27,7 +27,8 @@ mod statistics;
|
||||
|
||||
use crate::banner_art::BannerArt;
|
||||
use crate::card::Card;
|
||||
use crate::card_grid::{CardGrid, CardHovered};
|
||||
use crate::card_grid::{CardGrid, CardHovered, CardsMoved};
|
||||
use crate::card_lift::Lifts;
|
||||
use crate::card_order::card_order;
|
||||
use crate::champion_table::ChampionTable;
|
||||
use crate::motion::{AnimationSetting, Deferred, Fade, FadePhase, MatchEnd};
|
||||
@@ -164,6 +165,9 @@ pub struct Page {
|
||||
fade: Option<Fade>,
|
||||
/// A frame of the transition is asked for.
|
||||
frame_asked: bool,
|
||||
/// The cards lifted over their grid, by grid: the one under the pointer or the keyboard, and
|
||||
/// those settling back (#88).
|
||||
lifts: Lifts<EntityId, Rc<Card>>,
|
||||
/// « Paramètres » stands in for the page.
|
||||
covered: bool,
|
||||
/// The animation asked for while « Défi » was not visible.
|
||||
@@ -243,9 +247,9 @@ pub struct Page {
|
||||
others_grid: Entity<CardGrid>,
|
||||
/// The section's header button, which the keyboard reaches.
|
||||
others_focus: FocusHandle,
|
||||
/// Lights the ring's tick of the card hovered in « Autres champions », whose grid is made
|
||||
/// again at each fold.
|
||||
others_hover: Subscription,
|
||||
/// Lights the ring's tick of the card hovered in « Autres champions », and lifts it; its grid
|
||||
/// is made again at each fold.
|
||||
others_hover: [Subscription; 2],
|
||||
_subscriptions: Vec<Subscription>,
|
||||
_listener: Task<()>,
|
||||
}
|
||||
@@ -307,13 +311,16 @@ impl Page {
|
||||
let banner_art = BannerArt::new(cx);
|
||||
let others_hover = Self::light_on_hover(&others_grid, cx);
|
||||
|
||||
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.
|
||||
let mut subscriptions = Vec::new();
|
||||
subscriptions.extend(Self::light_on_hover(&home_grid, cx));
|
||||
subscriptions.extend(Self::light_on_hover(&anvil_grid, cx));
|
||||
subscriptions.extend([
|
||||
// The Windows setting turned off: a transition running ends, a card lifting is
|
||||
// lifted, and nothing waits.
|
||||
cx.observe_global_in::<AnimationSetting>(window, |this, window, cx| {
|
||||
if cx.reduce_motion() {
|
||||
this.deferred.abandon();
|
||||
this.lifts.finish(cx.background_executor().now());
|
||||
this.end_fade(window, cx);
|
||||
}
|
||||
}),
|
||||
@@ -323,6 +330,7 @@ impl Page {
|
||||
if visibility.is_visible() {
|
||||
this.play_waiting(window, cx);
|
||||
} else {
|
||||
this.lifts.finish(cx.background_executor().now());
|
||||
this.end_fade(window, cx);
|
||||
}
|
||||
}),
|
||||
@@ -403,7 +411,7 @@ impl Page {
|
||||
this.recompute(window, cx);
|
||||
},
|
||||
),
|
||||
];
|
||||
]);
|
||||
|
||||
// gpui-kit's async channel wakes the page on sends, with no timer or extra dependency.
|
||||
let listener = cx.spawn_in(window, async move |this, cx| {
|
||||
@@ -441,6 +449,7 @@ impl Page {
|
||||
shown_tab: Tab::Challenge,
|
||||
fade: None,
|
||||
frame_asked: false,
|
||||
lifts: Lifts::new(),
|
||||
covered: false,
|
||||
deferred: Deferred::new(),
|
||||
#[cfg(test)]
|
||||
@@ -507,6 +516,7 @@ impl Page {
|
||||
/// again when it is drawn.
|
||||
pub fn hidden(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.covered = true;
|
||||
self.lifts.clear();
|
||||
self.end_fade(window, cx);
|
||||
for grid in [&self.home_grid, &self.anvil_grid, &self.others_grid] {
|
||||
grid.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
@@ -680,6 +690,8 @@ impl Page {
|
||||
}
|
||||
if self.tab != tab {
|
||||
self.tab = tab;
|
||||
// The grids leave under the veil: no card stays lifted over it.
|
||||
self.lifts.clear();
|
||||
if cx.reduce_motion() || !window.is_visible() {
|
||||
// Nothing to see: the end state at once.
|
||||
self.end_fade(window, cx);
|
||||
@@ -1178,11 +1190,57 @@ impl Page {
|
||||
self.ring.update(cx, |ring, cx| ring.set_ticks(ticks, cx));
|
||||
}
|
||||
|
||||
/// 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, grid, CardHovered(id): &CardHovered, cx| {
|
||||
this.light(grid.entity_id(), *id, cx);
|
||||
})
|
||||
/// Lifts the card under the pointer or the keyboard in `grid`, and lights its ring's tick.
|
||||
/// A wheel over the grid drops its cards at once.
|
||||
fn light_on_hover(grid: &Entity<CardGrid>, cx: &mut Context<Self>) -> [Subscription; 2] {
|
||||
[
|
||||
cx.subscribe(grid, |this, grid, CardHovered(id): &CardHovered, cx| {
|
||||
this.lift(&grid, *id, cx);
|
||||
this.light(grid.entity_id(), *id, cx);
|
||||
}),
|
||||
cx.subscribe(grid, |this, grid, _: &CardsMoved, cx| {
|
||||
this.lifts.drop_grid(grid.entity_id());
|
||||
cx.notify();
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
/// The card under the pointer or the keyboard in `grid` is now `id`: it rises over the grid,
|
||||
/// and the one it replaces settles back. With the Windows « Show animations » setting off,
|
||||
/// each is where it goes at once.
|
||||
fn lift(&mut self, grid: &Entity<CardGrid>, id: Option<u32>, cx: &mut Context<Self>) {
|
||||
let now = cx.background_executor().now();
|
||||
let (card, hand) = {
|
||||
let grid = grid.read(cx);
|
||||
let card = id.and_then(|id| Some((id, Rc::new(grid.card(id)?.clone()))));
|
||||
(card, grid.is_hand())
|
||||
};
|
||||
self.lifts.hover(grid.entity_id(), card, hand, now);
|
||||
if cx.reduce_motion() {
|
||||
self.lifts.finish(now);
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// The cards lifted over `grid`, if any: drawn after it, as long as it is.
|
||||
pub(super) fn lift_layer(&self, grid: &Entity<CardGrid>, cx: &App) -> Option<AnyElement> {
|
||||
let now = cx.background_executor().now();
|
||||
let id = grid.entity_id();
|
||||
let lifted: Vec<_> = (self.lifts.lifted(id, now))
|
||||
.map(|lifted| (lifted.card.clone(), lifted.progress))
|
||||
.collect();
|
||||
let veil = self.lifts.veil(id, now);
|
||||
if lifted.is_empty() && veil == 0. {
|
||||
return None;
|
||||
}
|
||||
let grid = grid.read(cx);
|
||||
Some(crate::card_lift::layer(
|
||||
grid.placed().clone(),
|
||||
grid.images().cloned(),
|
||||
lifted,
|
||||
veil,
|
||||
!cx.reduce_motion(),
|
||||
))
|
||||
}
|
||||
|
||||
/// The card under the pointer in `grid` changed to `id`. The tick follows the grid that lit
|
||||
@@ -1215,6 +1273,7 @@ impl Page {
|
||||
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.lifts.drop_grid(replaced);
|
||||
self.light(replaced, None, cx);
|
||||
}
|
||||
|
||||
@@ -1537,6 +1596,12 @@ impl Page {
|
||||
|
||||
impl Render for Page {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
// A card lifting or settling asks for the next frame, and none once they are still.
|
||||
let now = cx.background_executor().now();
|
||||
self.lifts.tidy(now);
|
||||
if self.lifts.animating(now) {
|
||||
window.request_animation_frame();
|
||||
}
|
||||
let muted = cx.theme().muted_foreground;
|
||||
let busy = self.busy();
|
||||
let status_line = sync_line(busy, self.progress, self.crashed, self.stored);
|
||||
@@ -2541,10 +2606,8 @@ mod tests {
|
||||
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders + 1);
|
||||
}
|
||||
|
||||
// Hovering a card or scrolling the grid notifies the grid view, which GPUI draws again along
|
||||
// with its parent, the page (it is not a cached view). What the test proves is that this
|
||||
// costs no statistics and no cards: the statistics are not computed again and the cards are
|
||||
// not built again.
|
||||
// Hovering a card draws it lifted over the grid, which is not drawn again; scrolling the grid
|
||||
// draws it again. Neither computes the statistics again nor builds the cards again.
|
||||
#[gpui::test]
|
||||
fn scrolling_or_hovering_the_grid_does_not_recompute_the_statistics(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
@@ -2557,18 +2620,15 @@ mod tests {
|
||||
let renders = grid.read_with(cx, |grid, _| grid.renders);
|
||||
assert!(set_cards > 0);
|
||||
|
||||
let hovers = Rc::new(Cell::new(0));
|
||||
let _subscription = cx.update(|_, cx| {
|
||||
let hovers = hovers.clone();
|
||||
cx.observe(&grid, move |_, _| hovers.set(hovers.get() + 1))
|
||||
});
|
||||
let hovers = count_hovers(&grid, cx);
|
||||
for id in ["card-1", "card-2"] {
|
||||
let card = center(cx, id);
|
||||
cx.simulate_mouse_move(card, None, Modifiers::none());
|
||||
draw(cx);
|
||||
}
|
||||
settle(cx);
|
||||
assert!(hovers.get() > 0, "no card was hovered");
|
||||
assert!(grid.read_with(cx, |grid, _| grid.renders) > renders);
|
||||
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders);
|
||||
|
||||
let over = center(cx, "card-1");
|
||||
cx.simulate_event(ScrollEvent {
|
||||
@@ -2591,6 +2651,19 @@ mod tests {
|
||||
assert!(!page.read_with(cx, |page, _| page.stats_job.running()));
|
||||
}
|
||||
|
||||
/// How many times the card under the pointer or the keyboard changes in `grid`.
|
||||
fn count_hovers(grid: &Entity<CardGrid>, cx: &mut VisualTestContext) -> Rc<Cell<usize>> {
|
||||
let hovers = Rc::new(Cell::new(0));
|
||||
let counted = hovers.clone();
|
||||
cx.update(|_, cx| {
|
||||
cx.subscribe(grid, move |_, _: &crate::card_grid::CardHovered, _| {
|
||||
counted.set(counted.get() + 1)
|
||||
})
|
||||
.detach()
|
||||
});
|
||||
hovers
|
||||
}
|
||||
|
||||
fn center(cx: &mut VisualTestContext, id: &'static str) -> gpui_kit::Point<gpui_kit::Pixels> {
|
||||
cx.debug_bounds(id).unwrap().center()
|
||||
}
|
||||
@@ -2633,7 +2706,9 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
/// The cards showing their sheet once their lift has played.
|
||||
fn sheet_ids(cx: &mut VisualTestContext, count: u32) -> Vec<u32> {
|
||||
settle(cx);
|
||||
(1..=count).filter(|&id| sheet(cx, id).is_some()).collect()
|
||||
}
|
||||
|
||||
@@ -2667,6 +2742,129 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// How far the lifted card `id` stands above its place in the grid, if it is drawn lifted.
|
||||
fn rise(cx: &mut VisualTestContext, id: u32) -> Option<f32> {
|
||||
let lifted = cx.debug_bounds(Box::leak(format!("lifted-{id}").into_boxed_str()))?;
|
||||
let place = cx
|
||||
.debug_bounds(Box::leak(format!("card-{id}").into_boxed_str()))
|
||||
.unwrap();
|
||||
assert_eq!(lifted.size, place.size, "the lifted card changed size");
|
||||
Some((place.origin.y - lifted.origin.y).as_f32())
|
||||
}
|
||||
|
||||
fn hover(cx: &mut VisualTestContext, id: &'static str) {
|
||||
let at = center(cx, id);
|
||||
cx.simulate_mouse_move(at, None, Modifiers::none());
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
// The card under the pointer rises over the grid, from where the grid placed it, and settles
|
||||
// back once left: the grid stays cached through it all, no card is built and no statistics
|
||||
// are computed, and no frame is asked for once the cards are still.
|
||||
#[gpui::test]
|
||||
fn hovering_a_card_lifts_it_over_the_grid_which_is_not_drawn_again(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(1, 170, sheet_champions(170)));
|
||||
draw(cx);
|
||||
settle(cx);
|
||||
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
||||
let generation = page.read_with(cx, |page, _| page.stats_generation);
|
||||
let built = |cx: &mut VisualTestContext| {
|
||||
grid.read_with(cx, |grid, _| {
|
||||
(grid.renders, grid.card_builds, grid.set_cards_calls)
|
||||
})
|
||||
};
|
||||
let at_rest = built(cx);
|
||||
|
||||
hover(cx, "card-2");
|
||||
assert_eq!(rise(cx, 2), Some(0.), "it jumped");
|
||||
frame_after(cx, 100);
|
||||
let rising = rise(cx, 2).expect("the card is not lifted");
|
||||
assert!(rising > 0. && rising < 10., "{rising}");
|
||||
// Its sheet slides up while it rises.
|
||||
assert!(cx.debug_bounds("sheet-2").is_some());
|
||||
settle(cx);
|
||||
assert_eq!(rise(cx, 2), Some(10.));
|
||||
|
||||
// To the next card: it rises while the one left settles back.
|
||||
hover(cx, "card-3");
|
||||
frame_after(cx, 100);
|
||||
assert!(rise(cx, 2).is_some_and(|rise| rise > 0. && rise < 10.));
|
||||
assert!(rise(cx, 3).is_some_and(|rise| rise > 0. && rise < 10.));
|
||||
settle(cx);
|
||||
assert_eq!(rise(cx, 2), None, "the card left stayed lifted");
|
||||
assert_eq!(rise(cx, 3), Some(10.));
|
||||
|
||||
cx.simulate_mouse_move(point(px(5.), px(5.)), None, Modifiers::none());
|
||||
draw(cx);
|
||||
settle(cx);
|
||||
assert_eq!(rise(cx, 3), None);
|
||||
frame_after(cx, 16);
|
||||
let asked = cx.update(|window, cx| window.simulate_next_frame(cx));
|
||||
assert_eq!(asked, 0, "a frame is asked for at rest");
|
||||
|
||||
assert_eq!(built(cx), at_rest, "the grid was drawn again");
|
||||
assert_eq!(
|
||||
page.read_with(cx, |page, _| page.stats_generation),
|
||||
generation
|
||||
);
|
||||
assert!(!page.read_with(cx, |page, _| page.stats_job.running()));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_greyed_card_rises_less_with_the_same_sheet(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(1, 12, sheet_champions(12)));
|
||||
draw(cx);
|
||||
// The first champion is Completed: greyed.
|
||||
hover(cx, "card-1");
|
||||
assert_eq!(sheet_ids(cx, 12), [1]);
|
||||
assert_eq!(sheet(cx, 1), Some(true));
|
||||
assert_eq!(rise(cx, 1), Some(4.));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn without_animations_the_sheet_shows_at_once_and_the_card_stays_put(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(1, 12, sheet_champions(12)));
|
||||
draw(cx);
|
||||
settle(cx);
|
||||
animations(cx, false);
|
||||
draw(cx);
|
||||
|
||||
hover(cx, "card-2");
|
||||
assert_eq!(rise(cx, 2), Some(0.));
|
||||
assert!(cx.debug_bounds("sheet-2").is_some(), "the sheet waits");
|
||||
let asked = cx.update(|window, cx| window.simulate_next_frame(cx));
|
||||
assert_eq!(asked, 0, "a frame is asked for");
|
||||
|
||||
// Left, it is gone at once.
|
||||
hover(cx, "card-3");
|
||||
assert_eq!(rise(cx, 2), None);
|
||||
assert_eq!(rise(cx, 3), Some(0.));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn turning_animations_off_puts_a_rising_card_where_it_goes(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(1, 12, sheet_champions(12)));
|
||||
draw(cx);
|
||||
hover(cx, "card-2");
|
||||
frame_after(cx, 50);
|
||||
animations(cx, false);
|
||||
draw(cx);
|
||||
assert_eq!(rise(cx, 2), Some(0.));
|
||||
assert!(cx.debug_bounds("sheet-2").is_some());
|
||||
// The frame asked for before is the last.
|
||||
frame_after(cx, 16);
|
||||
let asked = cx.update(|window, cx| window.simulate_next_frame(cx));
|
||||
assert_eq!(asked, 0, "a frame is asked for");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn scrolling_the_grid_hides_the_sheet_of_the_card_that_was_under_the_pointer(
|
||||
cx: &mut TestAppContext,
|
||||
@@ -2686,13 +2884,20 @@ mod tests {
|
||||
..Default::default()
|
||||
});
|
||||
draw(cx);
|
||||
// At once, with no card settling back from where it was.
|
||||
assert!(
|
||||
cx.debug_bounds("lifted-1").is_none(),
|
||||
"the card stayed lifted"
|
||||
);
|
||||
assert!(sheet_ids(cx, 170).is_empty(), "the sheet stuck to its card");
|
||||
}
|
||||
|
||||
/// The focus on the sort selector, the last stop of the home's tools before the cards.
|
||||
/// The focus on the sort selector, the last stop of the home's tools before the cards, in
|
||||
/// the window in front: the focus moves only there.
|
||||
fn focus_sort(page: &Entity<Page>, cx: &mut VisualTestContext) {
|
||||
let select = page.read_with(cx, |p, _| p.sort_select.clone());
|
||||
cx.update(|window, cx| {
|
||||
window.activate_window();
|
||||
let handle = select.read(cx).focus_handle(cx);
|
||||
window.focus(&handle, cx)
|
||||
});
|
||||
@@ -2779,8 +2984,9 @@ mod tests {
|
||||
assert!(sheet_ids(cx, 3).is_empty(), "the focus stayed in the grid");
|
||||
}
|
||||
|
||||
// Hovering or tabbing over the cards notifies the grid view (GPUI draws its parent page again
|
||||
// too): the cards are not built again and no statistics are computed.
|
||||
// Hovering the cards does not draw the grid again; tabbing over them does (GPUI draws the
|
||||
// whole window when the focus moves). Neither builds the cards again nor computes any
|
||||
// statistics.
|
||||
#[gpui::test]
|
||||
fn showing_a_sheet_does_not_rebuild_the_cards_nor_recompute_the_statistics(
|
||||
cx: &mut TestAppContext,
|
||||
@@ -2789,6 +2995,8 @@ mod tests {
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(1, 170, sheet_champions(170)));
|
||||
draw(cx);
|
||||
// The Completed card's crown is loaded, which draws the grid again.
|
||||
settle(cx);
|
||||
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
||||
let generation = page.read_with(cx, |page, _| page.stats_generation);
|
||||
let set_cards = grid.read_with(cx, |grid, _| grid.set_cards_calls);
|
||||
@@ -2799,14 +3007,13 @@ mod tests {
|
||||
cx.simulate_mouse_move(card, None, Modifiers::none());
|
||||
draw(cx);
|
||||
}
|
||||
let hovered_renders = grid.read_with(cx, |grid, _| grid.renders);
|
||||
assert!(hovered_renders > renders, "the grid was not drawn");
|
||||
settle(cx);
|
||||
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders);
|
||||
|
||||
focus_sort(&page, cx);
|
||||
for _ in 0..10 {
|
||||
press(cx, "tab");
|
||||
}
|
||||
assert!(grid.read_with(cx, |grid, _| grid.renders) > hovered_renders);
|
||||
// The key presses ended the pointer's hover: the focused card alone shows its sheet.
|
||||
assert_eq!(sheet_ids(cx, 170), [10]);
|
||||
|
||||
@@ -2862,6 +3069,11 @@ mod tests {
|
||||
assert_eq!(page.read_with(cx, |page, _| page.tab), Tab::Statistics);
|
||||
}
|
||||
|
||||
/// Lets the cards lifting or settling back reach where they go.
|
||||
fn settle(cx: &mut VisualTestContext) {
|
||||
frame_after(cx, 400);
|
||||
}
|
||||
|
||||
/// Moves the test clock on, then delivers the next frame as the display would.
|
||||
fn frame_after(cx: &mut VisualTestContext, ms: u64) {
|
||||
cx.executor().advance_clock(Duration::from_millis(ms));
|
||||
@@ -3975,8 +4187,45 @@ mod tests {
|
||||
assert_eq!(ids(&anvil_cards(&page, &mut window)), [233]);
|
||||
}
|
||||
|
||||
// As the home grid's test: hovering the cards of « Autres champions » or scrolling it notifies
|
||||
// the grid, and costs no statistics and no cards. (The capture's catalog is too short for
|
||||
// In the hand alone, a veil lays on the other cards while one is lifted; the hand is not
|
||||
// drawn again.
|
||||
#[gpui::test]
|
||||
async fn in_the_hand_a_veil_lays_on_the_other_cards(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
let cx = &mut window;
|
||||
settle(cx);
|
||||
let hand = page.read_with(cx, |p, _| p.anvil_grid.clone());
|
||||
let renders = hand.read_with(cx, |grid, _| grid.renders);
|
||||
let id = ids(&anvil_cards(&page, cx))[0];
|
||||
let veil = |cx: &mut VisualTestContext, grid: &Entity<CardGrid>| {
|
||||
page.read_with(cx, |p, cx| {
|
||||
p.lifts
|
||||
.veil(grid.entity_id(), cx.background_executor().now())
|
||||
})
|
||||
};
|
||||
hover(cx, Box::leak(format!("card-{id}").into_boxed_str()));
|
||||
settle(cx);
|
||||
assert_eq!(rise(cx, id), Some(10.));
|
||||
assert_eq!(veil(cx, &hand), 1.);
|
||||
assert_eq!(hand.read_with(cx, |grid, _| grid.renders), renders);
|
||||
|
||||
cx.simulate_mouse_move(point(px(5.), px(5.)), None, Modifiers::none());
|
||||
draw(cx);
|
||||
settle(cx);
|
||||
assert_eq!(veil(cx, &hand), 0.);
|
||||
|
||||
// « Autres champions » has none.
|
||||
click_others(cx);
|
||||
scroll_champ_select_down(cx);
|
||||
let others = page.read_with(cx, |p, _| p.others_grid.clone());
|
||||
hover(cx, "card-103");
|
||||
settle(cx);
|
||||
assert_eq!(rise(cx, 103), Some(10.));
|
||||
assert_eq!(veil(cx, &others), 0.);
|
||||
}
|
||||
|
||||
// As the home grid's test: hovering the cards of « Autres champions » does not draw its grid
|
||||
// again, and neither it nor scrolling costs statistics or cards. (The capture's catalog is too short for
|
||||
// the list to scroll: the wheel still reaches the grid, which is what clears its hover.)
|
||||
#[gpui::test]
|
||||
async fn hovering_or_scrolling_others_does_not_recompute_the_statistics(
|
||||
@@ -3992,18 +4241,15 @@ mod tests {
|
||||
let renders = grid.read_with(cx, |grid, _| grid.renders);
|
||||
assert!(set_cards > 0 && renders > 0);
|
||||
|
||||
let hovers = Rc::new(Cell::new(0));
|
||||
let _subscription = cx.update(|_, cx| {
|
||||
let hovers = hovers.clone();
|
||||
cx.observe(&grid, move |_, _| hovers.set(hovers.get() + 1))
|
||||
});
|
||||
let hovers = count_hovers(&grid, cx);
|
||||
for id in ["card-103", "card-12", "card-103"] {
|
||||
let card = center(cx, id);
|
||||
cx.simulate_mouse_move(card, None, Modifiers::none());
|
||||
draw(cx);
|
||||
}
|
||||
settle(cx);
|
||||
assert!(hovers.get() > 0, "no card was hovered");
|
||||
assert!(grid.read_with(cx, |grid, _| grid.renders) > renders);
|
||||
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders);
|
||||
|
||||
let over = center(cx, "card-103");
|
||||
cx.simulate_event(ScrollEvent {
|
||||
|
||||
@@ -130,10 +130,11 @@ impl Page {
|
||||
// Cached: only a change to the cards, the filter, the search or a hover
|
||||
// or scroll over them draws the grid again. Its size comes from this
|
||||
// style.
|
||||
column =
|
||||
column.child(self.home_grid.clone().cached(
|
||||
column = column
|
||||
.child(self.home_grid.clone().cached(
|
||||
StyleRefinement::default().w_full().flex_1().min_h(px(240.)),
|
||||
));
|
||||
))
|
||||
.children(self.lift_layer(&self.home_grid, cx));
|
||||
}
|
||||
}
|
||||
// Without statistics the heading would count « 0 » and the grid would say no
|
||||
@@ -237,6 +238,7 @@ impl Page {
|
||||
.into_any_element(),
|
||||
None => self.anvil_grid.clone().into_any_element(),
|
||||
})
|
||||
.children(self.lift_layer(&self.anvil_grid, cx))
|
||||
.into_any_element(),
|
||||
),
|
||||
})
|
||||
@@ -321,6 +323,7 @@ impl Page {
|
||||
.min_h(row_height(window_width)),
|
||||
),
|
||||
)
|
||||
.children(self.lift_layer(&self.others_grid, cx))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,15 @@ pub fn gold_ink(theme: &Theme) -> Hsla {
|
||||
theme.link
|
||||
}
|
||||
|
||||
/// The gold glow around a card lifted under the pointer.
|
||||
pub fn gold_glow(theme: &Theme) -> Hsla {
|
||||
if theme.mode.is_dark() {
|
||||
Hsla::from(rgb(LOGO_GOLD)).opacity(0.55)
|
||||
} else {
|
||||
Hsla::from(rgb(LIGHT_GOLD)).opacity(0.45)
|
||||
}
|
||||
}
|
||||
|
||||
/// The pale gold of a played champion's tick on the ring.
|
||||
pub fn ring_played(theme: &Theme) -> Hsla {
|
||||
if theme.mode.is_dark() {
|
||||
|
||||
Reference in new issue
Block a user