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
+25
-2
@@ -74,7 +74,7 @@ impl Reason {
|
||||
pub struct Card {
|
||||
pub id: u32,
|
||||
pub name: SharedString,
|
||||
/// The square icon today; the tall art later.
|
||||
/// The tall portrait, else the square icon while the tall one is not downloaded yet.
|
||||
pub portrait: Option<PathBuf>,
|
||||
pub marks: Marks,
|
||||
/// In display order. A card with any reason is greyed.
|
||||
@@ -106,7 +106,7 @@ impl Card {
|
||||
Card {
|
||||
id: row.champion.id,
|
||||
name: row.champion.name.clone().into(),
|
||||
portrait: row.portrait.clone(),
|
||||
portrait: row.card_portrait.clone().or_else(|| row.portrait.clone()),
|
||||
marks,
|
||||
reasons: if marks.completed {
|
||||
vec![Reason::Completed]
|
||||
@@ -354,6 +354,8 @@ fn mark(label: &'static str, on: bool) -> Div {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use arena_tracker_core::{Champion, ChampionChallenge, ChampionRow, Date, Unavailability};
|
||||
|
||||
// Explicit imports: a glob of `gpui_kit` would shadow the built-in `#[test]`.
|
||||
@@ -530,6 +532,27 @@ mod tests {
|
||||
assert!(!card.greyed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tall_portrait_is_shown_and_the_square_icon_stands_in_while_it_is_missing() {
|
||||
let tall = PathBuf::from("portraits/cards/TwistedFate.jpg");
|
||||
let square = PathBuf::from("portraits/TwistedFate.png");
|
||||
let both = ChampionRow {
|
||||
portrait: Some(square.clone()),
|
||||
card_portrait: Some(tall.clone()),
|
||||
..row(None)
|
||||
};
|
||||
assert_eq!(Card::from_row(&both).portrait, Some(tall));
|
||||
|
||||
let downloading = ChampionRow {
|
||||
card_portrait: None,
|
||||
..both
|
||||
};
|
||||
assert_eq!(Card::from_row(&downloading).portrait, Some(square));
|
||||
|
||||
// Neither: the card keeps its plain background.
|
||||
assert_eq!(Card::from_row(&row(None)).portrait, None);
|
||||
}
|
||||
|
||||
fn completed_row() -> ChampionRow {
|
||||
row(Some(ChampionChallenge {
|
||||
matches: 1,
|
||||
|
||||
Reference in new issue
Block a user