Show the tall portraits on the cards, decoded only while shown (#77)
The champions thread downloads the card portraits after the square ones and tells the page at most once a second while they arrive, plus once at the end, so each shows without a restart. A card shows its tall portrait, the square icon while it is missing, else its plain background. Each card grid reads its portraits through its own image cache: only the cards it paints are loaded, and what its previous render did not paint is dropped at its next render, from the GPU atlas too, and all of it with the grid. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f1e8808082
commit
815daf33cb
8 files changed
+707
-11
No files matched your search
@@ -1,5 +1,6 @@
|
||||
//! 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.
|
||||
//! built. It is its own view because it owns the scrolling and the hover of its cards, and the
|
||||
//! portraits they show (`card_images`).
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Range;
|
||||
@@ -10,6 +11,7 @@ use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::card::{ASPECT, Card, CardState, card};
|
||||
use crate::card_images::{self, CardImages};
|
||||
use crate::page::PAGE_PADDING;
|
||||
|
||||
actions!(card_grid, [NextCard, PreviousCard]);
|
||||
@@ -92,6 +94,8 @@ pub struct CardGrid {
|
||||
/// All the rows built as a plain column, with no scrolling of its own: for a short list
|
||||
/// whose height comes from its content (the Anvil champions row of a champ select).
|
||||
fit_content: bool,
|
||||
/// The portraits of the cards it paints, its own: made by its first render.
|
||||
images: Option<Entity<CardImages>>,
|
||||
/// Guard the light rendering in tests.
|
||||
#[cfg(test)]
|
||||
pub(crate) renders: usize,
|
||||
@@ -111,6 +115,7 @@ impl CardGrid {
|
||||
focus: HashMap::new(),
|
||||
focus_stale: false,
|
||||
fit_content: false,
|
||||
images: None,
|
||||
#[cfg(test)]
|
||||
renders: 0,
|
||||
#[cfg(test)]
|
||||
@@ -232,6 +237,11 @@ impl CardGrid {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn images(&self) -> Option<&Entity<CardImages>> {
|
||||
self.images.as_ref()
|
||||
}
|
||||
|
||||
/// How far the grid is scrolled down.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn scrolled(&self) -> Pixels {
|
||||
@@ -285,9 +295,10 @@ impl CardGrid {
|
||||
}
|
||||
|
||||
impl CardGrid {
|
||||
/// The grid's key context and what it reacts to besides its cards.
|
||||
fn wired(&self, root: Div, cx: &mut Context<Self>) -> Div {
|
||||
root.key_context(CONTEXT)
|
||||
/// The grid's key context, its portraits and what it reacts to besides its cards.
|
||||
fn wired(&self, root: Div, images: Entity<CardImages>, cx: &mut Context<Self>) -> Div {
|
||||
card_images::provide(root, images)
|
||||
.key_context(CONTEXT)
|
||||
// A wheel scroll moves cards under a still pointer without a hover event: the
|
||||
// sheet of the card that was under it would stay. The next mouse move hovers again.
|
||||
.on_scroll(cx.listener(|grid, _: &ScrollEvent, _, cx| {
|
||||
@@ -311,6 +322,10 @@ impl Render for CardGrid {
|
||||
if self.focus_stale {
|
||||
self.sync_focus(window, cx);
|
||||
}
|
||||
let images = (self.images)
|
||||
.get_or_insert_with(|| CardImages::new(cx))
|
||||
.clone();
|
||||
images.update(cx, |images, cx| images.start_render(window, cx));
|
||||
if self.shown.is_empty() {
|
||||
let muted = cx.theme().muted_foreground;
|
||||
return div()
|
||||
@@ -329,11 +344,11 @@ impl Render for CardGrid {
|
||||
.map(|ix| self.row(ix, metrics, window, cx))
|
||||
.collect();
|
||||
return self
|
||||
.wired(div().v_flex().w_full(), cx)
|
||||
.wired(div().v_flex().w_full(), images, cx)
|
||||
.children(rows)
|
||||
.into_any_element();
|
||||
}
|
||||
self.wired(div().relative().size_full(), cx)
|
||||
self.wired(div().relative().size_full(), images, cx)
|
||||
.child(
|
||||
uniform_list(
|
||||
"cards",
|
||||
|
||||
Reference in new issue
Block a user