Show the Arena champ select in the banner (#85)
CI / core (pull_request) Successful in 1m35s
CI / core (pull_request) Successful in 1m35s
This commit is contained in:
1 parent
411d139a75
commit
d74da1bee1
6 files changed
+540
-211
No files matched your search
@@ -10,13 +10,18 @@
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use arena_tracker_core::{Splash, SplashFocus};
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::worker::BelowNormal;
|
||||
|
||||
const FADE: Duration = Duration::from_millis(500);
|
||||
|
||||
pub struct BannerArt {
|
||||
pub(crate) target: Option<Rc<Splash>>,
|
||||
previous: Option<(Rc<Splash>, Arc<RenderImage>, Instant)>,
|
||||
/// The splash shown, and its image; none when it could not be read.
|
||||
shown: Option<(Rc<Splash>, Option<Arc<RenderImage>>)>,
|
||||
/// The decode running, of which splash.
|
||||
@@ -32,6 +37,8 @@ pub struct BannerArt {
|
||||
impl BannerArt {
|
||||
pub fn new(cx: &mut App) -> Entity<BannerArt> {
|
||||
let art = cx.new(|_| BannerArt {
|
||||
target: None,
|
||||
previous: None,
|
||||
shown: None,
|
||||
decoding: None,
|
||||
wanted: None,
|
||||
@@ -39,11 +46,50 @@ impl BannerArt {
|
||||
loads: 0,
|
||||
});
|
||||
// The page is gone: so is the splash, from every window's atlas too.
|
||||
cx.observe_release(&art, |art, cx| art.drop_shown(None, cx))
|
||||
.detach();
|
||||
cx.observe_release(&art, |art, cx| {
|
||||
art.drop_previous(None, cx);
|
||||
art.drop_shown(None, cx);
|
||||
})
|
||||
.detach();
|
||||
art
|
||||
}
|
||||
|
||||
pub fn set_target(&mut self, target: Option<Rc<Splash>>, cx: &mut Context<Self>) {
|
||||
if self.target != target {
|
||||
self.target = target;
|
||||
self.wanted = None;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// The outgoing image is painted over the new one with decreasing opacity.
|
||||
pub(crate) fn previous_opacity(
|
||||
&mut self,
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<f32> {
|
||||
let (_, _, start) = self.previous.as_ref()?;
|
||||
let elapsed = cx.background_executor().now().duration_since(*start);
|
||||
if elapsed >= FADE || cx.reduce_motion() {
|
||||
self.drop_previous(Some(window), cx);
|
||||
return None;
|
||||
}
|
||||
window.request_animation_frame();
|
||||
Some(1. - elapsed.as_secs_f32() / FADE.as_secs_f32())
|
||||
}
|
||||
|
||||
pub(crate) fn previous_image(&self) -> Option<(Arc<RenderImage>, SplashFocus)> {
|
||||
self.previous
|
||||
.as_ref()
|
||||
.map(|(splash, image, _)| (image.clone(), splash.focus))
|
||||
}
|
||||
|
||||
fn drop_previous(&mut self, window: Option<&mut Window>, cx: &mut App) {
|
||||
if let Some((_, image, _)) = self.previous.take() {
|
||||
cx.drop_image(image, window);
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 art notifies when it changes. A
|
||||
/// splash that cannot be read shows nothing.
|
||||
@@ -59,7 +105,7 @@ impl BannerArt {
|
||||
.shown
|
||||
.as_ref()
|
||||
.is_some_and(|(shown, _)| shown == splash);
|
||||
if !shown_wanted && self.decoding.is_none() {
|
||||
if !shown_wanted && self.decoding.is_none() && self.previous.is_none() {
|
||||
self.decode(splash.clone(), cx);
|
||||
}
|
||||
let (shown, image) = self.shown.as_ref()?;
|
||||
@@ -89,7 +135,15 @@ impl BannerArt {
|
||||
return;
|
||||
};
|
||||
if self.wanted.as_ref() == Some(&splash) {
|
||||
self.drop_shown(None, cx);
|
||||
if image.is_some()
|
||||
&& !cx.reduce_motion()
|
||||
&& animations_enabled()
|
||||
&& let Some((old, Some(previous))) = self.shown.take()
|
||||
{
|
||||
self.previous = Some((old, previous, cx.background_executor().now()));
|
||||
} else {
|
||||
self.drop_shown(None, cx);
|
||||
}
|
||||
self.shown = Some((splash, image));
|
||||
cx.notify();
|
||||
} else if let Some(wanted) = self.wanted.clone()
|
||||
@@ -98,6 +152,7 @@ impl BannerArt {
|
||||
.as_ref()
|
||||
.is_none_or(|(shown, _)| *shown != wanted)
|
||||
{
|
||||
drop(image);
|
||||
self.decode(wanted, cx);
|
||||
}
|
||||
}
|
||||
@@ -113,6 +168,7 @@ impl BannerArt {
|
||||
/// has no illustration. A decode running ends unused.
|
||||
pub fn release(&mut self, window: &mut Window, cx: &mut App) {
|
||||
self.wanted = None;
|
||||
self.drop_previous(Some(window), cx);
|
||||
self.drop_shown(Some(window), cx);
|
||||
}
|
||||
|
||||
@@ -121,11 +177,15 @@ impl BannerArt {
|
||||
pub(crate) fn held(&self) -> Vec<std::path::PathBuf> {
|
||||
let shown = self.shown.as_ref().map(|(splash, _)| splash);
|
||||
let decoding = self.decoding.as_ref().map(|(splash, _)| splash);
|
||||
[shown, decoding]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|splash| splash.path.clone())
|
||||
.collect()
|
||||
[
|
||||
self.previous.as_ref().map(|(splash, _, _)| splash),
|
||||
shown,
|
||||
decoding,
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|splash| splash.path.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The splash decoded and shown.
|
||||
@@ -134,6 +194,7 @@ impl BannerArt {
|
||||
self.shown
|
||||
.iter()
|
||||
.filter_map(|(_, image)| image.clone())
|
||||
.chain(self.previous.iter().map(|(_, image, _)| image.clone()))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@@ -151,3 +212,27 @@ fn decode(path: &Path) -> Option<Arc<RenderImage>> {
|
||||
}
|
||||
Some(Arc::new(RenderImage::new(vec![image::Frame::new(pixels)])))
|
||||
}
|
||||
|
||||
#[cfg(all(windows, not(test)))]
|
||||
fn animations_enabled() -> bool {
|
||||
use windows::Win32::UI::WindowsAndMessaging::{
|
||||
SPI_GETCLIENTAREAANIMATION, SystemParametersInfoW,
|
||||
};
|
||||
let mut enabled = windows::core::BOOL::default();
|
||||
// SPI_GETCLIENTAREAANIMATION writes one BOOL to the supplied pointer.
|
||||
unsafe {
|
||||
SystemParametersInfoW(
|
||||
SPI_GETCLIENTAREAANIMATION,
|
||||
0,
|
||||
Some((&raw mut enabled).cast()),
|
||||
Default::default(),
|
||||
)
|
||||
.is_ok()
|
||||
&& enabled.as_bool()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(not(windows), test))]
|
||||
fn animations_enabled() -> bool {
|
||||
true
|
||||
}
|
||||
@@ -149,7 +149,7 @@ impl CardGrid {
|
||||
}
|
||||
|
||||
/// A grid that is as tall as its rows and builds them all. It has the home grid's cards and
|
||||
/// metrics, and is not meant to be a cached view: its height depends on its content.
|
||||
/// metrics. The parent uses the same row height to lay out the cached hand.
|
||||
pub fn fit_content() -> CardGrid {
|
||||
CardGrid {
|
||||
fit_content: true,
|
||||
@@ -157,6 +157,12 @@ impl CardGrid {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hand_height(&self, window_width: Pixels) -> Option<Pixels> {
|
||||
let metrics = Metrics::of(window_width);
|
||||
let rows = self.shown.len().div_ceil(metrics.columns);
|
||||
(rows > 0).then(|| px(metrics.row_height() * rows as f32))
|
||||
}
|
||||
|
||||
/// Replaces the cards; the grid is drawn again only when they differ (reloads keep coming
|
||||
/// during an import). `set_shown` follows, as the indices belong to the cards.
|
||||
pub fn set_cards(&mut self, cards: Rc<[Card]>, cx: &mut Context<Self>) {
|
||||
|
||||
+159
-16
@@ -2,6 +2,7 @@
|
||||
//! banners. `home` (which also holds the champ select's sections) and `statistics` render what
|
||||
//! is under the banners.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
@@ -177,6 +178,7 @@ pub struct Page {
|
||||
home_computed: Option<(String, Scope)>,
|
||||
/// What the banner shows, prepared when the statistics change.
|
||||
banner: home::BannerContent,
|
||||
champ_select_splashes: HashMap<u32, Rc<arena_tracker_core::Splash>>,
|
||||
/// The banner's ring: a cached view.
|
||||
ring: Entity<Ring>,
|
||||
/// The grid whose card lit the ring's tick.
|
||||
@@ -293,8 +295,6 @@ impl Page {
|
||||
let subscriptions = vec![
|
||||
Self::light_on_hover(&home_grid, cx),
|
||||
Self::light_on_hover(&anvil_grid, cx),
|
||||
// A splash decoded: the banner shows it.
|
||||
cx.observe(&banner_art, |_, _, cx| cx.notify()),
|
||||
cx.subscribe(&search_input, |this, input, event: &InputEvent, cx| {
|
||||
if matches!(event, InputEvent::Change) {
|
||||
this.search = ChampionSearch::new(&input.read(cx).value());
|
||||
@@ -420,6 +420,7 @@ impl Page {
|
||||
home_error: None,
|
||||
home_computed: None,
|
||||
banner: home::BannerContent::default(),
|
||||
champ_select_splashes: HashMap::new(),
|
||||
ring,
|
||||
lit_by: None,
|
||||
banner_art,
|
||||
@@ -995,7 +996,13 @@ impl Page {
|
||||
/// 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 champ_select = self.in_champ_select();
|
||||
let splashes = stats
|
||||
.filter(|_| champ_select)
|
||||
.into_iter()
|
||||
.flat_map(|s| &s.rows)
|
||||
.filter_map(|row| Some((row.champion.id, Rc::new(row.splash.clone()?))))
|
||||
.collect();
|
||||
let ticks: Rc<[Tick]> = stats
|
||||
.and_then(|s| {
|
||||
Some(ring::ticks(
|
||||
@@ -1005,7 +1012,12 @@ impl Page {
|
||||
})
|
||||
.unwrap_or_default()
|
||||
.into();
|
||||
self.banner = banner;
|
||||
if !champ_select {
|
||||
self.banner = home::BannerContent::new(self.home_season.as_ref(), stats);
|
||||
self.banner_art
|
||||
.update(cx, |art, cx| art.set_target(self.banner.splash.clone(), cx));
|
||||
}
|
||||
self.champ_select_splashes = splashes;
|
||||
self.ring.update(cx, |ring, cx| ring.set_ticks(ticks, cx));
|
||||
}
|
||||
|
||||
@@ -1026,6 +1038,18 @@ impl Page {
|
||||
None => return,
|
||||
}
|
||||
self.ring.update(cx, |ring, cx| ring.set_lit(id, cx));
|
||||
if self.in_champ_select() {
|
||||
self.select_art(id, cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn select_art(&self, hovered: Option<u32>, cx: &mut Context<Self>) {
|
||||
let splash = match hovered {
|
||||
Some(id) => self.champ_select_splashes.get(&id),
|
||||
None => self.banner.splash.as_ref(),
|
||||
};
|
||||
self.banner_art
|
||||
.update(cx, |art, cx| art.set_target(splash.cloned(), cx));
|
||||
}
|
||||
|
||||
/// A new grid for « Autres champions », whose hover lights the ring as the others do. The
|
||||
@@ -1104,14 +1128,30 @@ impl Page {
|
||||
// The same rows in the same order as the home grid (`ordered_rows`): the
|
||||
// cards keep their place whatever the champ select does. An id the rows do not know is
|
||||
// skipped.
|
||||
let anvil = self
|
||||
.live_champ_select()
|
||||
.and_then(|pick| pick.anvil_champions.as_deref())
|
||||
.unwrap_or_default();
|
||||
let champ_select = self.live_champ_select();
|
||||
let anvil = champ_select.and_then(|pick| pick.anvil_champions.as_deref());
|
||||
let ids = anvil.unwrap_or_default();
|
||||
let cards = self.champ_select_cards(
|
||||
self.ordered_rows()
|
||||
.filter(|row| anvil.contains(&row.champion.id)),
|
||||
.filter(|row| ids.contains(&row.champion.id)),
|
||||
);
|
||||
self.ring
|
||||
.update(cx, |ring, cx| ring.set_anvil(champ_select.map(|_| ids), cx));
|
||||
if champ_select.is_some() {
|
||||
let remaining_pickable = cards.iter().filter(|card| !card.greyed());
|
||||
let first = remaining_pickable.clone().next().or_else(|| cards.first());
|
||||
let splash = first
|
||||
.and_then(|card| self.champ_select_splashes.get(&card.id))
|
||||
.cloned();
|
||||
self.banner = home::BannerContent::champ_select(
|
||||
self.home_season.as_ref(),
|
||||
self.home_statistics(),
|
||||
anvil.is_some(),
|
||||
remaining_pickable.count(),
|
||||
splash,
|
||||
);
|
||||
self.select_art(self.ring.read(cx).lit(), cx);
|
||||
}
|
||||
self.anvil_count = cards.len().to_string().into();
|
||||
let shown = (0..cards.len()).collect();
|
||||
self.anvil_grid.update(cx, |grid, cx| {
|
||||
@@ -2896,6 +2936,38 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_champ_select_banner_follows_the_arena_capture(cx: &mut TestAppContext) {
|
||||
let mut picks = frames();
|
||||
// Put the capture's banned Alistar and the ally's Morgana in the hand.
|
||||
for pick in &mut picks {
|
||||
pick.anvil_champions = Some(vec![12, 16, 25, 233]);
|
||||
}
|
||||
let (page, mut window) = page_in_champ_select(cx, &picks[0]).await;
|
||||
page.update(&mut window, |p, cx| {
|
||||
p.home_season = Some("Saison 2 2026".into());
|
||||
p.prepare_champ_select(cx);
|
||||
});
|
||||
for (pick, available) in picks.iter().zip([3, 2, 2, 1, 1]) {
|
||||
send(&page, &mut window, pick);
|
||||
let text = banner(&page, &mut window);
|
||||
assert_eq!(text.season.as_ref(), "SAISON 2 · 2026 · 1 / 9 validés");
|
||||
assert_eq!(text.title.text.as_ref(), "Sélection des champions");
|
||||
assert_eq!(
|
||||
text.detail.text.as_ref(),
|
||||
format!("Champions de l’Enclume · {available} à valider et disponibles")
|
||||
);
|
||||
assert!(text.last_match.is_none());
|
||||
}
|
||||
let mut unknown = picks[4].clone();
|
||||
unknown.anvil_champions = None;
|
||||
send(&page, &mut window, &unknown);
|
||||
assert_eq!(
|
||||
banner(&page, &mut window).detail.text.as_ref(),
|
||||
"Champions de l'Enclume non communiqués par le client"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_arena_capture_fills_the_anvil_row_in_the_homes_order(cx: &mut TestAppContext) {
|
||||
cx.executor().allow_parking();
|
||||
@@ -3010,7 +3082,8 @@ 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.banner.title.text.as_ref(), "1 / 9 champions validés");
|
||||
assert_eq!(p.banner.season.as_ref(), "SAISON · 1 / 9 validés");
|
||||
assert_eq!(p.banner.title.text.as_ref(), "Sélection des champions");
|
||||
assert!(p.stats.as_ref().unwrap().challenge.is_some());
|
||||
});
|
||||
// The row is there; the grid, its filters and its search are not.
|
||||
@@ -3087,7 +3160,10 @@ mod tests {
|
||||
});
|
||||
// No row, and no champion is presented as without an anvil.
|
||||
assert!(anvil_cards(&page, &mut window).is_empty());
|
||||
assert!(window.debug_bounds("anvil-notice").is_some());
|
||||
assert_eq!(
|
||||
window.debug_bounds("anvil-notice").is_some(),
|
||||
anvil.is_some()
|
||||
);
|
||||
assert!(window.debug_bounds("anvil-row").is_none());
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
assert!(window.debug_bounds("card-16").is_none());
|
||||
@@ -4303,10 +4379,10 @@ mod tests {
|
||||
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(),
|
||||
text.detail.text.as_ref(),
|
||||
"Dernier champion validé : Ahri, le 20 nov."
|
||||
);
|
||||
assert_eq!(bold(&text.last_completed), "Ahri");
|
||||
assert_eq!(bold(&text.detail), "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();
|
||||
@@ -4328,7 +4404,7 @@ mod tests {
|
||||
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(),
|
||||
text.detail.text.as_ref(),
|
||||
"Aucun champion validé pour l’instant."
|
||||
);
|
||||
assert_eq!(text.last_match, None);
|
||||
@@ -4549,6 +4625,13 @@ mod tests {
|
||||
assert!(loaded_splashes(&page, cx).len() <= 2);
|
||||
cx.run_until_parked();
|
||||
draw(cx);
|
||||
assert_eq!(loaded_splashes(&page, cx).len(), 2);
|
||||
assert!(in_atlas(cx, &ahri[0]));
|
||||
cx.update(|_, cx| {
|
||||
cx.background_executor()
|
||||
.advance_clock(std::time::Duration::from_millis(501))
|
||||
});
|
||||
draw(cx);
|
||||
assert_eq!(held_splashes(&page, cx), ["Brand.50.30.jpg"]);
|
||||
let brand = loaded_splashes(&page, cx);
|
||||
assert_eq!(brand.len(), 1);
|
||||
@@ -4657,6 +4740,7 @@ mod tests {
|
||||
|
||||
#[gpui::test]
|
||||
fn a_splash_asked_for_while_another_decodes_waits_for_it(cx: &mut TestAppContext) {
|
||||
cx.update(|cx| cx.set_reduce_motion(true));
|
||||
let dir = TestDir::new("banner-queue");
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
@@ -4799,13 +4883,14 @@ mod tests {
|
||||
|
||||
send(&page, &mut window, &frames()[0]);
|
||||
let text = banner(&page, &mut window);
|
||||
assert!(text.title.text.is_empty(), "{:?}", text.title);
|
||||
assert_eq!(text.title.text.as_ref(), "Sélection des champions");
|
||||
assert!(!text.season.contains('/'));
|
||||
assert_eq!(text.splash, None);
|
||||
assert!(ring_ticks(&page, &mut window).is_empty());
|
||||
|
||||
// Its own statistics arrive.
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
assert!(!banner(&page, &mut window).title.text.is_empty());
|
||||
assert!(banner(&page, &mut window).season.contains("1 / 9"));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
@@ -4860,6 +4945,64 @@ mod tests {
|
||||
assert_eq!(held_splashes(&page, cx), ["Ahri.50.30.jpg"]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_champ_select_splash_follows_the_hand_and_other_champions(cx: &mut TestAppContext) {
|
||||
let dir = TestDir::new("champ-select-splashes");
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
let cx = &mut window;
|
||||
let mut stats = page.read_with(cx, |p, _| p.home_statistics().unwrap().clone());
|
||||
for row in &mut stats.rows {
|
||||
row.splash = Some(splash(dir.path(), &row.champion.key));
|
||||
}
|
||||
show(&page, cx, stats);
|
||||
cx.simulate_resize(size(px(1280.), px(1300.)));
|
||||
draw_loaded(cx);
|
||||
assert_eq!(held_splashes(&page, cx), ["Briar.50.30.jpg"]);
|
||||
click_others(cx);
|
||||
let hover = |cx: &mut VisualTestContext, card| {
|
||||
let at = center(cx, card);
|
||||
cx.simulate_mouse_move(at, None, Modifiers::none());
|
||||
draw_loaded(cx);
|
||||
};
|
||||
let finish_fade = |cx: &mut VisualTestContext| {
|
||||
cx.update(|_, cx| {
|
||||
cx.background_executor()
|
||||
.advance_clock(std::time::Duration::from_millis(501))
|
||||
});
|
||||
draw_loaded(cx);
|
||||
};
|
||||
// The first hover starts a fade. Crossing the rest of the hand leaves
|
||||
// those two images intact until it ends, even over an Other champion.
|
||||
for card in ANVIL_CARDS[1..].iter().copied().chain(["card-103"]) {
|
||||
hover(cx, card);
|
||||
assert_eq!(
|
||||
held_splashes(&page, cx),
|
||||
["Briar.50.30.jpg", "LeeSin.50.30.jpg"]
|
||||
);
|
||||
}
|
||||
let builds = page.read_with(cx, |p, cx| p.anvil_grid.read(cx).card_builds);
|
||||
finish_fade(cx);
|
||||
assert_eq!(
|
||||
held_splashes(&page, cx),
|
||||
["LeeSin.50.30.jpg", "Ahri.50.30.jpg"]
|
||||
);
|
||||
finish_fade(cx);
|
||||
assert_eq!(held_splashes(&page, cx), ["Ahri.50.30.jpg"]);
|
||||
assert_eq!(
|
||||
page.read_with(cx, |p, cx| p.anvil_grid.read(cx).card_builds),
|
||||
builds
|
||||
);
|
||||
hover(cx, "banner-title");
|
||||
finish_fade(cx);
|
||||
assert_eq!(held_splashes(&page, cx), ["Briar.50.30.jpg"]);
|
||||
// With every card grey, the first card in the chosen sort supplies the art.
|
||||
let mut pick = with_bans_and_ally(&[233], 233);
|
||||
pick.anvil_champions = Some(vec![16, 64]);
|
||||
send(&page, cx, &pick);
|
||||
draw_loaded(cx);
|
||||
assert_eq!(held_splashes(&page, cx).last().unwrap(), "LeeSin.50.30.jpg");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_tick_stays_with_the_grid_that_lit_it(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
|
||||
+228
-174
@@ -25,8 +25,7 @@ pub(super) const FILTERS: [(&str, StateFilter); 3] = [
|
||||
("Validés", StateFilter::Completed),
|
||||
];
|
||||
|
||||
/// What the banner says when there is no current Season, and the champ select's notice for the
|
||||
/// same cause.
|
||||
const UNKNOWN_ANVIL: &str = "Champions de l'Enclume non communiqués par le client";
|
||||
pub(super) const NO_SEASON: &str = "Aucune Saison en cours";
|
||||
|
||||
/// Why the home has no statistics to browse yet. The home and the champ select say it the same
|
||||
@@ -108,7 +107,7 @@ impl Page {
|
||||
// column may be taller than the window, and scrolls then. « Autres champions »
|
||||
// takes what is left of the height, and scrolls by itself while open.
|
||||
if shown("anvil") {
|
||||
column = column.child(self.anvil_area(cx));
|
||||
column = column.child(self.anvil_area(window.viewport_size().width, cx));
|
||||
}
|
||||
// With the statistics missing there is nothing to browse: the notice stands alone.
|
||||
if shown("others") && self.stats_notice().is_none() {
|
||||
@@ -183,7 +182,7 @@ impl Page {
|
||||
return Some(notice.label(self.error().map(String::as_str)));
|
||||
}
|
||||
match &self.live_champ_select()?.anvil_champions {
|
||||
None => Some("Champions de l'Enclume non communiqués par le client".into()),
|
||||
None => Some(UNKNOWN_ANVIL.into()),
|
||||
Some(ids) if ids.is_empty() => {
|
||||
Some("Aucun Champion de l'Enclume dans cette sélection".into())
|
||||
}
|
||||
@@ -192,11 +191,12 @@ impl Page {
|
||||
}
|
||||
|
||||
/// « Champions de l'Enclume » with how many there are, and the row of their cards.
|
||||
fn anvil_area(&self, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
fn anvil_area(&self, window_width: Pixels, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (muted, border) = (theme.muted_foreground, theme.border);
|
||||
let row = self.anvil_line();
|
||||
let said_elsewhere = self.stats_notice().is_some_and(StatsNotice::said_elsewhere);
|
||||
let said_elsewhere = self.stats_notice().is_some_and(StatsNotice::said_elsewhere)
|
||||
|| row.as_deref() == Some(UNKNOWN_ANVIL);
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_3()
|
||||
@@ -229,7 +229,14 @@ impl Page {
|
||||
div()
|
||||
.w_full()
|
||||
.debug_selector(|| "anvil-row".into())
|
||||
.child(self.anvil_grid.clone())
|
||||
.child(match self.anvil_grid.read(cx).hand_height(window_width) {
|
||||
Some(height) => self
|
||||
.anvil_grid
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().w_full().h(height))
|
||||
.into_any_element(),
|
||||
None => self.anvil_grid.clone().into_any_element(),
|
||||
})
|
||||
.into_any_element(),
|
||||
),
|
||||
})
|
||||
@@ -381,15 +388,6 @@ impl Page {
|
||||
gold_ink(theme),
|
||||
);
|
||||
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
|
||||
}
|
||||
};
|
||||
let name = |line: &Line| {
|
||||
StyledText::new(line.text.clone()).with_highlights([(
|
||||
line.bold.clone(),
|
||||
@@ -411,51 +409,41 @@ impl Page {
|
||||
.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(),
|
||||
),
|
||||
});
|
||||
.children(self.home_season.is_none().then(|| {
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(muted)
|
||||
.debug_selector(|| "no-season".into())
|
||||
.child(NO_SEASON)
|
||||
.into_any_element()
|
||||
}))
|
||||
.children((!text.title.text.is_empty()).then(|| {
|
||||
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.detail)))
|
||||
.children(
|
||||
text.last_match
|
||||
.as_ref()
|
||||
.map(|line| div().text_sm().text_color(muted).child(name(line))),
|
||||
)
|
||||
.into_any_element()
|
||||
}));
|
||||
div()
|
||||
.relative()
|
||||
.flex()
|
||||
@@ -476,7 +464,7 @@ impl Page {
|
||||
.px(px(layout.padding))
|
||||
.py(px(24.))
|
||||
.debug_selector(|| "banner".into())
|
||||
.children(art)
|
||||
.child(self.banner_art.clone())
|
||||
.child(
|
||||
// Cached: only a change of its ticks or of the lit one draws it again.
|
||||
self.ring
|
||||
@@ -519,113 +507,133 @@ impl BannerLayout {
|
||||
|
||||
/// 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| {
|
||||
// Scrolled entirely out of the column (a low window): nothing to show, so nothing
|
||||
// decoded nor held, and it comes back with the banner.
|
||||
let visible = bounds.intersect(&window.content_mask().bounds);
|
||||
if visible.size.width <= Pixels::ZERO || visible.size.height <= Pixels::ZERO {
|
||||
art.update(cx, |art, cx| art.release(window, cx));
|
||||
return;
|
||||
impl Render for BannerArt {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let Some(splash) = self.target.clone() else {
|
||||
self.release(window, cx);
|
||||
return div().absolute().into_any_element();
|
||||
};
|
||||
let layout = BannerLayout::of(window.viewport_size().width);
|
||||
let band = banner_band(cx.theme());
|
||||
let art = cx.entity();
|
||||
let corners = if layout.narrow {
|
||||
Corners::all(px(RADIUS))
|
||||
} else {
|
||||
Corners {
|
||||
top_right: px(RADIUS),
|
||||
bottom_right: px(RADIUS),
|
||||
..Corners::default()
|
||||
}
|
||||
let Some((image, focus)) = art.update(cx, |art, cx| art.image(&splash, 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)),
|
||||
};
|
||||
let layer = |previous: bool| {
|
||||
let art = art.clone();
|
||||
let splash = splash.clone();
|
||||
canvas(
|
||||
|_, _, _| {},
|
||||
move |bounds, _, window, cx| {
|
||||
// Scrolled entirely out of the column (a low window): nothing to show, so nothing
|
||||
// decoded nor held, and it comes back with the banner.
|
||||
let visible = bounds.intersect(&window.content_mask().bounds);
|
||||
if visible.size.width <= Pixels::ZERO || visible.size.height <= Pixels::ZERO {
|
||||
art.update(cx, |art, cx| art.release(window, cx));
|
||||
return;
|
||||
}
|
||||
let image = if previous {
|
||||
art.read(cx).previous_image()
|
||||
} else {
|
||||
art.update(cx, |art, cx| art.image(&splash, cx))
|
||||
};
|
||||
let Some((image, focus)) = image 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);
|
||||
},
|
||||
)
|
||||
.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()
|
||||
.size_full()
|
||||
};
|
||||
let area = div()
|
||||
.absolute()
|
||||
.top_0()
|
||||
.right_0()
|
||||
.bottom_0()
|
||||
.debug_selector(|| "banner-art".into())
|
||||
.child(layer(false))
|
||||
.children(self.previous_opacity(window, cx).map(|opacity| {
|
||||
div()
|
||||
.absolute()
|
||||
.inset_0()
|
||||
.opacity(opacity)
|
||||
.child(layer(true))
|
||||
}));
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,18 +667,64 @@ impl Line {
|
||||
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.
|
||||
/// The home counter or the champ select title.
|
||||
pub(super) title: Line,
|
||||
/// « Dernier champion validé : X, le 20 nov. »
|
||||
pub(super) last_completed: Line,
|
||||
/// Last completion at home, Anvil availability during champ select.
|
||||
pub(super) detail: 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.
|
||||
/// The illustration when no card is hovered.
|
||||
pub(super) splash: Option<Rc<Splash>>,
|
||||
}
|
||||
|
||||
impl BannerContent {
|
||||
pub(super) fn champ_select(
|
||||
season: Option<&SharedString>,
|
||||
stats: Option<&Statistics>,
|
||||
known: bool,
|
||||
count: usize,
|
||||
splash: Option<Rc<Splash>>,
|
||||
) -> Self {
|
||||
let mut season = season.map(|name| name.to_uppercase()).unwrap_or_default();
|
||||
// Default split Seasons are named « Saison 2 2026 » in the stored data.
|
||||
if let Some((split, year)) = season.rsplit_once(' ')
|
||||
&& year.len() == 4
|
||||
&& year.bytes().all(|b| b.is_ascii_digit())
|
||||
&& split
|
||||
.strip_prefix("SAISON ")
|
||||
.is_some_and(|n| n.parse::<u32>().is_ok())
|
||||
{
|
||||
season = format!("{split} · {year}");
|
||||
}
|
||||
if let Some(challenge) = stats.and_then(|s| s.challenge.as_ref()) {
|
||||
use std::fmt::Write;
|
||||
write!(
|
||||
season,
|
||||
" · {} / {} validés",
|
||||
challenge.completed, challenge.total
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let detail = if !known {
|
||||
Line::plain(UNKNOWN_ANVIL)
|
||||
} else if stats.is_some() {
|
||||
Line::new(
|
||||
"Champions de l’Enclume · ",
|
||||
&count.to_string(),
|
||||
" à valider et disponibles",
|
||||
)
|
||||
} else {
|
||||
Line::default()
|
||||
};
|
||||
Self {
|
||||
season: season.into(),
|
||||
title: Line::plain("Sélection des champions"),
|
||||
detail,
|
||||
last_match: None,
|
||||
splash,
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -681,7 +735,7 @@ impl BannerContent {
|
||||
};
|
||||
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 {
|
||||
let detail = match last {
|
||||
Some(row) => {
|
||||
let day = row
|
||||
.challenge
|
||||
@@ -713,7 +767,7 @@ impl BannerContent {
|
||||
text: format!("{count} / {} champions validés", challenge.total).into(),
|
||||
bold: 0..count.len(),
|
||||
},
|
||||
last_completed,
|
||||
detail,
|
||||
last_match,
|
||||
splash: last.and_then(|row| row.splash.clone()).map(Rc::new),
|
||||
}
|
||||
|
||||
+51
-11
@@ -136,12 +136,12 @@ struct Geometry {
|
||||
/// so a scroll that moves the ring does not make it again.
|
||||
size: Size<Pixels>,
|
||||
/// One path per state of tick.
|
||||
ticks: Vec<(ChampionState, Path<Pixels>)>,
|
||||
ticks: Vec<(ChampionState, bool, Path<Pixels>)>,
|
||||
crown: Option<Path<Pixels>>,
|
||||
}
|
||||
|
||||
impl Geometry {
|
||||
fn new(size: Size<Pixels>, ticks: &[Tick]) -> Geometry {
|
||||
fn new(size: Size<Pixels>, ticks: &[Tick], anvil: Option<&[u32]>) -> Geometry {
|
||||
let frame = Frame::of(Bounds {
|
||||
origin: Point::default(),
|
||||
size,
|
||||
@@ -154,16 +154,32 @@ impl Geometry {
|
||||
];
|
||||
let ticks = states
|
||||
.into_iter()
|
||||
.filter_map(|state| {
|
||||
.flat_map(|state| [(state, false), (state, true)])
|
||||
.filter_map(|(state, dim)| {
|
||||
if dim && anvil.is_none() {
|
||||
return None;
|
||||
}
|
||||
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, shape(state).2);
|
||||
if tick.state == state
|
||||
&& dim == anvil.is_some_and(|ids| !ids.contains(&tick.id))
|
||||
{
|
||||
frame.add_tick(
|
||||
&mut path,
|
||||
index,
|
||||
count,
|
||||
state,
|
||||
if anvil.is_some() && !dim {
|
||||
7.
|
||||
} else {
|
||||
shape(state).2
|
||||
},
|
||||
);
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
Some((state, path.build().ok().filter(|_| any)?))
|
||||
Some((state, dim, path.build().ok().filter(|_| any)?))
|
||||
})
|
||||
.collect();
|
||||
let mut crown = PathBuilder::fill();
|
||||
@@ -191,6 +207,7 @@ fn moved(path: &Path<Pixels>, by: Point<Pixels>) -> Path<Pixels> {
|
||||
}
|
||||
|
||||
pub struct Ring {
|
||||
anvil: Option<Rc<[u32]>>,
|
||||
ticks: Rc<[Tick]>,
|
||||
/// The champion whose card is under the pointer.
|
||||
lit: Option<u32>,
|
||||
@@ -208,6 +225,7 @@ impl Ring {
|
||||
pub fn new() -> Ring {
|
||||
Ring {
|
||||
ticks: Rc::new([]),
|
||||
anvil: None,
|
||||
lit: None,
|
||||
geometry: Rc::default(),
|
||||
#[cfg(test)]
|
||||
@@ -226,6 +244,14 @@ impl Ring {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_anvil(&mut self, ids: Option<&[u32]>, cx: &mut Context<Self>) {
|
||||
if self.anvil.as_deref() != ids {
|
||||
self.anvil = ids.map(Rc::from);
|
||||
self.geometry.replace(None);
|
||||
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 {
|
||||
@@ -239,7 +265,6 @@ impl Ring {
|
||||
&self.ticks
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn lit(&self) -> Option<u32> {
|
||||
self.lit
|
||||
}
|
||||
@@ -266,6 +291,7 @@ impl Render for Ring {
|
||||
let (disc, crown, lit_color) = (theme.background, theme.primary, theme.foreground);
|
||||
let ticks = self.ticks.clone();
|
||||
let geometry = self.geometry.clone();
|
||||
let anvil = self.anvil.clone();
|
||||
#[cfg(test)]
|
||||
let tessellations = self.tessellations.clone();
|
||||
// The lit tick, and where it is.
|
||||
@@ -285,14 +311,18 @@ impl Render for Ring {
|
||||
if geometry.as_ref().is_none_or(|g| g.size != bounds.size) {
|
||||
#[cfg(test)]
|
||||
tessellations.set(tessellations.get() + 1);
|
||||
*geometry = Some(Geometry::new(bounds.size, &ticks));
|
||||
*geometry = Some(Geometry::new(bounds.size, &ticks, anvil.as_deref()));
|
||||
}
|
||||
let Some(geometry) = geometry.as_ref() else {
|
||||
return;
|
||||
};
|
||||
for (state, path) in &geometry.ticks {
|
||||
for (state, dim, path) in &geometry.ticks {
|
||||
let color = colors.iter().find(|(s, _)| s == state).map(|(_, c)| *c);
|
||||
window.paint_path(moved(path, bounds.origin), color.unwrap_or(crown));
|
||||
let color = color.unwrap_or(crown);
|
||||
window.paint_path(
|
||||
moved(path, bounds.origin),
|
||||
if *dim { color.opacity(0.16) } else { color },
|
||||
);
|
||||
}
|
||||
if let Some(path) = &geometry.crown {
|
||||
window.paint_path(moved(path, bounds.origin), crown);
|
||||
@@ -302,7 +332,17 @@ impl Render for Ring {
|
||||
let mut path = PathBuilder::fill();
|
||||
frame.add_tick(&mut path, index, ticks.len(), state, 7.);
|
||||
if let Ok(path) = path.build() {
|
||||
window.paint_path(path, lit_color);
|
||||
let dim = anvil
|
||||
.as_ref()
|
||||
.is_some_and(|ids| !ids.contains(&ticks[index].id));
|
||||
window.paint_path(
|
||||
path,
|
||||
if dim {
|
||||
lit_color.opacity(0.16)
|
||||
} else {
|
||||
lit_color
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user