Add the folding « Autres champions » section to the Arena champ select (#75)
Folded at each new selection, it lists the champions without an anvil (all of them, as « Tous les champions », when the client gave no Anvil list) with the anvil row's cards, order and greyed reasons. Its own search filters only this section. Its cards are built only while it is open, in a cached virtualized grid. The `others` profiling part is documented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6f2a6244cc
commit
f1e8808082
3 files changed
+488
-11
No files matched your search
+402
-8
@@ -6,8 +6,9 @@ use std::sync::Arc;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use arena_tracker_core::{
|
||||
Account, ChampSelect, ChampionSearch, Format, ProgressCheck, Scope, SeasonScope, StateFilter,
|
||||
Statistics, Status, SyncProgress, Tracker, UpdateProblem, account_riot_id, same_riot_id,
|
||||
Account, ChampSelect, ChampionRow, ChampionSearch, Format, ProgressCheck, Scope, SeasonScope,
|
||||
StateFilter, Statistics, Status, SyncProgress, Tracker, UpdateProblem, account_riot_id,
|
||||
same_riot_id,
|
||||
};
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::base::async_util::{Receiver, Sender};
|
||||
@@ -177,6 +178,16 @@ pub struct Page {
|
||||
anvil_grid: Entity<CardGrid>,
|
||||
/// How many Anvil champions the row shows, prepared with the cards.
|
||||
anvil_count: SharedString,
|
||||
/// « Autres champions »: folded at each new selection. While it is, it holds no card.
|
||||
others_open: bool,
|
||||
/// Filters this section only; emptied with each new selection.
|
||||
others_search: ChampionSearch,
|
||||
others_search_input: Entity<InputState>,
|
||||
/// The champions without an Anvil (all of them when the list is unknown), only built while
|
||||
/// the section is open: a virtualized grid, as the home's.
|
||||
others_grid: Entity<CardGrid>,
|
||||
/// The section's header button, which the keyboard reaches.
|
||||
others_focus: FocusHandle,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
_listener: Task<()>,
|
||||
}
|
||||
@@ -220,6 +231,10 @@ impl Page {
|
||||
let table = cx.new(|_| ChampionTable::new());
|
||||
let home_grid = cx.new(|_| CardGrid::new());
|
||||
let anvil_grid = cx.new(|_| CardGrid::fit_content());
|
||||
let others_search_input =
|
||||
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 subscriptions = vec![
|
||||
cx.subscribe(&search_input, |this, input, event: &InputEvent, cx| {
|
||||
@@ -234,6 +249,15 @@ impl Page {
|
||||
this.refresh_home(cx);
|
||||
}
|
||||
}),
|
||||
cx.subscribe(
|
||||
&others_search_input,
|
||||
|this, input, event: &InputEvent, cx| {
|
||||
if matches!(event, InputEvent::Change) {
|
||||
this.others_search = ChampionSearch::new(&input.read(cx).value());
|
||||
this.refresh_others(cx);
|
||||
}
|
||||
},
|
||||
),
|
||||
cx.subscribe_in(
|
||||
&account_select,
|
||||
window,
|
||||
@@ -342,6 +366,11 @@ impl Page {
|
||||
home_shown_count: SharedString::default(),
|
||||
anvil_grid,
|
||||
anvil_count: SharedString::default(),
|
||||
others_open: false,
|
||||
others_search: ChampionSearch::new(""),
|
||||
others_search_input,
|
||||
others_grid,
|
||||
others_focus,
|
||||
_subscriptions: subscriptions,
|
||||
_listener: listener,
|
||||
};
|
||||
@@ -484,6 +513,8 @@ impl Page {
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.stored = None;
|
||||
// A new selection starts with « Autres champions » folded and searchless.
|
||||
self.fold_others(window, cx);
|
||||
self.reload_in_background(window, cx);
|
||||
}
|
||||
if changed_page {
|
||||
@@ -841,12 +872,10 @@ impl Page {
|
||||
// The same rows in the same order as the home grid (`prepare_home_cards`): the
|
||||
// cards keep their place whatever the champ select does. An id the rows do not know is
|
||||
// skipped.
|
||||
let cards: Rc<[Card]> = match (self.stats.as_ref(), self.live_champ_select()) {
|
||||
(Some(stats), Some(pick)) => {
|
||||
let cards: Rc<[Card]> = match self.live_champ_select() {
|
||||
Some(pick) => {
|
||||
let anvil = pick.anvil_champions.as_deref().unwrap_or_default();
|
||||
stats
|
||||
.rows
|
||||
.iter()
|
||||
self.champ_select_order()
|
||||
.filter(|row| anvil.contains(&row.champion.id))
|
||||
.map(|row| {
|
||||
Card::from_row(row)
|
||||
@@ -854,7 +883,7 @@ impl Page {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
_ => Rc::new([]),
|
||||
None => Rc::new([]),
|
||||
};
|
||||
self.anvil_count = cards.len().to_string().into();
|
||||
let shown = (0..cards.len()).collect();
|
||||
@@ -862,6 +891,81 @@ impl Page {
|
||||
grid.set_cards(cards, cx);
|
||||
grid.set_shown(shown, cx);
|
||||
});
|
||||
self.prepare_others(cx);
|
||||
}
|
||||
|
||||
/// The master order of the champ select's cards, which every section follows: the
|
||||
/// statistics' rows, as the home grid's.
|
||||
fn champ_select_order(&self) -> impl Iterator<Item = &ChampionRow> {
|
||||
self.stats.iter().flat_map(|stats| stats.rows.iter())
|
||||
}
|
||||
|
||||
/// The rows of « Autres champions »: those whose id is not an Anvil one, in the master
|
||||
/// order; all of them when the client gave no list.
|
||||
fn other_rows(&self) -> impl Iterator<Item = &ChampionRow> {
|
||||
let anvil = self
|
||||
.live_champ_select()
|
||||
.and_then(|pick| pick.anvil_champions.as_deref());
|
||||
self.champ_select_order()
|
||||
.filter(move |row| anvil.is_none_or(|ids| !ids.contains(&row.champion.id)))
|
||||
}
|
||||
|
||||
/// Builds the cards of « Autres champions », for when the section opens or the champ select
|
||||
/// or the statistics change; while it is folded, nothing is built.
|
||||
fn prepare_others(&mut self, cx: &mut Context<Self>) {
|
||||
if !self.others_open {
|
||||
return;
|
||||
}
|
||||
let cards: Rc<[Card]> = match self.live_champ_select() {
|
||||
Some(pick) => self
|
||||
.other_rows()
|
||||
.map(|row| {
|
||||
Card::from_row(row).with_unavailability(pick.unavailability(row.champion.id))
|
||||
})
|
||||
.collect(),
|
||||
None => Rc::new([]),
|
||||
};
|
||||
self.others_grid
|
||||
.update(cx, |grid, cx| grid.set_cards(cards, cx));
|
||||
self.refresh_others(cx);
|
||||
}
|
||||
|
||||
/// Recomputes which cards of « Autres champions » its search keeps: the cards are the rows
|
||||
/// of `other_rows`, in the same order.
|
||||
fn refresh_others(&mut self, cx: &mut Context<Self>) {
|
||||
if !self.others_open {
|
||||
return;
|
||||
}
|
||||
let shown: Vec<usize> = self
|
||||
.other_rows()
|
||||
.enumerate()
|
||||
.filter(|(_, row)| self.others_search.matches(&row.champion))
|
||||
.map(|(ix, _)| ix)
|
||||
.collect();
|
||||
self.others_grid
|
||||
.update(cx, |grid, cx| grid.set_shown(shown, cx));
|
||||
}
|
||||
|
||||
/// Opens or folds « Autres champions »; folded, it gives its cards back.
|
||||
fn toggle_others(&mut self, cx: &mut Context<Self>) {
|
||||
self.others_open = !self.others_open;
|
||||
if self.others_open {
|
||||
self.prepare_others(cx);
|
||||
} else {
|
||||
self.others_grid = cx.new(|_| CardGrid::new());
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Folds « Autres champions » and empties its search, for a new selection.
|
||||
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.others_search = ChampionSearch::new("");
|
||||
self.others_search_input
|
||||
.update(cx, |input, cx| input.set_value("", window, cx));
|
||||
}
|
||||
|
||||
/// At the end of a champ select the home is as at launch: « Tous » and an empty search. The
|
||||
@@ -2567,6 +2671,296 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the non-anvil champions of the capture are, in the home's order (A to Z by name).
|
||||
const OTHERS_A_TO_Z: [u32; 4] = [103, 12, 25, 50];
|
||||
|
||||
fn others_cards(page: &Entity<Page>, window: &mut VisualTestContext) -> Vec<Card> {
|
||||
let grid = page.read_with(window, |p, _| p.others_grid.clone());
|
||||
grid.read_with(window, |grid, _| grid.shown_cards())
|
||||
}
|
||||
|
||||
fn others_open(page: &Entity<Page>, window: &mut VisualTestContext) -> bool {
|
||||
page.read_with(window, |p, _| p.others_open)
|
||||
}
|
||||
|
||||
fn click_others(window: &mut VisualTestContext) {
|
||||
let toggle = center(window, "others-toggle");
|
||||
window.simulate_click(toggle, Modifiers::none());
|
||||
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 =
|
||||
window.update(|_, cx| Keystroke::parse_with_os(key, cx.platform_info().os).unwrap());
|
||||
window.simulate_event(KeyDownEvent {
|
||||
keystroke: keystroke.clone(),
|
||||
is_held: false,
|
||||
prefer_character_input: false,
|
||||
});
|
||||
window.simulate_event(KeyUpEvent { keystroke });
|
||||
draw(window);
|
||||
}
|
||||
|
||||
/// Tab, until the section's header has the focus.
|
||||
fn focus_others_toggle(page: &Entity<Page>, window: &mut VisualTestContext) {
|
||||
for _ in 0..60 {
|
||||
window.update(|w, cx| w.focus_next(cx));
|
||||
draw(window);
|
||||
if window.update(|w, cx| page.read(cx).others_focus.is_focused(w)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
panic!("Tab never reached « Autres champions »");
|
||||
}
|
||||
|
||||
fn search_others(page: &Entity<Page>, window: &mut VisualTestContext, text: &str) {
|
||||
let input = page.read_with(window, |p, _| p.others_search_input.clone());
|
||||
window.update(|w, cx| {
|
||||
input.update(cx, |input, cx| {
|
||||
input.focus(w, cx);
|
||||
input.clean(w, cx);
|
||||
})
|
||||
});
|
||||
if !text.is_empty() {
|
||||
window.simulate_input(text);
|
||||
}
|
||||
draw(window);
|
||||
}
|
||||
|
||||
/// The page in the first frame of the capture, once its statistics are there.
|
||||
async fn page_in_champ_select(
|
||||
cx: &mut TestAppContext,
|
||||
pick: &ChampSelect,
|
||||
) -> (Entity<Page>, VisualTestContext) {
|
||||
cx.executor().allow_parking();
|
||||
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
||||
send(&page, &mut window, pick);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
draw(&mut window);
|
||||
(page, window)
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn others_is_folded_at_entry_and_builds_no_card(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
assert!(!others_open(&page, &mut window));
|
||||
assert!(window.debug_bounds("others-toggle").is_some());
|
||||
assert!(window.debug_bounds("anvil-row").is_some());
|
||||
let grid = page.read_with(&window, |p, _| p.others_grid.clone());
|
||||
grid.read_with(&window, |grid, _| {
|
||||
assert_eq!(grid.renders, 0);
|
||||
assert_eq!(grid.card_builds, 0);
|
||||
assert_eq!(grid.set_cards_calls, 0);
|
||||
});
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
// The frames and the statistics keep coming while it is folded: still nothing.
|
||||
for pick in &frames()[1..] {
|
||||
send(&page, &mut window, pick);
|
||||
draw(&mut window);
|
||||
}
|
||||
grid.read_with(&window, |grid, _| {
|
||||
assert_eq!((grid.renders, grid.set_cards_calls), (0, 0));
|
||||
});
|
||||
page.read_with(&window, |p, _| {
|
||||
assert_eq!(p.others_title(), "Autres champions")
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn others_opens_and_closes_with_the_mouse_and_the_keyboard(cx: &mut TestAppContext) {
|
||||
let pick = with_bans_and_ally(&[12, 50], 25);
|
||||
let (page, mut window) = page_in_champ_select(cx, &pick).await;
|
||||
let anvil_before = anvil_cards(&page, &mut window);
|
||||
|
||||
click_others(&mut window);
|
||||
assert!(others_open(&page, &mut window));
|
||||
// Every champion without an anvil, banned or taken ones included, in the home's order.
|
||||
let cards = others_cards(&page, &mut window);
|
||||
assert_eq!(ids(&cards), OTHERS_A_TO_Z);
|
||||
assert_eq!(reasons(&cards, 103), []);
|
||||
assert_eq!(reasons(&cards, 12), [Reason::Banned]);
|
||||
assert_eq!(reasons(&cards, 25), [Reason::TakenByAlly]);
|
||||
assert_eq!(reasons(&cards, 50), [Reason::Banned]);
|
||||
assert!(window.debug_bounds("card-103").is_some());
|
||||
assert!(window.debug_bounds("card-12").is_some());
|
||||
// The anvil row is untouched.
|
||||
assert_eq!(anvil_cards(&page, &mut window), anvil_before);
|
||||
|
||||
click_others(&mut window);
|
||||
assert!(!others_open(&page, &mut window));
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
assert!(others_cards(&page, &mut window).is_empty());
|
||||
|
||||
// With the keyboard: Tab reaches the header, Enter opens it and Space folds it.
|
||||
focus_others_toggle(&page, &mut window);
|
||||
activate(&mut window, "enter");
|
||||
assert!(others_open(&page, &mut window));
|
||||
assert_eq!(ids(&others_cards(&page, &mut window)), OTHERS_A_TO_Z);
|
||||
activate(&mut window, "space");
|
||||
assert!(!others_open(&page, &mut window));
|
||||
activate(&mut window, "enter");
|
||||
assert!(others_open(&page, &mut window));
|
||||
|
||||
// The lock-ins of the selection reach the open section, which keeps its place.
|
||||
send(&page, &mut window, &with_bans_and_ally(&[103], 25));
|
||||
draw(&mut window);
|
||||
let cards = others_cards(&page, &mut window);
|
||||
assert_eq!(ids(&cards), OTHERS_A_TO_Z);
|
||||
assert_eq!(reasons(&cards, 103), [Reason::Banned]);
|
||||
assert_eq!(reasons(&cards, 12), []);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn others_shows_the_completed_champions_it_holds(cx: &mut TestAppContext) {
|
||||
// 16 is Completed; with only 233 an Anvil champion it is one of the others.
|
||||
let session = capture()["sessions"][0].clone();
|
||||
let pick = read_champ_select(&ChampSelectReader::default(), session, Some("[233]".into()));
|
||||
let (page, mut window) = page_in_champ_select(cx, &pick).await;
|
||||
click_others(&mut window);
|
||||
let cards = others_cards(&page, &mut window);
|
||||
assert_eq!(ids(&cards), [103, 12, 64, 25, 68, 16, 50, 5]);
|
||||
assert_eq!(reasons(&cards, 16), [Reason::Completed]);
|
||||
assert_eq!(reasons(&cards, 64), [Reason::NotOffered]);
|
||||
assert_eq!(ids(&anvil_cards(&page, &mut window)), [233]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_search_of_others_filters_only_that_section(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
click_others(&mut window);
|
||||
let anvil_before = anvil_cards(&page, &mut window);
|
||||
let grid = page.read_with(&window, |p, _| p.others_grid.clone());
|
||||
|
||||
search_others(&page, &mut window, "ahr");
|
||||
assert_eq!(grid_names(&grid, &mut window), ["Ahri"]);
|
||||
// By alias: « cow » is Alistar's.
|
||||
search_others(&page, &mut window, "cow");
|
||||
assert_eq!(grid_names(&grid, &mut window), ["Alistar"]);
|
||||
// An Anvil champion is not in this section, whoever searches for it.
|
||||
search_others(&page, &mut window, "xz");
|
||||
assert!(grid_names(&grid, &mut window).is_empty());
|
||||
assert!(window.debug_bounds("no-champion").is_some());
|
||||
|
||||
// The anvil row and the home's search are intact.
|
||||
assert_eq!(anvil_cards(&page, &mut window), anvil_before);
|
||||
assert_eq!(ids(&anvil_cards(&page, &mut window)), ANVIL_A_TO_Z);
|
||||
page.read_with(&window, |p, cx| {
|
||||
assert!(p.home_search_input.read(cx).value().is_empty())
|
||||
});
|
||||
|
||||
search_others(&page, &mut window, "");
|
||||
assert_eq!(ids(&others_cards(&page, &mut window)), OTHERS_A_TO_Z);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn a_new_selection_folds_others_and_empties_its_search(cx: &mut TestAppContext) {
|
||||
let frames = frames();
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames[0]).await;
|
||||
let fresh = |window: &mut VisualTestContext| {
|
||||
page.read_with(window, |p, cx| {
|
||||
assert!(!p.others_open);
|
||||
assert!(p.others_search_input.read(cx).value().is_empty());
|
||||
assert_eq!(p.others_grid.read(cx).renders, 0);
|
||||
assert!(p.others_grid.read(cx).shown_cards().is_empty());
|
||||
})
|
||||
};
|
||||
|
||||
// The frames of the same selection keep it open, with its search.
|
||||
click_others(&mut window);
|
||||
search_others(&page, &mut window, "ahr");
|
||||
send(&page, &mut window, &frames[1]);
|
||||
draw(&mut window);
|
||||
assert!(others_open(&page, &mut window));
|
||||
assert_eq!(others_cards(&page, &mut window).len(), 1);
|
||||
let grid = page.read_with(&window, |p, _| p.others_grid.clone());
|
||||
assert_eq!(grid_names(&grid, &mut window), ["Ahri"]);
|
||||
|
||||
// Leaving, then entering again.
|
||||
leave(&page, &mut window);
|
||||
draw(&mut window);
|
||||
fresh(&mut window);
|
||||
send(&page, &mut window, &frames[0]);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
draw(&mut window);
|
||||
fresh(&mut window);
|
||||
assert!(window.debug_bounds("others-toggle").is_some());
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
|
||||
// The selection of another Riot ID.
|
||||
click_others(&mut window);
|
||||
search_others(&page, &mut window, "cow");
|
||||
let live = Some(("Autre#EUW".to_string(), frames[0].clone()));
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
p.apply(crate::worker::Msg::ChampSelect(live), w, cx)
|
||||
})
|
||||
});
|
||||
fresh(&mut window);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
draw(&mut window);
|
||||
fresh(&mut window);
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn others_lists_every_champion_when_the_anvil_list_is_unknown(cx: &mut TestAppContext) {
|
||||
let session = capture()["sessions"][0].clone();
|
||||
let pick = read_champ_select(&ChampSelectReader::default(), session, None);
|
||||
let (page, mut window) = page_in_champ_select(cx, &pick).await;
|
||||
page.read_with(&window, |p, _| {
|
||||
assert_eq!(p.others_title(), "Tous les champions")
|
||||
});
|
||||
click_others(&mut window);
|
||||
let all: Vec<u32> = page.read_with(&window, |p, _| {
|
||||
p.stats
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.rows
|
||||
.iter()
|
||||
.map(|r| r.champion.id)
|
||||
.collect()
|
||||
});
|
||||
assert_eq!(all.len(), 9);
|
||||
assert_eq!(ids(&others_cards(&page, &mut window)), all);
|
||||
assert!(anvil_cards(&page, &mut window).is_empty());
|
||||
assert!(window.debug_bounds("card-233").is_some());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn others_builds_only_the_visible_cards_and_hovering_elsewhere_does_not_draw_them(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let (page, mut window) = open_page_in_season(cx);
|
||||
send(&page, &mut window, &frames()[0]);
|
||||
// The statistics of the Account, as the worker would give them: 170 champions, most
|
||||
// of them without an anvil.
|
||||
show(&page, &mut window, statistics(0, 170, champions(170)));
|
||||
draw(&mut window);
|
||||
click_others(&mut window);
|
||||
let grid = page.read_with(&window, |p, _| p.others_grid.clone());
|
||||
let (built, renders) = grid.read_with(&window, |grid, _| (grid.card_builds, grid.renders));
|
||||
// 170 champions less the Anvil ones the statistics know: 5, 16, 64 and 68.
|
||||
assert_eq!(
|
||||
grid.read_with(&window, |grid, _| grid.shown_cards().len()),
|
||||
166
|
||||
);
|
||||
assert!(built > 0 && built <= 8 * 6, "{built} cards built for 170");
|
||||
assert!(renders > 0);
|
||||
|
||||
// Hovering the header, outside the cards, draws the page and not the cards.
|
||||
let toggle = center(&mut window, "others-toggle");
|
||||
for dx in 0..5 {
|
||||
window.simulate_mouse_move(
|
||||
point(toggle.x + px(dx as f32 * 7.), toggle.y),
|
||||
None,
|
||||
Modifiers::none(),
|
||||
);
|
||||
draw(&mut window);
|
||||
}
|
||||
assert_eq!(grid.read_with(&window, |grid, _| grid.renders), renders);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn no_champ_select_changes_nothing(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open_page_in_season(cx);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
//! The « Défi » tab, the home: the Challenge of one Season, and its champions.
|
||||
|
||||
use arena_tracker_core::StateFilter;
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::component::input::Input;
|
||||
use gpui_kit::component::tab::{Tab, TabBar};
|
||||
use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
|
||||
use gpui_kit::component::{ActiveTheme as _, Icon, IconName, Sizable as _, StyledExt as _};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
@@ -35,10 +36,14 @@ impl Page {
|
||||
}
|
||||
if self.in_champ_select() {
|
||||
// The selection takes the place of the grid, its filters and its search: the
|
||||
// column may be taller than the window, and scrolls then.
|
||||
// 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));
|
||||
}
|
||||
if shown("others") {
|
||||
column = column.child(self.others_area(cx));
|
||||
}
|
||||
return vec![
|
||||
column
|
||||
.id("champ-select")
|
||||
@@ -127,6 +132,84 @@ impl Page {
|
||||
})
|
||||
}
|
||||
|
||||
/// « Autres champions » when the client gave the Anvil champions, so that these are the ones
|
||||
/// without an anvil; « Tous les champions » when it did not, as the section then lists all.
|
||||
pub(super) fn others_title(&self) -> &'static str {
|
||||
let known = self
|
||||
.live_champ_select()
|
||||
.is_some_and(|pick| pick.anvil_champions.is_some());
|
||||
if known {
|
||||
"Autres champions"
|
||||
} else {
|
||||
"Tous les champions"
|
||||
}
|
||||
}
|
||||
|
||||
/// « Autres champions »: a header that folds the section, and open, its search and its
|
||||
/// cards. Folded, no card is built and the grid is not even drawn. The champions are « sans
|
||||
/// enclume » only when the client gave the list: else they are all of them.
|
||||
fn others_area(&self, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (muted, border, ring, hover, hover_foreground) = (
|
||||
theme.muted_foreground,
|
||||
theme.border,
|
||||
theme.ring,
|
||||
theme.accent,
|
||||
theme.accent_foreground,
|
||||
);
|
||||
let title = self.others_title();
|
||||
let open = self.others_open;
|
||||
let chevron = if open {
|
||||
IconName::ChevronDown
|
||||
} else {
|
||||
IconName::ChevronRight
|
||||
};
|
||||
div()
|
||||
.v_flex()
|
||||
.w_full()
|
||||
.gap_3()
|
||||
.when(open, |section| section.flex_1())
|
||||
.child(
|
||||
BaseButton::new("others-toggle")
|
||||
.track_focus(&self.others_focus)
|
||||
.w_full()
|
||||
.justify_start()
|
||||
.gap_2()
|
||||
.px_1()
|
||||
.py_2()
|
||||
.border_t_1()
|
||||
.border_b_1()
|
||||
.border_color(border)
|
||||
.focus_visible(|style| style.border_color(ring))
|
||||
.hover(|style| style.bg(hover).text_color(hover_foreground))
|
||||
.text_lg()
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.accessibility_label(title)
|
||||
.debug_selector(|| "others-toggle".into())
|
||||
.child(Icon::new(chevron).small().text_color(muted))
|
||||
.child(title)
|
||||
.on_click(cx.listener(|this, _, _, cx| this.toggle_others(cx))),
|
||||
)
|
||||
.when(open, |section| {
|
||||
section
|
||||
.child(
|
||||
div().h_flex().child(
|
||||
Input::new(&self.others_search_input)
|
||||
.cleanable(true)
|
||||
.w(px(260.))
|
||||
.min_w(px(150.)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
// Cached, as the home's grid: hovering elsewhere does not draw its
|
||||
// cards again. Its size comes from this style.
|
||||
self.others_grid
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().w_full().flex_1().min_h(px(240.))),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// « Mes champions » with how many cards are shown, and on the right the filters and search.
|
||||
fn home_heading(&self, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
|
||||
Reference in new issue
Block a user