diff --git a/apps/desktop/src/game_view.rs b/apps/desktop/src/game_view.rs index 05a8bba..db29558 100644 --- a/apps/desktop/src/game_view.rs +++ b/apps/desktop/src/game_view.rs @@ -247,19 +247,28 @@ impl GameView { self.sync_analysis(analysis); let databases = settings.databases.clone(); egui::Panel::top("game_header").show(ui, |ui| self.header(ui, &databases, &mut actions)); - // Keep room for the board on narrow windows: the side panel never exceeds 60 %. + // The board takes the full height of the window: the side panel is never wider + // than what is left beside it (the user can make it narrower, not wider). The + // reference tab has two wide tables and its own width (egui remembers each). let width = ui.available_width(); - // The reference tab has two wide tables: its own (wider) panel width, which - // egui remembers apart from the notation's. - let (side_id, side_width) = if self.side_tab == SideTab::Reference { - ("game_side_reference", (width * 0.55).clamp(360.0, 1100.0)) + let height = ui.available_height(); + let graph = self.review.visible && (self.review.has_data() || self.review.running()); + let board = if graph { + height - (height * 0.14).clamp(80.0, 130.0) - 8.0 } else { - ("game_side", (width * 0.4).clamp(260.0, 460.0)) + height + } - 16.0; + let room = (width - board - 24.0).max(240.0); + let (side_id, side_width) = if self.side_tab == SideTab::Reference { + ("game_side_ref", room.min(1100.0)) + } else { + ("game_side", (width * 0.4).clamp(260.0, 460.0).min(room)) }; + let max = room.max(side_width).min((width * 0.7).max(240.0)); egui::Panel::right(side_id) .resizable(true) .default_size(side_width) - .size_range(240.0_f32.min(width * 0.5)..=(width * 0.7).max(240.0)) + .size_range(240.0_f32.min(width * 0.5).min(max)..=max) .show(ui, |ui| { self.side_panel(ui, settings, analysis, reference, &mut actions) }); diff --git a/apps/desktop/src/reference.rs b/apps/desktop/src/reference.rs index 9cb7280..af35c3d 100644 --- a/apps/desktop/src/reference.rs +++ b/apps/desktop/src/reference.rs @@ -711,6 +711,14 @@ fn book_end( }) } +/// "Mega Database 2026 · 11,7 млн партий" for the database picker. +fn db_label(d: &RefDb) -> String { + match &d.db { + Some(db) => format!("{} · {}", d.name, crate::i18n::games_short(db.len())), + None => format!("{} · {}", d.name, tr("not open")), + } +} + impl Reference { /// The move under the pointer, or the selected one (an arrow on the board). pub fn hover(&self) -> Option { @@ -884,27 +892,77 @@ impl Reference { }; let path = current.path.clone(); let db = current.db.clone(); - // The database picker. - ui.horizontal(|ui| { + let failed = current.failed.clone(); + let current_label = db_label(current); + let query = query_for(game, cursor); + let exclude = source.filter(|(p, _)| *p == path).map(|(_, i)| i); + if let (Some(db), Some(q)) = (&db, &query) { + self.request(ui.ctx(), &path, db, game, q, exclude); + if self.job.is_some() || self.prepare.is_some() || self.book_job.is_some() { + ui.ctx() + .request_repaint_after(std::time::Duration::from_millis(100)); + } + } + // The novelty (the first move of the game no other game of the database played) + // and a copy of the game in the database, once worked out. + let line = main_line(game); + let book = db + .is_some() + .then(|| self.book_for(&path, &line).cloned()) + .flatten(); + let novelty = book.as_ref().and_then(|b| match b.last { + _ if b.to_the_end || line.is_empty() => None, + Some(last) => game.main_child(last), + None => game.main_child(game.root()), + }); + let copy = book + .as_ref() + .and_then(|b| b.copies.iter().copied().find(|c| Some(*c) != exclude)); + // The first line: the database, then the novelty and the copy beside it (they + // come a moment later; on this line they take no room of their own). + ui.horizontal_wrapped(|ui| { ui.label(tr("Database")); - let label = |d: &RefDb| match &d.db { - Some(db) => format!("{} · {}", d.name, crate::i18n::games_short(db.len())), - None => format!("{} · {}", d.name, tr("not open")), - }; egui::ComboBox::from_id_salt("reference_db") - .selected_text(label(current)) - .width(ui.available_width().min(380.0)) + .selected_text(current_label) + .width(ui.available_width().min(340.0)) .truncate() .show_ui(ui, |ui| { for d in &self.dbs { - if ui.selectable_label(d.path == path, label(d)).clicked() && d.path != path + if ui.selectable_label(d.path == path, db_label(d)).clicked() + && d.path != path { action = Some(RefAction::Choose(d.path.clone())); } } }); + if let Some(node) = novelty { + ui.add_space(8.0); + ui.label(RichText::new(tr("Novelty:")).weak()); + if ui + .link(node_label(game, node).unwrap_or_default()) + .on_hover_text(tr( + "The first move of this game that no other game of this database played; before it the game followed games of the database", + )) + .clicked() + { + action = Some(RefAction::Goto(node)); + } + } + if let (Some(c), Some(q)) = (copy, &query) { + ui.add_space(8.0); + ui.label(RichText::new(tr("This game is in the database")).weak()); + if ui + .link(tr("open it")) + .on_hover_text(tr( + "Open the copy of this game from the database at this position", + )) + .clicked() + { + action = Some(RefAction::OpenGame(path.clone(), c, q.position.clone())); + } + } }); - if let Some(e) = ¤t.failed { + if let Some(e) = &failed { ui.add_space(8.0); ui.label( RichText::new(trf("This database cannot be opened: {e}", &[("e", e)])) @@ -920,16 +978,10 @@ impl Reference { }); return action.or(Some(RefAction::Load(path))); }; - let Some(query) = query_for(game, cursor) else { + let Some(query) = query else { return action; }; let pos = query.position.clone(); - let exclude = source.filter(|(p, _)| *p == path).map(|(_, i)| i); - self.request(ui.ctx(), &path, &db, game, &query, exclude); - if self.job.is_some() || self.prepare.is_some() || self.book_job.is_some() { - ui.ctx() - .request_repaint_after(std::time::Duration::from_millis(100)); - } if let Some((p, job)) = &self.prepare && *p == path { @@ -971,56 +1023,6 @@ impl Reference { )); } ui.label(RichText::new(context).weak()); - // Theory: where the main line leaves the database (the line keeps its height - // while it is worked out, so nothing jumps). - let line = main_line(game); - let book = self.book_for(&path, &line).cloned(); - // The novelty: the first move of the game no other game of the database played - // (the line keeps its height while it is worked out, so nothing jumps). - let novelty = book.as_ref().and_then(|b| match b.last { - _ if b.to_the_end => None, - Some(last) => game.main_child(last), - None => game.main_child(game.root()), - }); - ui.horizontal(|ui| match (&book, novelty) { - _ if line.is_empty() => {} - (Some(_), Some(node)) => { - ui.label(RichText::new(tr("Novelty:")).weak()); - if ui - .link(node_label(game, node).unwrap_or_default()) - .on_hover_text(tr( - "The first move of this game that no other game of this database played; before it the game followed games of the database", - )) - .clicked() - { - action = Some(RefAction::Goto(node)); - } - } - (Some(_), None) => {} - // Still being worked out: an empty line of the same height, so the tables - // do not jump when the novelty appears. - (None, _) => { - ui.label(" "); - } - }); - // The game itself is in the database (maybe annotated there): open it. - if let Some(copy) = book - .as_ref() - .and_then(|b| b.copies.iter().find(|c| Some(**c) != exclude)) - { - ui.horizontal(|ui| { - ui.label(RichText::new(tr("This game is in the database")).weak()); - if ui - .link(tr("open it")) - .on_hover_text(tr( - "Open the copy of this game from the database at this position", - )) - .clicked() - { - action = Some(RefAction::OpenGame(path.clone(), *copy, pos.clone())); - } - }); - } ui.separator(); let current_key = key(&path, &query); let shown = self diff --git a/docs/design/reference.md b/docs/design/reference.md index eb8c5e0..7ff63df 100644 --- a/docs/design/reference.md +++ b/docs/design/reference.md @@ -4,7 +4,7 @@ ## Где -Вкладка в правой панели окна партии: `Нотация | Справочник | Отчёт` (не «Справка»: её читают как «Помощь») («Отчёт» — только когда есть анализ партии). Справочнику нужна ширина: у панели с открытым «Справочником» своя ширина по умолчанию — 55 % окна (а не 40 %, как у нотации); пользователь меняет её перетаскиванием, egui запоминает отдельно для каждой вкладки. +Вкладка в правой панели окна партии: `Нотация | Справочник | Отчёт` (не «Справка»: её читают как «Помощь») («Отчёт» — только когда есть анализ партии). Справочнику нужна ширина: у панели с открытым «Справочником» своя ширина — всё, что остаётся рядом с доской во всю высоту окна (у нотации — 40 %, не больше 460). Панель никогда не шире этого, доска не уменьшается; уже — можно, перетаскиванием (egui запоминает отдельно для каждой вкладки). ## Сверху: база и теория @@ -17,9 +17,8 @@ - Новинка: «Новинка: 14.Nf3» (ссылка) — первый ход партии, которого нет ни в одной другой партии базы; если такого хода нет (все ходы партии встречаются в базе), строки нет. Сама партия и её копии не считаются. Первые 12 полуходов проверяются по одному, дальше граница ищется удвоением и делением пополам (позиция почти всегда есть в базе, если в ней есть более поздняя позиция той же линии). Ответ сохраняется, пока партия удлиняется за его пределы; номера ходов у партий с FEN — от их начала. - Пока большая база строит индекс: «Ускоряю поиск по этой базе (один раз)… N %». -Под выбором базы: +В строке выбора базы, справа от него (появляются через мгновение и не занимают своей строки): «Новинка: 14.Bg5» и «Эта партия есть в базе — открыть». Под ней: - строка позиции: «Ход белых · после 4…Nc6 · в партии 5.Nb5»; -- новинка (пока считается, строка пустая, но держит высоту); - «Эта партия есть в базе — открыть», если в базе нашлась копия: партия с теми же игроками (фамилии) и годом, доходящая до финальной позиции этой. Тренеру ценно открыть, например, комментированную версию. У пустой партии копий и теории нет. Копии партии и сама партия (если она из этой базы) не входят в «теорию» и в таблицу партий; в счётчиках ходов остаются, как в ChessBase.