Replace the home header with the banner and the ring (#84)
CI / core (pull_request) Successful in 1m32s
CI / core (pull_request) Successful in 1m32s
The banner shows the ring, a cached view with one tick per champion of the Challenge in a fixed order, the Season, the « N / total champions validés » title, the last Completed champion and the last Match, over the splash of the last Completed champion, faded into the band. In a narrow window the ring goes above the text and the splash covers the banner. Hovering a card lights its tick. The banner reads its splash through its own cache: two at most, the one replaced given back from the GPU atlas too, none while « Statistiques » is shown or without an illustration. 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
e28aefc3bc
commit
d256dd61d2
9 files changed
+1397
-102
No files matched your search
@@ -0,0 +1,137 @@
|
||||
//! The banner's illustration: the splash of one champion, decoded off the UI thread and held by
|
||||
//! the banner alone, never by GPUI's app-wide asset cache (rule #1: memory in proportion to what
|
||||
//! is shown).
|
||||
//!
|
||||
//! It holds two splashes at most: the one shown and the one replacing it, which shows once
|
||||
//! decoded. The one it replaces is then given back, in memory and in the window's atlas, as the
|
||||
//! card portraits are (#77).
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use arena_tracker_core::{Splash, SplashFocus};
|
||||
use gpui_kit::*;
|
||||
|
||||
struct Held {
|
||||
splash: Rc<Splash>,
|
||||
item: ImageCacheItem,
|
||||
}
|
||||
|
||||
impl Held {
|
||||
fn new(splash: &Rc<Splash>, cx: &mut App) -> Held {
|
||||
Held {
|
||||
splash: splash.clone(),
|
||||
item: ImageCacheItem::new(&Resource::Path(splash.path.clone().into()), cx),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives the image back, from `window`'s atlas and the others'; a load still running is
|
||||
/// cancelled.
|
||||
fn drop_image(self, window: Option<&mut Window>, cx: &mut App) {
|
||||
if let Some(Ok(image)) = self.item.get() {
|
||||
cx.drop_image(image, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BannerArt {
|
||||
shown: Option<Held>,
|
||||
/// The splash to show next, while it decodes.
|
||||
next: Option<Held>,
|
||||
/// Loads started.
|
||||
#[cfg(test)]
|
||||
pub(crate) loads: usize,
|
||||
}
|
||||
|
||||
impl BannerArt {
|
||||
pub fn new(cx: &mut App) -> Entity<BannerArt> {
|
||||
let art = cx.new(|_| BannerArt {
|
||||
shown: None,
|
||||
next: None,
|
||||
#[cfg(test)]
|
||||
loads: 0,
|
||||
});
|
||||
// The page is gone: so are the splashes, from every window's atlas too.
|
||||
cx.observe_release(&art, |art, cx| art.drop_all(None, cx))
|
||||
.detach();
|
||||
art
|
||||
}
|
||||
|
||||
/// For the paint of `splash`: the image to paint and its focus. That is `splash` once
|
||||
/// decoded, and until then the splash shown before it. The view painting is drawn again when
|
||||
/// the decoding ends. A splash that cannot be read shows nothing.
|
||||
pub fn image(
|
||||
&mut self,
|
||||
splash: &Rc<Splash>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Option<(Arc<RenderImage>, SplashFocus)> {
|
||||
if self
|
||||
.shown
|
||||
.as_ref()
|
||||
.is_some_and(|held| held.splash == *splash)
|
||||
{
|
||||
if let Some(stale) = self.next.take() {
|
||||
stale.drop_image(Some(window), cx);
|
||||
}
|
||||
} else {
|
||||
if self
|
||||
.next
|
||||
.as_ref()
|
||||
.is_some_and(|held| held.splash != *splash)
|
||||
&& let Some(stale) = self.next.take()
|
||||
{
|
||||
stale.drop_image(Some(window), cx);
|
||||
}
|
||||
let next = self.next.get_or_insert_with(|| {
|
||||
#[cfg(test)]
|
||||
{
|
||||
self.loads += 1;
|
||||
}
|
||||
Held::new(splash, cx)
|
||||
});
|
||||
if next.item.use_image(window).is_some() {
|
||||
// Decoded, or failed: it replaces the one shown.
|
||||
if let Some(replaced) = self.shown.take() {
|
||||
replaced.drop_image(Some(window), cx);
|
||||
}
|
||||
self.shown = self.next.take();
|
||||
}
|
||||
}
|
||||
let shown = self.shown.as_ref()?;
|
||||
let image = shown.item.use_image(window)?.ok()?;
|
||||
Some((image, shown.splash.focus))
|
||||
}
|
||||
|
||||
/// Drops both splashes, in memory and in the window's atlas, for a banner that is not shown
|
||||
/// or has no illustration: a load still running is cancelled.
|
||||
pub fn release(&mut self, window: &mut Window, cx: &mut App) {
|
||||
self.drop_all(Some(window), cx);
|
||||
}
|
||||
|
||||
fn drop_all(&mut self, mut window: Option<&mut Window>, cx: &mut App) {
|
||||
for held in [self.shown.take(), self.next.take()].into_iter().flatten() {
|
||||
held.drop_image(window.as_deref_mut(), cx);
|
||||
}
|
||||
}
|
||||
|
||||
/// The splashes held, loaded or not.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn held(&self) -> Vec<std::path::PathBuf> {
|
||||
[&self.shown, &self.next]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|held| held.splash.path.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The splashes decoded.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn loaded(&self) -> Vec<Arc<RenderImage>> {
|
||||
[&self.shown, &self.next]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|held| held.item.get()?.ok())
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,10 @@ 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.
|
||||
#[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).
|
||||
struct CardFocus {
|
||||
@@ -118,6 +122,8 @@ pub struct CardGrid {
|
||||
pub(crate) set_cards_calls: usize,
|
||||
}
|
||||
|
||||
impl EventEmitter<CardHovered> for CardGrid {}
|
||||
|
||||
impl CardGrid {
|
||||
pub fn new() -> CardGrid {
|
||||
CardGrid {
|
||||
@@ -189,6 +195,7 @@ impl CardGrid {
|
||||
};
|
||||
if next != self.hovered {
|
||||
self.hovered = next;
|
||||
cx.emit(CardHovered(next));
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
@@ -227,6 +234,10 @@ impl CardGrid {
|
||||
/// The grid is not shown any more: its portraits are given back, in memory and in the
|
||||
/// window's atlas, and load again when it is drawn.
|
||||
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.
|
||||
if self.hovered.take().is_some() {
|
||||
cx.emit(CardHovered(None));
|
||||
}
|
||||
let released = self
|
||||
.images
|
||||
.as_ref()
|
||||
@@ -334,6 +345,7 @@ impl CardGrid {
|
||||
// sheet of the card that was under it would stay. The next mouse move hovers again.
|
||||
.on_scroll(cx.listener(|grid, _: &ScrollEvent, _, cx| {
|
||||
if grid.hovered.take().is_some() {
|
||||
cx.emit(CardHovered(None));
|
||||
cx.notify();
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod banner_art;
|
||||
mod card;
|
||||
mod card_grid;
|
||||
mod card_images;
|
||||
@@ -9,6 +10,7 @@ mod page;
|
||||
#[cfg(feature = "profile")]
|
||||
mod profile;
|
||||
mod release;
|
||||
mod ring;
|
||||
mod settings;
|
||||
mod single_instance;
|
||||
mod text;
|
||||
|
||||
+529
-30
@@ -24,10 +24,12 @@ use gpui_kit::*;
|
||||
mod home;
|
||||
mod statistics;
|
||||
|
||||
use crate::banner_art::BannerArt;
|
||||
use crate::card::Card;
|
||||
use crate::card_grid::CardGrid;
|
||||
use crate::card_grid::{CardGrid, CardHovered};
|
||||
use crate::card_order::card_order;
|
||||
use crate::champion_table::ChampionTable;
|
||||
use crate::ring::{self, Ring, Tick};
|
||||
use crate::text::{CLIENT_ABSENT, official_differs, sync_line};
|
||||
use crate::worker::{
|
||||
LiveChampSelect, Msg, RefreshGate, compute_statistics, spawn_refresh, spawn_statistics,
|
||||
@@ -173,10 +175,12 @@ pub struct Page {
|
||||
/// The Account and scope `home_stats` or `home_error` were computed for: the home does not
|
||||
/// depend on the Format, so a change of Format keeps them.
|
||||
home_computed: Option<(String, Scope)>,
|
||||
/// « N / total », prepared when the statistics change.
|
||||
home_count: SharedString,
|
||||
/// Completed over total, for the progress line.
|
||||
home_fraction: f32,
|
||||
/// What the banner shows, prepared when the statistics change.
|
||||
banner: home::BannerContent,
|
||||
/// The banner's ring: a cached view.
|
||||
ring: Entity<Ring>,
|
||||
/// 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.
|
||||
home_filter: StateFilter,
|
||||
home_search: ChampionSearch,
|
||||
@@ -220,6 +224,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,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
_listener: Task<()>,
|
||||
}
|
||||
@@ -277,8 +284,13 @@ impl Page {
|
||||
cx.new(|cx| InputState::new(window, cx).placeholder("Rechercher"));
|
||||
let others_grid = cx.new(|_| CardGrid::new());
|
||||
let others_focus = cx.focus_handle().tab_stop(true);
|
||||
let ring = cx.new(|_| Ring::new());
|
||||
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),
|
||||
cx.subscribe(&search_input, |this, input, event: &InputEvent, cx| {
|
||||
if matches!(event, InputEvent::Change) {
|
||||
this.search = ChampionSearch::new(&input.read(cx).value());
|
||||
@@ -403,8 +415,9 @@ impl Page {
|
||||
home_stats: None,
|
||||
home_error: None,
|
||||
home_computed: None,
|
||||
home_count: SharedString::default(),
|
||||
home_fraction: 0.,
|
||||
banner: home::BannerContent::default(),
|
||||
ring,
|
||||
banner_art,
|
||||
home_filter: StateFilter::All,
|
||||
home_search: ChampionSearch::new(""),
|
||||
home_search_input,
|
||||
@@ -431,6 +444,7 @@ impl Page {
|
||||
others_search_input,
|
||||
others_grid,
|
||||
others_focus,
|
||||
others_hover,
|
||||
_subscriptions: subscriptions,
|
||||
_listener: listener,
|
||||
};
|
||||
@@ -562,6 +576,9 @@ impl Page {
|
||||
// with the grid.
|
||||
self.home_grid
|
||||
.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
// Nor is the banner: its illustration too.
|
||||
self.banner_art
|
||||
.update(cx, |art, cx| art.release(window, cx));
|
||||
}
|
||||
// The tab left was not kept up to date.
|
||||
self.refresh_table(cx);
|
||||
@@ -928,12 +945,12 @@ impl Page {
|
||||
self.reorder();
|
||||
if self.in_champ_select() {
|
||||
// Neither the charts, the table nor the home grid are shown during a champ select.
|
||||
self.prepare_home_labels();
|
||||
self.prepare_banner(cx);
|
||||
self.prepare_champ_select(cx);
|
||||
cx.notify();
|
||||
return;
|
||||
}
|
||||
self.prepare_home_labels();
|
||||
self.prepare_banner(cx);
|
||||
self.prepare_home_cards(cx);
|
||||
let charts = self.stats.as_ref().map(|s| &s.charts);
|
||||
let in_season = self.in_season();
|
||||
@@ -955,15 +972,36 @@ impl Page {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// The counter's text and the progress line's length, for when the statistics change.
|
||||
fn prepare_home_labels(&mut self) {
|
||||
let challenge = self.home_statistics().and_then(|s| s.challenge.as_ref());
|
||||
let count = challenge.map(|c| format!("{} / {}", c.completed, c.total));
|
||||
let fraction = challenge.map_or(0., |c| {
|
||||
(c.completed as f32 / c.total.max(1) as f32).clamp(0., 1.)
|
||||
});
|
||||
self.home_count = count.unwrap_or_default().into();
|
||||
self.home_fraction = fraction;
|
||||
/// The banner's text and the ring's ticks, for when the home statistics change. Neither
|
||||
/// follows the Format, the filter, the search nor the sort.
|
||||
fn prepare_banner(&mut self, cx: &mut Context<Self>) {
|
||||
let stats = self.home_statistics();
|
||||
let banner = home::BannerContent::new(self.home_season.as_ref(), stats);
|
||||
let ticks: Rc<[Tick]> = stats
|
||||
.and_then(|s| {
|
||||
Some(ring::ticks(
|
||||
&s.rows,
|
||||
&s.challenge.as_ref()?.completion_order,
|
||||
))
|
||||
})
|
||||
.unwrap_or_default()
|
||||
.into();
|
||||
self.banner = banner;
|
||||
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, _, CardHovered(id): &CardHovered, cx| {
|
||||
this.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.
|
||||
fn new_others_grid(&mut self, cx: &mut Context<Self>) {
|
||||
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));
|
||||
}
|
||||
|
||||
/// Computes the cards' order again: for when the home statistics (the champ select's during
|
||||
@@ -1105,7 +1143,7 @@ impl Page {
|
||||
if self.others_open {
|
||||
self.prepare_others(cx);
|
||||
} else {
|
||||
self.others_grid = cx.new(|_| CardGrid::new());
|
||||
self.new_others_grid(cx);
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
@@ -1114,7 +1152,7 @@ impl Page {
|
||||
fn fold_others(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self.others_open {
|
||||
self.others_open = false;
|
||||
self.others_grid = cx.new(|_| CardGrid::new());
|
||||
self.new_others_grid(cx);
|
||||
}
|
||||
self.others_search = ChampionSearch::new("");
|
||||
self.others_search_input
|
||||
@@ -1740,6 +1778,8 @@ mod tests {
|
||||
attempts: 0,
|
||||
average_attempts: None,
|
||||
first_tries: 0,
|
||||
completion_order: Vec::new(),
|
||||
last_match: None,
|
||||
}),
|
||||
rows,
|
||||
charts: Charts {
|
||||
@@ -1784,7 +1824,7 @@ mod tests {
|
||||
assert_eq!(page.season, SeasonScope::AllSeasons);
|
||||
assert_eq!(page.home_season, None);
|
||||
assert!(page.home_statistics().is_none());
|
||||
assert!(page.home_count.is_empty());
|
||||
assert!(page.banner.title.text.is_empty());
|
||||
assert!(page.home_grid.read(cx).names().is_empty());
|
||||
});
|
||||
}
|
||||
@@ -1899,17 +1939,16 @@ mod tests {
|
||||
names.sort();
|
||||
names
|
||||
};
|
||||
let counter = |cx: &mut VisualTestContext| {
|
||||
page.read_with(cx, |p, _| (p.home_count.to_string(), p.home_fraction))
|
||||
};
|
||||
let counter =
|
||||
|cx: &mut VisualTestContext| page.read_with(cx, |p, _| p.banner.title.text.to_string());
|
||||
assert_eq!(names(cx), ["Ahri", "Akali", "Annie", "Zed"]);
|
||||
assert_eq!(counter(cx), ("1 / 4".to_string(), 0.25));
|
||||
assert_eq!(counter(cx), "1 / 4 champions validés");
|
||||
|
||||
// The home's search is its own: the Statistics tab's is untouched.
|
||||
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
|
||||
cx.simulate_input("an");
|
||||
assert_eq!(names(cx), ["Annie"]);
|
||||
assert_eq!(counter(cx), ("1 / 4".to_string(), 0.25));
|
||||
assert_eq!(counter(cx), "1 / 4 champions validés");
|
||||
assert!(page.read_with(cx, |p, _| p.search.matches(&row("Zed").champion)));
|
||||
|
||||
cx.update(|window, cx| input.update(cx, |input, cx| input.clean(window, cx)));
|
||||
@@ -1920,14 +1959,14 @@ mod tests {
|
||||
assert_eq!(names(cx), ["Akali", "Annie", "Zed"]);
|
||||
cx.simulate_input("a");
|
||||
assert_eq!(names(cx), ["Akali", "Annie"]);
|
||||
assert_eq!(counter(cx), ("1 / 4".to_string(), 0.25));
|
||||
assert_eq!(counter(cx), "1 / 4 champions validés");
|
||||
|
||||
page.update(cx, |p, cx| {
|
||||
p.home_filter = StateFilter::Completed;
|
||||
p.refresh_home(cx);
|
||||
});
|
||||
assert_eq!(names(cx), ["Ahri"]);
|
||||
assert_eq!(counter(cx), ("1 / 4".to_string(), 0.25));
|
||||
assert_eq!(counter(cx), "1 / 4 champions validés");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
@@ -1960,6 +1999,7 @@ mod tests {
|
||||
let (season, apart, current) = home(&mut window);
|
||||
assert_eq!(season.as_deref(), Some("Récente"));
|
||||
assert!(!apart);
|
||||
assert_eq!(banner(&page, &mut window).season.as_ref(), "RÉCENTE");
|
||||
let current = current.unwrap();
|
||||
assert_eq!(current.rows.iter().map(|r| r.matches).sum::<usize>(), 1);
|
||||
|
||||
@@ -1972,6 +2012,11 @@ mod tests {
|
||||
assert_eq!(season.as_deref(), Some("Récente"));
|
||||
assert!(apart);
|
||||
assert_eq!(same.as_ref(), Some(¤t));
|
||||
let text = banner(&page, &mut window);
|
||||
assert_eq!(
|
||||
(text.season.as_ref(), text.title.text.as_ref()),
|
||||
("RÉCENTE", "0 / 1 champions validés")
|
||||
);
|
||||
|
||||
// Another Season: the home follows.
|
||||
recompute(&mut window, &|page| {
|
||||
@@ -1981,6 +2026,7 @@ mod tests {
|
||||
let (season, apart, other) = home(&mut window);
|
||||
assert_eq!(season.as_deref(), Some("Ancienne"));
|
||||
assert!(!apart);
|
||||
assert_eq!(banner(&page, &mut window).season.as_ref(), "ANCIENNE");
|
||||
let other = other.unwrap();
|
||||
assert_ne!(other, current);
|
||||
assert_eq!(other.rows.iter().map(|r| r.matches).sum::<usize>(), 0);
|
||||
@@ -2931,7 +2977,7 @@ mod tests {
|
||||
assert_eq!(p.viewed().unwrap().puuid, "Autre");
|
||||
assert_eq!(p.displayed().unwrap().puuid, "Joueur");
|
||||
assert_eq!(p.home_season.as_deref(), Some("Saison"));
|
||||
assert_eq!(p.home_count.as_ref(), "1 / 9");
|
||||
assert_eq!(p.banner.title.text.as_ref(), "1 / 9 champions validés");
|
||||
assert!(p.stats.as_ref().unwrap().challenge.is_some());
|
||||
});
|
||||
// The row is there; the grid, its filters and its search are not.
|
||||
@@ -2963,7 +3009,7 @@ mod tests {
|
||||
assert!(p.home_search_input.read(cx).value().is_empty());
|
||||
assert_eq!(p.home_shown_count.as_ref(), "9");
|
||||
assert_eq!(p.home_grid.read(cx).names().len(), 9);
|
||||
assert_eq!(p.home_count.as_ref(), "0 / 9");
|
||||
assert_eq!(p.banner.title.text.as_ref(), "0 / 9 champions validés");
|
||||
assert!(p.anvil_grid.read(cx).names().is_empty());
|
||||
});
|
||||
assert_eq!(
|
||||
@@ -3069,6 +3115,18 @@ mod tests {
|
||||
draw(window);
|
||||
}
|
||||
|
||||
/// Scrolls the champ select's column to its end, over the banner: the open « Autres
|
||||
/// champions » starts under the window's bottom edge.
|
||||
fn scroll_champ_select_down(window: &mut VisualTestContext) {
|
||||
let banner = center(window, "banner");
|
||||
window.simulate_event(ScrollEvent {
|
||||
position: banner,
|
||||
delta: ScrollDelta::Pixels(point(px(0.), px(-5000.))),
|
||||
..Default::default()
|
||||
});
|
||||
draw(window);
|
||||
}
|
||||
|
||||
/// Presses and releases `key` on the focused element, as the navigation's test does.
|
||||
fn activate(window: &mut VisualTestContext, key: &str) {
|
||||
let keystroke =
|
||||
@@ -3214,6 +3272,7 @@ mod tests {
|
||||
) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
click_others(&mut window);
|
||||
scroll_champ_select_down(&mut window);
|
||||
let cx = &mut window;
|
||||
let grid = page.read_with(cx, |p, _| p.others_grid.clone());
|
||||
let generation = page.read_with(cx, |p, _| p.stats_generation);
|
||||
@@ -4087,4 +4146,444 @@ mod tests {
|
||||
);
|
||||
assert_eq!(grid_names(&home_grid, &mut window), ALL_A_TO_Z);
|
||||
}
|
||||
|
||||
// ---- The banner and its ring (#84). ----
|
||||
|
||||
use arena_tracker_core::{LastMatch, MatchOutcome, Splash, SplashFocus};
|
||||
|
||||
use crate::ring::Tick;
|
||||
|
||||
fn on(month: u8, day: u8) -> Date {
|
||||
Date {
|
||||
year: 2026,
|
||||
month,
|
||||
day,
|
||||
}
|
||||
}
|
||||
|
||||
/// One champion of the banner's tests: `completed_on` makes it Completed, `matches` played.
|
||||
fn banner_champion(
|
||||
id: u32,
|
||||
name: &str,
|
||||
matches: usize,
|
||||
completed_on: Option<Date>,
|
||||
points: u64,
|
||||
) -> ChampionRow {
|
||||
let state = match (completed_on, matches) {
|
||||
(Some(_), _) => ChampionState::Completed,
|
||||
(None, 0) => ChampionState::NeverPlayed,
|
||||
(None, _) => ChampionState::InProgress,
|
||||
};
|
||||
ChampionRow {
|
||||
champion: Champion {
|
||||
id,
|
||||
key: name.into(),
|
||||
name: name.into(),
|
||||
},
|
||||
state: Some(state),
|
||||
challenge: Some(ChampionChallenge {
|
||||
matches,
|
||||
completed_on,
|
||||
..Default::default()
|
||||
}),
|
||||
mastery_points: Some(points),
|
||||
..row(name)
|
||||
}
|
||||
}
|
||||
|
||||
/// Brand then Ahri Completed, Garen and Zyra played, Lux never played; A to Z.
|
||||
fn banner_rows() -> Vec<ChampionRow> {
|
||||
vec![
|
||||
banner_champion(1, "Ahri", 3, Some(on(11, 20)), 100),
|
||||
banner_champion(2, "Brand", 1, Some(on(11, 3)), 5),
|
||||
banner_champion(4, "Garen", 2, None, 900),
|
||||
banner_champion(5, "Lux", 0, None, 10),
|
||||
banner_champion(3, "Zyra", 4, None, 50),
|
||||
]
|
||||
}
|
||||
|
||||
fn banner_statistics(
|
||||
rows: Vec<ChampionRow>,
|
||||
completion_order: Vec<u32>,
|
||||
last_match: Option<LastMatch>,
|
||||
) -> Statistics {
|
||||
let mut stats = statistics(completion_order.len(), rows.len(), rows);
|
||||
let challenge = stats.challenge.as_mut().unwrap();
|
||||
challenge.completion_order = completion_order;
|
||||
challenge.last_match = last_match;
|
||||
stats
|
||||
}
|
||||
|
||||
fn banner(page: &Entity<Page>, cx: &mut VisualTestContext) -> super::home::BannerContent {
|
||||
page.read_with(cx, |page, _| page.banner.clone())
|
||||
}
|
||||
|
||||
fn bold(line: &super::home::Line) -> &str {
|
||||
&line.text[line.bold.clone()]
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_banner_says_the_count_the_last_completion_and_the_last_match(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
let last_match = |champion_id, placement, outcome| {
|
||||
Some(LastMatch {
|
||||
champion_id,
|
||||
placement,
|
||||
outcome,
|
||||
})
|
||||
};
|
||||
let cases = [
|
||||
// Not yet Completed: its Attempt, the first one feminine.
|
||||
(
|
||||
last_match(3, 4, MatchOutcome::Attempt(3)),
|
||||
"Dernière Partie : Zyra, 4ᵉ · 3ᵉ Tentative",
|
||||
),
|
||||
(
|
||||
last_match(3, 2, MatchOutcome::Attempt(1)),
|
||||
"Dernière Partie : Zyra, 2ᵉ · 1ʳᵉ Tentative",
|
||||
),
|
||||
// The Match that completes it.
|
||||
(
|
||||
last_match(1, 1, MatchOutcome::Completed(3)),
|
||||
"Dernière Partie : Ahri, 1ᵉʳ · validé en 3 Tentatives",
|
||||
),
|
||||
(
|
||||
last_match(1, 1, MatchOutcome::Completed(1)),
|
||||
"Dernière Partie : Ahri, 1ᵉʳ · validé du premier coup",
|
||||
),
|
||||
// Already Completed.
|
||||
(
|
||||
last_match(2, 4, MatchOutcome::AfterCompletion),
|
||||
"Dernière Partie : Brand, 4ᵉ",
|
||||
),
|
||||
];
|
||||
for (last, expected) in cases {
|
||||
show(
|
||||
&page,
|
||||
cx,
|
||||
banner_statistics(banner_rows(), vec![2, 1], last),
|
||||
);
|
||||
draw(cx);
|
||||
let text = banner(&page, cx);
|
||||
assert_eq!(text.season.as_ref(), "SAISON");
|
||||
assert_eq!(text.title.text.as_ref(), "2 / 5 champions validés");
|
||||
assert_eq!(bold(&text.title), "2");
|
||||
assert_eq!(
|
||||
text.last_completed.text.as_ref(),
|
||||
"Dernier champion validé : Ahri, le 20 nov."
|
||||
);
|
||||
assert_eq!(bold(&text.last_completed), "Ahri");
|
||||
let line = text.last_match.expect("no last Match line");
|
||||
assert_eq!(line.text.as_ref(), expected);
|
||||
let champion = expected["Dernière Partie : ".len()..].split(',').next();
|
||||
assert_eq!(Some(bold(&line)), champion);
|
||||
assert!(cx.debug_bounds("banner-title").is_some());
|
||||
}
|
||||
|
||||
// A Season without a Completed champion nor a Match.
|
||||
let never: Vec<_> = banner_rows()
|
||||
.into_iter()
|
||||
.map(|row| ChampionRow {
|
||||
state: Some(ChampionState::NeverPlayed),
|
||||
challenge: Some(ChampionChallenge::default()),
|
||||
..row
|
||||
})
|
||||
.collect();
|
||||
show(&page, cx, banner_statistics(never, Vec::new(), None));
|
||||
draw(cx);
|
||||
let text = banner(&page, cx);
|
||||
assert_eq!(text.title.text.as_ref(), "0 / 5 champions validés");
|
||||
assert_eq!(
|
||||
text.last_completed.text.as_ref(),
|
||||
"Aucun champion validé pour l’instant."
|
||||
);
|
||||
assert_eq!(text.last_match, None);
|
||||
assert_eq!(text.splash, None);
|
||||
assert!(cx.debug_bounds("banner-title").is_some());
|
||||
assert!(cx.debug_bounds("banner-art").is_none());
|
||||
}
|
||||
|
||||
fn ring_ticks(page: &Entity<Page>, cx: &mut VisualTestContext) -> Vec<(u32, ChampionState)> {
|
||||
page.read_with(cx, |page, cx| {
|
||||
page.ring
|
||||
.read(cx)
|
||||
.ticks()
|
||||
.iter()
|
||||
.map(|tick: &Tick| (tick.id, tick.state))
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
fn ring_renders(page: &Entity<Page>, cx: &mut VisualTestContext) -> usize {
|
||||
page.read_with(cx, |page, cx| page.ring.read(cx).renders)
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_ring_keeps_its_fixed_order_whatever_the_sort(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
show(
|
||||
&page,
|
||||
cx,
|
||||
banner_statistics(banner_rows(), vec![2, 1], None),
|
||||
);
|
||||
draw(cx);
|
||||
let expected = [
|
||||
(2, ChampionState::Completed),
|
||||
(1, ChampionState::Completed),
|
||||
(4, ChampionState::InProgress),
|
||||
(3, ChampionState::InProgress),
|
||||
(5, ChampionState::NeverPlayed),
|
||||
];
|
||||
assert_eq!(ring_ticks(&page, cx), expected);
|
||||
assert!(cx.debug_bounds("ring").is_some());
|
||||
let renders = ring_renders(&page, cx);
|
||||
|
||||
// The cards follow the sort; the ring does not, and is not drawn again.
|
||||
page.update(cx, |page, cx| page.choose_sort(ChampionSort::Name, cx));
|
||||
draw(cx);
|
||||
assert_eq!(ring_ticks(&page, cx), expected);
|
||||
assert_eq!(ring_renders(&page, cx), renders);
|
||||
}
|
||||
|
||||
// The ring is a cached view (rule #1): hovering the grid draws it again only when a tick
|
||||
// lights up or goes out, and builds no card.
|
||||
#[gpui::test]
|
||||
fn hovering_the_grid_draws_the_ring_only_for_the_tick_that_lights_or_goes_out(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(0, 170, champions(170)));
|
||||
draw(cx);
|
||||
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
||||
let set_cards = grid.read_with(cx, |grid, _| grid.set_cards_calls);
|
||||
let renders = ring_renders(&page, cx);
|
||||
assert!(renders > 0);
|
||||
let lit = |cx: &mut VisualTestContext| page.read_with(cx, |p, cx| p.ring.read(cx).lit());
|
||||
let hover = |cx: &mut VisualTestContext, at: gpui_kit::Point<gpui_kit::Pixels>| {
|
||||
cx.simulate_mouse_move(at, None, Modifiers::none());
|
||||
draw(cx);
|
||||
};
|
||||
|
||||
let card = cx.debug_bounds("card-1").unwrap();
|
||||
hover(cx, card.center());
|
||||
assert_eq!(lit(cx), Some(1));
|
||||
assert_eq!(ring_renders(&page, cx), renders + 1);
|
||||
// Elsewhere on the same card: nothing changes.
|
||||
hover(cx, card.center() + point(px(10.), px(10.)));
|
||||
assert_eq!(ring_renders(&page, cx), renders + 1);
|
||||
|
||||
let at = center(cx, "card-2");
|
||||
hover(cx, at);
|
||||
assert_eq!(lit(cx), Some(2));
|
||||
assert_eq!(ring_renders(&page, cx), renders + 2);
|
||||
|
||||
// Off the grid, over a button whose hover draws the page: the tick goes out once.
|
||||
let at = center(cx, "tab-statistics");
|
||||
hover(cx, at);
|
||||
assert_eq!(lit(cx), None);
|
||||
assert_eq!(ring_renders(&page, cx), renders + 3);
|
||||
hover(cx, point(px(5.), px(5.)));
|
||||
let at = center(cx, "tab-statistics");
|
||||
hover(cx, at);
|
||||
assert_eq!(ring_renders(&page, cx), renders + 3);
|
||||
|
||||
// Scrolling moves the cards under a still pointer: the ring is drawn again only when
|
||||
// that changes the lit tick, at most once a frame.
|
||||
let at = center(cx, "card-1");
|
||||
hover(cx, at);
|
||||
assert_eq!(ring_renders(&page, cx), renders + 4);
|
||||
// The grid tells each change of the card under the pointer, and only a change.
|
||||
let changes = Rc::new(Cell::new(0));
|
||||
let _subscription = cx.update(|_, cx| {
|
||||
let changes = changes.clone();
|
||||
cx.subscribe(&grid, move |_, _: &crate::card_grid::CardHovered, _| {
|
||||
changes.set(changes.get() + 1)
|
||||
})
|
||||
});
|
||||
for _ in 0..3 {
|
||||
let (was_changed, was_drawn) = (changes.get(), ring_renders(&page, cx));
|
||||
cx.simulate_event(ScrollEvent {
|
||||
position: at,
|
||||
delta: ScrollDelta::Pixels(point(px(0.), px(-200.))),
|
||||
..Default::default()
|
||||
});
|
||||
draw(cx);
|
||||
assert_eq!(
|
||||
ring_renders(&page, cx) - was_drawn,
|
||||
changes.get() - was_changed
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
changes.get() > 0,
|
||||
"no scroll changed the card under the pointer"
|
||||
);
|
||||
assert!(grid.read_with(cx, |grid, _| grid.scrolled()) > px(0.));
|
||||
|
||||
assert_eq!(
|
||||
grid.read_with(cx, |grid, _| grid.set_cards_calls),
|
||||
set_cards,
|
||||
"the cards were built again"
|
||||
);
|
||||
|
||||
// A grid that is no longer shown has no card under the pointer.
|
||||
hover(cx, point(px(5.), px(5.)));
|
||||
hover(cx, at);
|
||||
assert!(lit(cx).is_some());
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
assert_eq!(lit(cx), None);
|
||||
}
|
||||
|
||||
fn splash(dir: &Path, key: &str) -> Splash {
|
||||
let path = dir.join(format!("{key}.50.30.jpg"));
|
||||
std::fs::write(&path, PORTRAIT_JPEG).unwrap();
|
||||
Splash {
|
||||
path,
|
||||
focus: SplashFocus { x: 50, y: 30 },
|
||||
}
|
||||
}
|
||||
|
||||
/// `banner_rows`, Ahri and Brand with a splash each.
|
||||
fn rows_with_splashes(dir: &Path) -> Vec<ChampionRow> {
|
||||
let mut rows = banner_rows();
|
||||
rows[0].splash = Some(splash(dir, "Ahri"));
|
||||
rows[1].splash = Some(splash(dir, "Brand"));
|
||||
rows
|
||||
}
|
||||
|
||||
fn draw_loaded(cx: &mut VisualTestContext) {
|
||||
draw(cx);
|
||||
cx.run_until_parked();
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
fn held_splashes(page: &Entity<Page>, cx: &mut VisualTestContext) -> Vec<String> {
|
||||
page.read_with(cx, |page, cx| {
|
||||
let held = page.banner_art.read(cx).held();
|
||||
held.iter()
|
||||
.map(|path| path.file_name().unwrap().to_string_lossy().into_owned())
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
fn loaded_splashes(
|
||||
page: &Entity<Page>,
|
||||
cx: &mut VisualTestContext,
|
||||
) -> Vec<Arc<gpui_kit::RenderImage>> {
|
||||
page.read_with(cx, |page, cx| page.banner_art.read(cx).loaded())
|
||||
}
|
||||
|
||||
fn in_atlas(cx: &mut VisualTestContext, image: &gpui_kit::RenderImage) -> bool {
|
||||
cx.update(|window, _| window.has_image_atlas_entry(image))
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_banner_holds_two_splashes_at_most_and_gives_back_the_one_replaced(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let dir = TestDir::new("banner-splashes");
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
// Ahri was Completed last: its splash is the illustration.
|
||||
show(
|
||||
&page,
|
||||
cx,
|
||||
banner_statistics(rows_with_splashes(dir.path()), vec![2, 1], None),
|
||||
);
|
||||
draw_loaded(cx);
|
||||
assert!(cx.debug_bounds("banner-art").is_some());
|
||||
assert_eq!(held_splashes(&page, cx), ["Ahri.50.30.jpg"]);
|
||||
let ahri = loaded_splashes(&page, cx);
|
||||
assert_eq!(ahri.len(), 1, "the splash was not decoded");
|
||||
assert!(in_atlas(cx, &ahri[0]));
|
||||
// Never through the app-wide asset cache, which would keep it.
|
||||
let source = gpui_kit::ImageSource::from(dir.path().join("Ahri.50.30.jpg"));
|
||||
assert!(!cx.update(|_, cx| source.is_asset_cached(cx)));
|
||||
|
||||
// Brand is now the last: Ahri stays shown while Brand decodes, then is given back.
|
||||
show(
|
||||
&page,
|
||||
cx,
|
||||
banner_statistics(rows_with_splashes(dir.path()), vec![1, 2], None),
|
||||
);
|
||||
draw(cx);
|
||||
assert_eq!(
|
||||
held_splashes(&page, cx),
|
||||
["Ahri.50.30.jpg", "Brand.50.30.jpg"]
|
||||
);
|
||||
assert!(loaded_splashes(&page, cx).len() <= 2);
|
||||
cx.run_until_parked();
|
||||
draw(cx);
|
||||
assert_eq!(held_splashes(&page, cx), ["Brand.50.30.jpg"]);
|
||||
let brand = loaded_splashes(&page, cx);
|
||||
assert_eq!(brand.len(), 1);
|
||||
assert!(in_atlas(cx, &brand[0]));
|
||||
assert!(!in_atlas(cx, &ahri[0]));
|
||||
|
||||
// « Statistiques » has no banner: its splash is given back, and comes back with it.
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
draw(cx);
|
||||
assert!(held_splashes(&page, cx).is_empty());
|
||||
assert!(!in_atlas(cx, &brand[0]));
|
||||
switch_tab(&page, cx, Tab::Challenge);
|
||||
draw_loaded(cx);
|
||||
assert_eq!(held_splashes(&page, cx), ["Brand.50.30.jpg"]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_banner_without_splash_has_no_illustration(cx: &mut TestAppContext) {
|
||||
let dir = TestDir::new("banner-no-splash");
|
||||
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),
|
||||
);
|
||||
draw_loaded(cx);
|
||||
assert_eq!(held_splashes(&page, cx).len(), 1);
|
||||
|
||||
// The last Completed champion's splash is not downloaded yet: no illustration, and the
|
||||
// one shown before is given back.
|
||||
let mut rows = rows_with_splashes(dir.path());
|
||||
rows[0].splash = None;
|
||||
show(&page, cx, banner_statistics(rows, vec![2, 1], None));
|
||||
draw(cx);
|
||||
assert!(cx.debug_bounds("banner").is_some());
|
||||
assert!(cx.debug_bounds("banner-title").is_some());
|
||||
assert!(cx.debug_bounds("banner-art").is_none());
|
||||
assert!(held_splashes(&page, cx).is_empty());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn in_a_narrow_window_the_ring_goes_above_the_text_and_the_splash_covers_the_banner(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let dir = TestDir::new("banner-narrow");
|
||||
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),
|
||||
);
|
||||
draw(cx);
|
||||
let bounds = |cx: &mut VisualTestContext| {
|
||||
["banner", "ring", "banner-title", "banner-art"].map(|id| cx.debug_bounds(id).unwrap())
|
||||
};
|
||||
// Wide: the ring beside the text, the splash on the right.
|
||||
let [banner, ring, title, art] = bounds(cx);
|
||||
assert!(ring.right() <= title.left(), "{ring:?} {title:?}");
|
||||
assert!((art.size.width.as_f32() - 0.72 * banner.size.width.as_f32()).abs() < 1.);
|
||||
assert_eq!(art.right(), banner.right());
|
||||
|
||||
cx.simulate_resize(size(px(600.), px(860.)));
|
||||
draw(cx);
|
||||
let [banner, ring, title, art] = bounds(cx);
|
||||
assert!(ring.bottom() <= title.top(), "{ring:?} {title:?}");
|
||||
assert_eq!(art.size.width, banner.size.width);
|
||||
assert_eq!(art.size.height, banner.size.height);
|
||||
}
|
||||
}
|
||||
+352
-70
@@ -1,6 +1,9 @@
|
||||
//! The « Défi » tab, the home: the Challenge of one Season, and its champions.
|
||||
|
||||
use arena_tracker_core::StateFilter;
|
||||
use std::ops::Range;
|
||||
use std::rc::Rc;
|
||||
|
||||
use arena_tracker_core::{MatchOutcome, Splash, StateFilter, Statistics};
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::component::input::Input;
|
||||
use gpui_kit::component::select::Select;
|
||||
@@ -10,7 +13,9 @@ use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use super::{Page, shown};
|
||||
use crate::banner_art::BannerArt;
|
||||
use crate::card_grid::{MAX_WIDTH, row_height};
|
||||
use crate::text::{attempt_ordinal, ordinal, short_date};
|
||||
use crate::theme::{banner_band, gold_ink, heading};
|
||||
|
||||
/// The filters on offer, whatever the Season.
|
||||
@@ -20,7 +25,7 @@ pub(super) const FILTERS: [(&str, StateFilter); 3] = [
|
||||
("Validés", StateFilter::Completed),
|
||||
];
|
||||
|
||||
/// What the header says when there is no current Season, and the champ select's notice for the
|
||||
/// What the banner says when there is no current Season, and the champ select's notice for the
|
||||
/// same cause.
|
||||
pub(super) const NO_SEASON: &str = "Aucune Saison en cours";
|
||||
|
||||
@@ -28,7 +33,7 @@ pub(super) const NO_SEASON: &str = "Aucune Saison en cours";
|
||||
/// way (`label`).
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub(super) enum StatsNotice {
|
||||
/// There is no Season to read: the header already says so.
|
||||
/// There is no Season to read: the banner already says so.
|
||||
NoSeason,
|
||||
/// No Account to read.
|
||||
NoAccount,
|
||||
@@ -79,10 +84,14 @@ fn count_badge(count: SharedString, muted: Hsla, border: Hsla) -> impl IntoEleme
|
||||
}
|
||||
|
||||
impl Page {
|
||||
/// Under the banners: the Season and its counter, then the heading with the filters and
|
||||
/// Under the status messages: the banner, then the heading with the filters and
|
||||
/// search, and the cards. It holds no chart (#71): the cached charts row only belongs to the
|
||||
/// Statistics tab. Everything is one centred column, as wide as the mockup's.
|
||||
pub(super) fn home_content(&self, window: &Window, cx: &mut Context<Page>) -> Vec<AnyElement> {
|
||||
pub(super) fn home_content(
|
||||
&self,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Page>,
|
||||
) -> Vec<AnyElement> {
|
||||
let mut column = div()
|
||||
.v_flex()
|
||||
.flex_1()
|
||||
@@ -91,8 +100,8 @@ impl Page {
|
||||
.max_w(px(MAX_WIDTH))
|
||||
.mx_auto()
|
||||
.gap_3();
|
||||
if shown("home-header") {
|
||||
column = column.child(self.home_header(cx));
|
||||
if shown("banner") {
|
||||
column = column.child(self.banner(window, cx));
|
||||
}
|
||||
if self.in_champ_select() {
|
||||
// The champ select takes the place of the grid, its filters and its search: the
|
||||
@@ -356,76 +365,349 @@ impl Page {
|
||||
)
|
||||
}
|
||||
|
||||
/// The Season, the title and, beside it, the champions Completed out of the Challenge's total.
|
||||
fn home_header(&self, cx: &App) -> impl IntoElement {
|
||||
/// The banner, on the home and during a champ select: the ring, then the Season, the
|
||||
/// Challenge's count and its two lines, over the splash of the last champion Completed. In a
|
||||
/// narrow window the ring goes above the text, and the splash covers the whole banner under a
|
||||
/// stronger fade.
|
||||
fn banner(&self, window: &mut Window, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
let layout = BannerLayout::of(window.viewport_size().width);
|
||||
let theme = cx.theme();
|
||||
let (muted, border, ink, fill) = (
|
||||
let (band, muted, foreground, ink) = (
|
||||
banner_band(theme),
|
||||
theme.muted_foreground,
|
||||
theme.border,
|
||||
theme.foreground,
|
||||
gold_ink(theme),
|
||||
theme.progress_bar,
|
||||
);
|
||||
let counter = match &self.home_season {
|
||||
Some(_) if self.home_count.is_empty() => None,
|
||||
Some(_) => Some(
|
||||
// The line is as wide as the text above it: the block shrinks to its content.
|
||||
div()
|
||||
.v_flex()
|
||||
.flex_shrink_0()
|
||||
.gap(px(5.))
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_1()
|
||||
.whitespace_nowrap()
|
||||
.text_xs()
|
||||
.text_color(muted)
|
||||
.child(heading(cx).text_color(ink).child(self.home_count.clone()))
|
||||
.child("champions validés"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.w_full()
|
||||
.h(px(2.))
|
||||
.bg(border)
|
||||
.child(div().h_full().w(relative(self.home_fraction)).bg(fill)),
|
||||
)
|
||||
.into_any_element(),
|
||||
),
|
||||
None => Some(
|
||||
div()
|
||||
.text_sm()
|
||||
.whitespace_nowrap()
|
||||
.text_color(muted)
|
||||
.debug_selector(|| "no-season".into())
|
||||
.child(NO_SEASON)
|
||||
.into_any_element(),
|
||||
),
|
||||
let text = &self.banner;
|
||||
let art = match &text.splash {
|
||||
Some(splash) => Some(banner_art(&self.banner_art, splash.clone(), layout, band)),
|
||||
None => {
|
||||
// Nothing to show: nothing held.
|
||||
self.banner_art
|
||||
.update(cx, |art, cx| art.release(window, cx));
|
||||
None
|
||||
}
|
||||
};
|
||||
div()
|
||||
let name = |line: &Line| {
|
||||
StyledText::new(line.text.clone()).with_highlights([(
|
||||
line.bold.clone(),
|
||||
HighlightStyle {
|
||||
color: Some(foreground),
|
||||
font_weight: Some(FontWeight::SEMIBOLD),
|
||||
..Default::default()
|
||||
},
|
||||
)])
|
||||
};
|
||||
let copy = div()
|
||||
.v_flex()
|
||||
.bg(banner_band(theme))
|
||||
.p_3()
|
||||
.gap_1()
|
||||
.children(
|
||||
self.home_season
|
||||
.clone()
|
||||
.map(|season| div().text_xs().text_color(muted).child(season)),
|
||||
)
|
||||
.child(
|
||||
.min_w_0()
|
||||
.when(!layout.narrow, |copy| copy.max_w(relative(0.46)))
|
||||
.children((!text.season.is_empty()).then(|| {
|
||||
div()
|
||||
.h_flex()
|
||||
.flex_wrap()
|
||||
.items_center()
|
||||
.justify_between()
|
||||
.gap_x_4()
|
||||
.gap_y_1()
|
||||
.child(heading(cx).text_3xl().child(if self.in_champ_select() {
|
||||
"Sélection des champions"
|
||||
} else {
|
||||
"Défi de saison"
|
||||
}))
|
||||
.children(counter),
|
||||
.text_xs()
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.text_color(ink)
|
||||
.child(text.season.clone())
|
||||
}))
|
||||
.children(match &self.home_season {
|
||||
None => Some(
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(muted)
|
||||
.debug_selector(|| "no-season".into())
|
||||
.child(NO_SEASON)
|
||||
.into_any_element(),
|
||||
),
|
||||
Some(_) if text.title.text.is_empty() => None,
|
||||
Some(_) => Some(
|
||||
div()
|
||||
.v_flex()
|
||||
.gap(px(3.))
|
||||
.child(
|
||||
heading(cx)
|
||||
.mt(px(8.))
|
||||
.mb(px(7.))
|
||||
.text_size(px(layout.title))
|
||||
.line_height(relative(1.12))
|
||||
.debug_selector(|| "banner-title".into())
|
||||
.child(StyledText::new(text.title.text.clone()).with_highlights([
|
||||
(
|
||||
text.title.bold.clone(),
|
||||
HighlightStyle {
|
||||
color: Some(ink),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
])),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(muted)
|
||||
.child(name(&text.last_completed)),
|
||||
)
|
||||
.children(
|
||||
text.last_match
|
||||
.as_ref()
|
||||
.map(|line| div().text_sm().text_color(muted).child(name(line))),
|
||||
)
|
||||
.into_any_element(),
|
||||
),
|
||||
});
|
||||
div()
|
||||
.relative()
|
||||
.flex()
|
||||
.w_full()
|
||||
.flex_shrink_0()
|
||||
.min_h(px(layout.min_height))
|
||||
.rounded(px(RADIUS))
|
||||
.overflow_hidden()
|
||||
.bg(band)
|
||||
.map(|banner| {
|
||||
if layout.narrow {
|
||||
banner.flex_col().items_start()
|
||||
} else {
|
||||
banner.flex_row().items_center()
|
||||
}
|
||||
})
|
||||
.gap(px(layout.gap))
|
||||
.px(px(layout.padding))
|
||||
.py(px(24.))
|
||||
.debug_selector(|| "banner".into())
|
||||
.children(art)
|
||||
.child(
|
||||
// Cached: only a change of its ticks or of the lit one draws it again.
|
||||
self.ring
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().size(px(layout.ring)).flex_none()),
|
||||
)
|
||||
.child(copy)
|
||||
}
|
||||
}
|
||||
|
||||
/// The banner's rounded corners.
|
||||
const RADIUS: f32 = 16.;
|
||||
|
||||
/// The banner's measures, from the window width as the reference page's `clamp` and `vw` give
|
||||
/// them.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
struct BannerLayout {
|
||||
/// At most 680 px: the ring goes above the text.
|
||||
narrow: bool,
|
||||
min_height: f32,
|
||||
gap: f32,
|
||||
padding: f32,
|
||||
ring: f32,
|
||||
title: f32,
|
||||
}
|
||||
|
||||
impl BannerLayout {
|
||||
fn of(window_width: Pixels) -> BannerLayout {
|
||||
let vw = window_width.as_f32() / 100.;
|
||||
BannerLayout {
|
||||
narrow: window_width.as_f32() <= 680.,
|
||||
min_height: (26. * vw).clamp(220., 310.),
|
||||
gap: (3. * vw).clamp(16., 40.),
|
||||
padding: (3. * vw).clamp(16., 36.),
|
||||
ring: (16. * vw).clamp(120., 200.),
|
||||
title: (2.8 * vw).clamp(22., 34.),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The splash, framed on the champion (#83), in the banner's illustration area: its right 72 %,
|
||||
/// or all of it in a narrow window. It fades into the band on the text's side.
|
||||
fn banner_art(
|
||||
art: &Entity<BannerArt>,
|
||||
splash: Rc<Splash>,
|
||||
layout: BannerLayout,
|
||||
band: Hsla,
|
||||
) -> AnyElement {
|
||||
let art = art.clone();
|
||||
let corners = if layout.narrow {
|
||||
Corners::all(px(RADIUS))
|
||||
} else {
|
||||
Corners {
|
||||
top_right: px(RADIUS),
|
||||
bottom_right: px(RADIUS),
|
||||
..Corners::default()
|
||||
}
|
||||
};
|
||||
let image = canvas(
|
||||
|_, _, _| {},
|
||||
move |bounds, _, window, cx| {
|
||||
let Some((image, focus)) = art.update(cx, |art, cx| art.image(&splash, window, cx))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let frame = focus.banner_frame(bounds.size.width.as_f32(), bounds.size.height.as_f32());
|
||||
let frame = Bounds {
|
||||
origin: bounds.origin + point(px(frame.left), px(frame.top)),
|
||||
size: size(px(frame.width), px(frame.height)),
|
||||
};
|
||||
let _ = window.paint_image(bounds, frame, corners, image, 0, false);
|
||||
},
|
||||
)
|
||||
.size_full();
|
||||
let area = div()
|
||||
.absolute()
|
||||
.top_0()
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.debug_selector(|| "banner-art".into())
|
||||
.child(image);
|
||||
// A layer of the band over the splash, from `from` to `to` opacity in the gradient's
|
||||
// direction (`angle`: 0 to the top, 90 to the right, 180 to the bottom).
|
||||
let fade = |angle: f32, (from, at): (f32, f32), to: f32| {
|
||||
div().absolute().bg(linear_gradient(
|
||||
angle,
|
||||
linear_color_stop(band.opacity(from), at),
|
||||
linear_color_stop(band.opacity(to), 1.),
|
||||
))
|
||||
};
|
||||
if layout.narrow {
|
||||
// From the bottom: the band, then a fade to the splash at the top.
|
||||
area.left_0()
|
||||
.child(
|
||||
fade(180., (0., 0.), 0.4)
|
||||
.left_0()
|
||||
.right_0()
|
||||
.top_0()
|
||||
.h(relative(0.25)),
|
||||
)
|
||||
.child(
|
||||
fade(180., (0.4, 0.), 1.)
|
||||
.left_0()
|
||||
.right_0()
|
||||
.top(relative(0.25))
|
||||
.h(relative(0.35)),
|
||||
)
|
||||
.child(
|
||||
fade(180., (1., 0.), 1.)
|
||||
.left_0()
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.h(relative(0.4))
|
||||
.rounded_b(px(RADIUS)),
|
||||
)
|
||||
.into_any_element()
|
||||
} else {
|
||||
// The banner's fade, solid to its 30 %, 72 % at its 46 %, none from its 74 %, in the
|
||||
// area that starts at its 28 %; and a lighter one from the bottom.
|
||||
area.w(relative(0.72))
|
||||
.child(
|
||||
fade(90., (1., 0.11), 0.72)
|
||||
.top_0()
|
||||
.bottom_0()
|
||||
.left_0()
|
||||
.w(relative(0.25)),
|
||||
)
|
||||
.child(
|
||||
fade(90., (0.72, 0.), 0.)
|
||||
.top_0()
|
||||
.bottom_0()
|
||||
.left(relative(0.25))
|
||||
.w(relative(0.39)),
|
||||
)
|
||||
.child(
|
||||
fade(0., (0.55, 0.), 0.)
|
||||
.left_0()
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.h(relative(0.45))
|
||||
.rounded_br(px(RADIUS)),
|
||||
)
|
||||
.into_any_element()
|
||||
}
|
||||
}
|
||||
|
||||
/// A line of the banner, the champion's name (or the count) set apart.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub(super) struct Line {
|
||||
pub(super) text: SharedString,
|
||||
pub(super) bold: Range<usize>,
|
||||
}
|
||||
|
||||
impl Line {
|
||||
/// `before`, then `bold`, then `after`.
|
||||
fn new(before: &str, bold: &str, after: &str) -> Line {
|
||||
Line {
|
||||
text: format!("{before}{bold}{after}").into(),
|
||||
bold: before.len()..before.len() + bold.len(),
|
||||
}
|
||||
}
|
||||
|
||||
fn plain(text: &str) -> Line {
|
||||
Line {
|
||||
text: text.to_owned().into(),
|
||||
bold: 0..0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What the banner shows, prepared when the home statistics change: it follows the home's Season,
|
||||
/// never the Format, the filter nor the search.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub(super) struct BannerContent {
|
||||
/// The Season, as the overline writes it; empty without a Season.
|
||||
pub(super) season: SharedString,
|
||||
/// « N / total champions validés », N set apart; empty without statistics.
|
||||
pub(super) title: Line,
|
||||
/// « Dernier champion validé : X, le 20 nov. »
|
||||
pub(super) last_completed: Line,
|
||||
/// « Dernière Partie : … », from the stored Matches; none without a Match in the Season.
|
||||
pub(super) last_match: Option<Line>,
|
||||
/// The last Completed champion's splash: the illustration. Shared, so drawing the banner
|
||||
/// clones a pointer rather than a path.
|
||||
pub(super) splash: Option<Rc<Splash>>,
|
||||
}
|
||||
|
||||
impl BannerContent {
|
||||
pub(super) fn new(season: Option<&SharedString>, stats: Option<&Statistics>) -> BannerContent {
|
||||
let season = season.map_or_else(SharedString::default, |name| name.to_uppercase().into());
|
||||
let Some((stats, challenge)) = stats.and_then(|s| Some((s, s.challenge.as_ref()?))) else {
|
||||
return BannerContent {
|
||||
season,
|
||||
..BannerContent::default()
|
||||
};
|
||||
};
|
||||
let row = |id: u32| stats.rows.iter().find(|row| row.champion.id == id);
|
||||
let last = challenge.completion_order.last().and_then(|&id| row(id));
|
||||
let last_completed = match last {
|
||||
Some(row) => {
|
||||
let day = row
|
||||
.challenge
|
||||
.and_then(|c| c.completed_on)
|
||||
.map(|day| format!(", le {}", short_date(day)))
|
||||
.unwrap_or_default();
|
||||
Line::new("Dernier champion validé : ", &row.champion.name, &day)
|
||||
}
|
||||
None => Line::plain("Aucun champion validé pour l’instant."),
|
||||
};
|
||||
let last_match = challenge.last_match.and_then(|m| {
|
||||
let name = &row(m.champion_id)?.champion.name;
|
||||
let detail = match m.outcome {
|
||||
MatchOutcome::Attempt(n) => format!(" · {} Tentative", attempt_ordinal(n)),
|
||||
MatchOutcome::Completed(1) => " · validé du premier coup".into(),
|
||||
MatchOutcome::Completed(n) => format!(" · validé en {n} Tentatives"),
|
||||
MatchOutcome::AfterCompletion => String::new(),
|
||||
};
|
||||
Some(Line::new(
|
||||
"Dernière Partie : ",
|
||||
name,
|
||||
&format!(", {}{detail}", ordinal(m.placement)),
|
||||
))
|
||||
});
|
||||
let count = challenge.completed.to_string();
|
||||
BannerContent {
|
||||
season,
|
||||
title: Line {
|
||||
text: format!("{count} / {} champions validés", challenge.total).into(),
|
||||
bold: 0..count.len(),
|
||||
},
|
||||
last_completed,
|
||||
last_match,
|
||||
splash: last.and_then(|row| row.splash.clone()).map(Rc::new),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
//! The ring: the logo enlarged, with one tick per champion of the Challenge around the crown. It
|
||||
//! is a gauge in a fixed order, never the chosen sort: the Completed champions in the order of
|
||||
//! their first top 1, turning from noon, then the played ones, then the never played ones, these
|
||||
//! two by Mastery Points (A to Z while the points are unknown, as the cards).
|
||||
//!
|
||||
//! A cached view (rule #1): laid out from the style its parent gives, drawn again only when its
|
||||
//! ticks or the lit one change, never by a hover or a scroll elsewhere.
|
||||
|
||||
use std::f32::consts::{FRAC_PI_2, TAU};
|
||||
use std::rc::Rc;
|
||||
|
||||
use arena_tracker_core::{ChampionRow, ChampionSort, ChampionState};
|
||||
use gpui_kit::component::ActiveTheme as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::card_order::card_order;
|
||||
use crate::theme::{ring_never, ring_played};
|
||||
|
||||
/// A champion's tick: long and gold when Completed, pale gold when played, short and faint when
|
||||
/// never played.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Tick {
|
||||
pub id: u32,
|
||||
pub state: ChampionState,
|
||||
}
|
||||
|
||||
/// The ticks of `rows` in the ring's order. `completion_order` lists the Completed champions'
|
||||
/// ids by their first top 1; an id the rows do not know is skipped.
|
||||
pub fn ticks(rows: &[ChampionRow], completion_order: &[u32]) -> Vec<Tick> {
|
||||
let completed = completion_order
|
||||
.iter()
|
||||
.filter(|&&id| rows.iter().any(|row| row.champion.id == id))
|
||||
.map(|&id| Tick {
|
||||
id,
|
||||
state: ChampionState::Completed,
|
||||
});
|
||||
let by_mastery = card_order(rows, ChampionSort::Mastery);
|
||||
let of_state = |state: ChampionState| {
|
||||
by_mastery
|
||||
.iter()
|
||||
.map(|&ix| &rows[ix])
|
||||
.filter(move |row| row.state == Some(state))
|
||||
.map(move |row| Tick {
|
||||
id: row.champion.id,
|
||||
state,
|
||||
})
|
||||
};
|
||||
completed
|
||||
.chain(of_state(ChampionState::InProgress))
|
||||
.chain(of_state(ChampionState::NeverPlayed))
|
||||
.collect()
|
||||
}
|
||||
|
||||
// The reference page's geometry, in the units of its SVG: the ring is drawn in a square
|
||||
// `BOX` wide, its centre `PAD + C` from the edges.
|
||||
const C: f32 = 260.;
|
||||
const R1: f32 = 214.;
|
||||
const R2: f32 = 246.;
|
||||
const PAD: f32 = 20.;
|
||||
const BOX: f32 = 2. * (C + PAD);
|
||||
/// The disc under the crown.
|
||||
const DISC: f32 = R1 - 18.;
|
||||
/// The crown of the logo, in its own 256 wide square, placed as the reference page does.
|
||||
const CROWN: [(f32, f32); 7] = [
|
||||
(68., 186.),
|
||||
(52., 86.),
|
||||
(98., 126.),
|
||||
(128., 66.),
|
||||
(158., 126.),
|
||||
(204., 86.),
|
||||
(188., 186.),
|
||||
];
|
||||
const CROWN_SCALE: f32 = 0.64;
|
||||
const CROWN_AT: (f32, f32) = (C - 82., C - 92.);
|
||||
|
||||
/// From and to which radius the tick of a champion in `state` runs, and how wide it is.
|
||||
fn shape(state: ChampionState) -> (f32, f32, f32) {
|
||||
match state {
|
||||
ChampionState::Completed => (R1, R2, 4.),
|
||||
ChampionState::InProgress => (R1 + 10., R2 - 6., 3.),
|
||||
ChampionState::NeverPlayed => (R1 + 18., R1 + 21., 3.),
|
||||
}
|
||||
}
|
||||
|
||||
/// Maps the reference page's units into `bounds`.
|
||||
#[derive(Clone, Copy)]
|
||||
struct Frame {
|
||||
origin: Point<Pixels>,
|
||||
scale: f32,
|
||||
}
|
||||
|
||||
impl Frame {
|
||||
fn of(bounds: Bounds<Pixels>) -> Frame {
|
||||
Frame {
|
||||
origin: bounds.origin,
|
||||
scale: bounds.size.width.min(bounds.size.height).as_f32() / BOX,
|
||||
}
|
||||
}
|
||||
|
||||
fn point(self, x: f32, y: f32) -> Point<Pixels> {
|
||||
self.origin + point(px((x + PAD) * self.scale), px((y + PAD) * self.scale))
|
||||
}
|
||||
|
||||
/// Adds the tick `index` of `count` to `path`: a segment with round ends, as a filled shape.
|
||||
fn add_tick(
|
||||
self,
|
||||
path: &mut PathBuilder,
|
||||
index: usize,
|
||||
count: usize,
|
||||
state: ChampionState,
|
||||
width: f32,
|
||||
) {
|
||||
let angle = -FRAC_PI_2 + (index as f32 + 0.5) * TAU / count as f32;
|
||||
let (from, to, _) = shape(state);
|
||||
let (cos, sin) = (angle.cos(), angle.sin());
|
||||
let half = width / 2.;
|
||||
// Along the tick, and across it.
|
||||
let at = |radius: f32, side: f32| {
|
||||
self.point(C + radius * cos - side * sin, C + radius * sin + side * cos)
|
||||
};
|
||||
let cap = point(px(half * self.scale), px(half * self.scale));
|
||||
path.move_to(at(from, half));
|
||||
path.line_to(at(to, half));
|
||||
path.arc_to(cap, px(0.), false, false, at(to, -half));
|
||||
path.line_to(at(from, -half));
|
||||
path.arc_to(cap, px(0.), false, false, at(from, half));
|
||||
path.close();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Ring {
|
||||
ticks: Rc<[Tick]>,
|
||||
/// The champion whose card is under the pointer.
|
||||
lit: Option<u32>,
|
||||
/// How many times it was drawn: the tests check it stays light.
|
||||
#[cfg(test)]
|
||||
pub(crate) renders: usize,
|
||||
}
|
||||
|
||||
impl Ring {
|
||||
pub fn new() -> Ring {
|
||||
Ring {
|
||||
ticks: Rc::new([]),
|
||||
lit: None,
|
||||
#[cfg(test)]
|
||||
renders: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Replaces the ticks; the ring is drawn again only when they differ.
|
||||
pub fn set_ticks(&mut self, ticks: Rc<[Tick]>, cx: &mut Context<Self>) {
|
||||
if *self.ticks != *ticks {
|
||||
self.ticks = ticks;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// Lights the tick of the card under the pointer, or none.
|
||||
pub fn set_lit(&mut self, lit: Option<u32>, cx: &mut Context<Self>) {
|
||||
if self.lit != lit {
|
||||
self.lit = lit;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn ticks(&self) -> &[Tick] {
|
||||
&self.ticks
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn lit(&self) -> Option<u32> {
|
||||
self.lit
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for Ring {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
#[cfg(test)]
|
||||
{
|
||||
self.renders += 1;
|
||||
}
|
||||
let theme = cx.theme();
|
||||
let colors = [
|
||||
(ChampionState::Completed, theme.primary),
|
||||
(ChampionState::InProgress, ring_played(theme)),
|
||||
(ChampionState::NeverPlayed, ring_never(theme)),
|
||||
];
|
||||
let (disc, crown, lit_color) = (theme.background, theme.primary, theme.foreground);
|
||||
let ticks = self.ticks.clone();
|
||||
let lit = self.lit;
|
||||
div().size_full().debug_selector(|| "ring".into()).child(
|
||||
canvas(
|
||||
|_, _, _| {},
|
||||
move |bounds, _, window, _| {
|
||||
let frame = Frame::of(bounds);
|
||||
let radius = px(DISC * frame.scale);
|
||||
let centre = frame.point(C, C);
|
||||
let disc_bounds = Bounds::centered_at(centre, size(radius * 2., radius * 2.));
|
||||
window.paint_quad(fill(disc_bounds, disc).corner_radii(radius));
|
||||
let count = ticks.len();
|
||||
// One path per kind of tick, the lit one over them.
|
||||
for (state, color) in colors {
|
||||
let width = shape(state).2;
|
||||
let mut path = PathBuilder::fill();
|
||||
let mut any = false;
|
||||
for (index, tick) in ticks.iter().enumerate() {
|
||||
if tick.state == state {
|
||||
frame.add_tick(&mut path, index, count, state, width);
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
if any && let Ok(path) = path.build() {
|
||||
window.paint_path(path, color);
|
||||
}
|
||||
}
|
||||
if let Some((index, tick)) = ticks
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, tick)| Some(tick.id) == lit)
|
||||
{
|
||||
let mut path = PathBuilder::fill();
|
||||
frame.add_tick(&mut path, index, count, tick.state, 7.);
|
||||
if let Ok(path) = path.build() {
|
||||
window.paint_path(path, lit_color);
|
||||
}
|
||||
}
|
||||
let mut path = PathBuilder::fill();
|
||||
let points: Vec<_> = CROWN
|
||||
.iter()
|
||||
.map(|&(x, y)| {
|
||||
frame.point(CROWN_AT.0 + x * CROWN_SCALE, CROWN_AT.1 + y * CROWN_SCALE)
|
||||
})
|
||||
.collect();
|
||||
path.add_polygon(&points, true);
|
||||
if let Ok(path) = path.build() {
|
||||
window.paint_path(path, crown);
|
||||
}
|
||||
},
|
||||
)
|
||||
.size_full(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use arena_tracker_core::{Champion, ChampionRow, ChampionState};
|
||||
|
||||
use super::{Tick, ticks};
|
||||
use crate::champion_table::tests::row;
|
||||
|
||||
fn champion(id: u32, name: &str, state: ChampionState, points: Option<u64>) -> ChampionRow {
|
||||
ChampionRow {
|
||||
champion: Champion {
|
||||
id,
|
||||
..row(name).champion
|
||||
},
|
||||
state: Some(state),
|
||||
mastery_points: points,
|
||||
..row(name)
|
||||
}
|
||||
}
|
||||
|
||||
fn order(ticks: &[Tick]) -> Vec<(u32, ChampionState)> {
|
||||
ticks.iter().map(|tick| (tick.id, tick.state)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completed_by_first_top_1_then_played_then_never_played_by_mastery() {
|
||||
use ChampionState::*;
|
||||
// A to Z, as the statistics give them.
|
||||
let rows = [
|
||||
champion(1, "Ahri", NeverPlayed, Some(10)),
|
||||
champion(2, "Brand", Completed, Some(5)),
|
||||
champion(3, "Garen", InProgress, Some(100)),
|
||||
champion(4, "Jinx", Completed, Some(900)),
|
||||
champion(5, "Lux", InProgress, Some(700)),
|
||||
champion(6, "Zed", NeverPlayed, Some(800)),
|
||||
];
|
||||
assert_eq!(
|
||||
order(&ticks(&rows, &[2, 4])),
|
||||
[
|
||||
(2, Completed),
|
||||
(4, Completed),
|
||||
(5, InProgress),
|
||||
(3, InProgress),
|
||||
(6, NeverPlayed),
|
||||
(1, NeverPlayed),
|
||||
]
|
||||
);
|
||||
// Unknown points: A to Z, as the cards. An id the rows do not know is skipped.
|
||||
let unknown: Vec<_> = rows
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|row| ChampionRow {
|
||||
mastery_points: None,
|
||||
..row
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
order(&ticks(&unknown, &[4, 99, 2])),
|
||||
[
|
||||
(4, Completed),
|
||||
(2, Completed),
|
||||
(3, InProgress),
|
||||
(5, InProgress),
|
||||
(1, NeverPlayed),
|
||||
(6, NeverPlayed),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
+37
-1
@@ -1,6 +1,6 @@
|
||||
//! French display helpers shared by the page and the table.
|
||||
|
||||
use arena_tracker_core::{ChampionState, SyncProgress};
|
||||
use arena_tracker_core::{ChampionState, Date, SyncProgress};
|
||||
|
||||
/// Fixed decimals with a decimal comma: `1,96`.
|
||||
pub fn decimal(value: f64, digits: usize) -> String {
|
||||
@@ -38,6 +38,27 @@ pub fn ordinal(placement: u8) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// An Attempt's rank, feminine: « 1ʳᵉ », « 2ᵉ »…
|
||||
pub fn attempt_ordinal(attempt: usize) -> String {
|
||||
match attempt {
|
||||
1 => "1ʳᵉ".into(),
|
||||
n => format!("{n}ᵉ"),
|
||||
}
|
||||
}
|
||||
|
||||
/// A day as the banner writes it: « 20 nov. », « 3 mai ».
|
||||
pub fn short_date(date: Date) -> String {
|
||||
const MONTHS: [&str; 12] = [
|
||||
"janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.",
|
||||
"déc.",
|
||||
];
|
||||
let month = MONTHS
|
||||
.get(usize::from(date.month).wrapping_sub(1))
|
||||
.copied()
|
||||
.unwrap_or_default();
|
||||
format!("{} {month}", date.day)
|
||||
}
|
||||
|
||||
pub fn state_label(state: Option<ChampionState>) -> &'static str {
|
||||
match state {
|
||||
Some(ChampionState::Completed) => "Validé",
|
||||
@@ -105,6 +126,21 @@ mod tests {
|
||||
assert_eq!(ordinal(1), "1ᵉʳ");
|
||||
assert_eq!(ordinal(2), "2ᵉ");
|
||||
assert_eq!(ordinal(8), "8ᵉ");
|
||||
assert_eq!(attempt_ordinal(1), "1ʳᵉ");
|
||||
assert_eq!(attempt_ordinal(3), "3ᵉ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn short_dates_have_the_french_month_abbreviations() {
|
||||
let date = |month, day| Date {
|
||||
year: 2026,
|
||||
month,
|
||||
day,
|
||||
};
|
||||
assert_eq!(short_date(date(11, 20)), "20 nov.");
|
||||
assert_eq!(short_date(date(2, 1)), "1 févr.");
|
||||
assert_eq!(short_date(date(5, 3)), "3 mai");
|
||||
assert_eq!(short_date(date(8, 31)), "31 août");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -30,6 +30,20 @@ pub fn gold_ink(theme: &Theme) -> Hsla {
|
||||
theme.link
|
||||
}
|
||||
|
||||
/// The pale gold of a played champion's tick on the ring.
|
||||
pub fn ring_played(theme: &Theme) -> Hsla {
|
||||
if theme.mode.is_dark() {
|
||||
Hsla::from(rgb(LOGO_GOLD)).opacity(0.34)
|
||||
} else {
|
||||
Hsla::from(rgb(0xd4920e)).opacity(0.4)
|
||||
}
|
||||
}
|
||||
|
||||
/// The faint tick of a never played champion.
|
||||
pub fn ring_never(theme: &Theme) -> Hsla {
|
||||
theme.switch
|
||||
}
|
||||
|
||||
struct HeadingFamily(SharedString);
|
||||
impl Global for HeadingFamily {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user