From b682755f0e08259d4d946d2fb47c0b7e1c5df465 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Sat, 31 Oct 2026 22:04:09 +0300 Subject: [PATCH] Prep row shortens in one order; the game link as in its header everywhere The period and the depth captions are chosen together: the depth gives way first at every width. The list's context menu reads the game's link (once per menu) and names the site as the game screen does; the header's subtitle leaves the web address to the globe, whose tooltip says what opens. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/game_link.rs | 10 ++++ apps/desktop/src/game_view.rs | 10 ++-- apps/desktop/src/i18n.rs | 58 ++++++++++++------ apps/desktop/src/large_db.rs | 21 ++++--- apps/desktop/src/prep_ui.rs | 108 +++++++++++++++++++--------------- 5 files changed, 129 insertions(+), 78 deletions(-) diff --git a/apps/desktop/src/game_link.rs b/apps/desktop/src/game_link.rs index fa56f44..a29f587 100644 --- a/apps/desktop/src/game_link.rs +++ b/apps/desktop/src/game_link.rs @@ -69,6 +69,16 @@ impl GameLink { } } + /// The globe's tooltip: «Open on Lichess (in the browser, at this move)». + pub fn hint(&self) -> &'static str { + match (self.site, self.lichess_id.is_some()) { + (Site::Lichess, true) => tr("Open on Lichess (in the browser, at this move)"), + (Site::Lichess, false) => tr("Open on Lichess (in the browser)"), + (Site::ChessCom, _) => tr("Open on Chess.com (in the browser)"), + (Site::Other, _) => tr("Open the game's link (in the browser)"), + } + } + /// «🌐 Open on Lichess». pub fn label(&self) -> &'static str { match self.site { diff --git a/apps/desktop/src/game_view.rs b/apps/desktop/src/game_view.rs index 08a129c..025fc06 100644 --- a/apps/desktop/src/game_view.rs +++ b/apps/desktop/src/game_view.rs @@ -355,7 +355,10 @@ impl GameView { for t in ["Event", "Site", "Date", "ECO", "Annotator"] { if let Some(v) = g .tag(t) - .filter(|v| !v.is_empty() && !v.chars().all(|c| c == '?' || c == '.')) + // A web address is the globe's, not text. + .filter(|v| { + !v.is_empty() && !v.chars().all(|c| c == '?' || c == '.') && !v.contains("://") + }) { parts.push(v.to_string()); } @@ -1134,10 +1137,7 @@ impl GameView { .on_hover_text(result_hint); } if let Some(l) = &link - && ui - .small_button("🌐") - .on_hover_text(format!("{} — {}", l.label(), tr("in the browser"))) - .clicked() + && ui.button("🌐").on_hover_text(l.hint()).clicked() { self.open_link(ui.ctx(), l); } diff --git a/apps/desktop/src/i18n.rs b/apps/desktop/src/i18n.rs index 6adefc2..4a01fb5 100644 --- a/apps/desktop/src/i18n.rs +++ b/apps/desktop/src/i18n.rs @@ -16123,26 +16123,48 @@ const ROWS: &[[&str; 9]] = &[ "🌐 Партия сілтемесін ашу", ], [ - "🌐 Open in the browser", - "🌐 Открыть в браузере", - "🌐 Ouvrir dans le navigateur", - "🌐 Im Browser öffnen", - "🌐 Abrir en el navegador", - "🌐 Apri nel browser", - "🌐 Abrir no navegador", - "🌐 Brauzerda ochish", - "🌐 Браузерде ашу", + "Open on Lichess (in the browser, at this move)", + "Открыть на Lichess (в браузере, с этого хода)", + "Ouvrir sur Lichess (dans le navigateur, à ce coup)", + "Auf Lichess öffnen (im Browser, bei diesem Zug)", + "Abrir en Lichess (en el navegador, en esta jugada)", + "Apri su Lichess (nel browser, a questa mossa)", + "Abrir no Lichess (no navegador, neste lance)", + "Lichess’da ochish (brauzerda, shu yurishdan)", + "Lichess-те ашу (браузерде, осы жүрістен)", ], [ - "in the browser", - "в браузере", - "dans le navigateur", - "im Browser", - "en el navegador", - "nel browser", - "no navegador", - "brauzerda", - "браузерде", + "Open on Lichess (in the browser)", + "Открыть на Lichess (в браузере)", + "Ouvrir sur Lichess (dans le navigateur)", + "Auf Lichess öffnen (im Browser)", + "Abrir en Lichess (en el navegador)", + "Apri su Lichess (nel browser)", + "Abrir no Lichess (no navegador)", + "Lichess’da ochish (brauzerda)", + "Lichess-те ашу (браузерде)", + ], + [ + "Open on Chess.com (in the browser)", + "Открыть на Chess.com (в браузере)", + "Ouvrir sur Chess.com (dans le navigateur)", + "Auf Chess.com öffnen (im Browser)", + "Abrir en Chess.com (en el navegador)", + "Apri su Chess.com (nel browser)", + "Abrir no Chess.com (no navegador)", + "Chess.com’da ochish (brauzerda)", + "Chess.com-да ашу (браузерде)", + ], + [ + "Open the game's link (in the browser)", + "Открыть ссылку партии (в браузере)", + "Ouvrir le lien de la partie (dans le navigateur)", + "Link der Partie öffnen (im Browser)", + "Abrir el enlace de la partida (en el navegador)", + "Apri il link della partita (nel browser)", + "Abrir o link da partida (no navegador)", + "Partiya havolasini ochish (brauzerda)", + "Партия сілтемесін ашу (браузерде)", ], ]; diff --git a/apps/desktop/src/large_db.rs b/apps/desktop/src/large_db.rs index d93d60d..a50c0cd 100644 --- a/apps/desktop/src/large_db.rs +++ b/apps/desktop/src/large_db.rs @@ -341,6 +341,8 @@ pub struct LargeView { /// «Prepare against…» was asked (the panel's button, a row's menu): the library /// takes it (docs/design/opponent-prep.md §2.1). pub prepare: Option, + /// The web page of the game whose context menu is open (its record, the link). + menu_link: Option<(usize, Option)>, } impl LargeView { @@ -426,6 +428,7 @@ impl LargeView { drawer_asked: false, drawer_top: 0.0, prepare: None, + menu_link: None, } } @@ -2260,15 +2263,17 @@ impl LargeView { opened = Some(index); ui.close(); } - // A game downloaded from Lichess or Chess.com: its page. - let online = r.site.to_ascii_lowercase().contains("lichess.org") - || r.site.trim().eq_ignore_ascii_case("chess.com"); - if online && ui.button(tr("🌐 Open in the browser")).clicked() { - if let Some(link) = db.load_game(index).and_then(|p| { + // The game's page, when its tags have one (read once per menu). + if self.menu_link.as_ref().is_none_or(|(i, _)| *i != index) { + let link = db.load_game(index).and_then(|p| { crate::game_link::of(|t| p.game.tag(t).map(str::to_owned)) - }) { - ui.ctx().open_url(egui::OpenUrl::new_tab(link.at(0, false))); - } + }); + self.menu_link = Some((index, link)); + } + if let Some((_, Some(link))) = &self.menu_link + && ui.button(link.label()).clicked() + { + ui.ctx().open_url(egui::OpenUrl::new_tab(link.at(0, false))); ui.close(); } // One item per player of the game (the same name once). diff --git a/apps/desktop/src/prep_ui.rs b/apps/desktop/src/prep_ui.rs index 3dec6a3..5584388 100644 --- a/apps/desktop/src/prep_ui.rs +++ b/apps/desktop/src/prep_ui.rs @@ -3165,27 +3165,26 @@ impl PrepScreen { } else { 0.0 }; - // The period takes what the depth leaves at its shortest. - let depth_least = text_width( - ui, - &trf("{n} m.", &[("n", &moves)]), - egui::TextStyle::Button, - ) + pad - + 20.0 - + 2.0 * gap; - let period_room = ui.available_width() - engine_w - board_w - depth_least; - self.period_picker(ui, settings, period_room, actions); - ui.separator(); - // The depth's caption by the room left: «Opening: 10 moves», «10 moves», «10 m.». - let room = ui.available_width() - engine_w - board_w; - let depth_label = [ + // The period's and the depth's captions by the room left, shortened in one + // order at every width: the depth first, then the period, then both. + let depths = [ trf("Opening: {n} moves", &[("n", &moves)]), trf("{n} moves", &[("n", &moves)]), trf("{n} m.", &[("n", &moves)]), - ] - .into_iter() - .find(|l| text_width(ui, l, egui::TextStyle::Button) + pad + 20.0 + gap <= room) - .unwrap_or_else(|| trf("{n} m.", &[("n", &moves)])); + ]; + let periods = self.period_captions(); + let combo = |t: &str| text_width(ui, t, egui::TextStyle::Button) + pad + 20.0 + gap; + let room = + ui.available_width() - engine_w - board_w - ui.spacing().item_spacing.x * 2.0; + let (p, d) = [(0, 0), (0, 1), (1, 1), (1, 2), (2, 2)] + .into_iter() + .find(|&(p, d)| combo(&periods[p]) + combo(&depths[d]) <= room) + .unwrap_or((2, 2)); + let [p0, p1, p2] = periods; + let period_label_now = [p0, p1, p2].into_iter().nth(p).unwrap_or_default(); + self.period_picker(ui, settings, period_label_now, actions); + ui.separator(); + let depth_label = depths[d].clone(); let mut new_plies = None; let depth_w = text_width(ui, &depth_label, egui::TextStyle::Button) + 8.0; egui::ComboBox::from_id_salt("prep_plies") @@ -3226,45 +3225,60 @@ impl PrepScreen { }); } + /// The period shown: a period by months over games without dates takes all. + fn period_shown(&self) -> Period { + let dated = self + .report + .as_ref() + .is_some_and(|r| r.pool.iter().any(|g| g.date != 0)); + match self.period { + Period::Months(_) if self.report.is_some() && !dated => Period::All, + p => p, + } + } + + /// How many games `p` takes of the colour(s) shown: «80», «100 + 100». + fn period_number(&self, p: Period) -> String { + let Some(r) = &self.report else { + return "…".to_owned(); + }; + let side = self.color.side(); + match (p, side) { + // The last N of each colour, not N in all. + (Period::Last(_), Side::Any) => format!( + "{} + {}", + grouped(r.count(p, Side::White).games), + grouped(r.count(p, Side::Black).games) + ), + _ => grouped(r.count(p, side).games), + } + } + + /// The period's captions, longest first: «Last 2 years · 80», «2 yrs · 80», «80». + fn period_captions(&self) -> [String; 3] { + let p = self.period_shown(); + let n = self.period_number(p); + [ + format!("{} · {n}", period_label(p)), + format!("{} · {n}", period_short(p)), + n, + ] + } + /// «Last 2 years · 80 ▾»: which of the player's games, with how many each takes of - /// the colour(s) shown; shorter («2 yrs · 80», «80») when `room` is short. + /// the colour(s) shown; `selected` is the caption the row has room for. fn period_picker( &mut self, ui: &mut Ui, settings: &mut Settings, - room: f32, + selected: String, actions: &mut Vec, ) { let side = self.color.side(); let report = self.report.as_ref(); let dated = report.is_some_and(|r| r.pool.iter().any(|g| g.date != 0)); - // Without dates a period by months takes all the games: it is shown as all. - let shown = match self.period { - Period::Months(_) if report.is_some() && !dated => Period::All, - p => p, - }; - let number = |p: Period| -> String { - let Some(r) = report else { - return "…".to_owned(); - }; - match (p, side) { - // «100 + 100»: the last N of each colour, not N in all. - (Period::Last(_), Side::Any) => format!( - "{} + {}", - grouped(r.count(p, Side::White).games), - grouped(r.count(p, Side::Black).games) - ), - _ => grouped(r.count(p, side).games), - } - }; - let pad = 2.0 * ui.spacing().button_padding.x + 20.0; - let selected = [ - format!("{} · {}", period_label(shown), number(shown)), - format!("{} · {}", period_short(shown), number(shown)), - ] - .into_iter() - .find(|t| text_width(ui, t, egui::TextStyle::Button) + pad <= room) - .unwrap_or_else(|| number(shown)); + let shown = self.period_shown(); + let number = |p: Period| self.period_number(p); let mut picked = None; // As wide as its text: the room is the row's. let width = text_width(ui, &selected, egui::TextStyle::Button) + 8.0;