opening session: the line of moves to the board (block C) is back, by the owner's decision of 2026-11-27

This commit is contained in:
vrubelroman 2026-11-27 08:23:31 +03:00
parent 7cb0291e48
commit 3011bebd80
3 changed files with 46 additions and 2 deletions

View file

@ -1458,6 +1458,17 @@ impl OpeningSessionUi {
}
}
/// «1. e4 e5 2. Nf3» up to the position on the board; the asked move is not in it.
/// A wrong move on the board is not either: the line stays at the asked position.
fn path_text(&self) -> String {
let node = self.shown_node().or_else(|| {
let (game, asked) = self.expected_node()?;
Some((game, game.parent(asked)?))
});
node.map(|(game, node)| layout::path_text(game, node))
.unwrap_or_default()
}
/// The asked move's node in the PGN.
fn expected_node(&self) -> Option<(&Game, NodeId)> {
let target = self.session.current_target()?;
@ -1976,6 +1987,7 @@ impl OpeningSessionUi {
.shown_node()
.map(|(game, node)| layout::opening_text(game, node))
.unwrap_or_default();
let path = self.path_text();
let (left, right) = match state {
State::Summary => {
let more = self.more_new_count();
@ -2015,6 +2027,7 @@ impl OpeningSessionUi {
ui,
|ui| self.state_card(ui, state),
&opening,
&path,
|ui| {
if *state == State::Summary {
self.summary_body(ui);
@ -2238,6 +2251,7 @@ pub fn show_preparing(
)
},
"",
"",
|_| {},
Some((tr("Hint (H)").to_owned(), false)),
None,
@ -2338,6 +2352,7 @@ fn side_panel(
ui: &mut Ui,
card: impl FnOnce(&mut Ui),
opening: &str,
path: &str,
body: impl FnOnce(&mut Ui),
left: Option<(String, bool)>,
right: Option<(String, bool)>,
@ -2360,6 +2375,12 @@ fn side_panel(
layout::fixed_block(ui, LINE_H, |ui| {
layout::line(ui, RichText::new(opening).weak());
});
// C: the moves to the position on the board, cut on the left.
layout::fixed_block(ui, LINE_H, |ui| {
let font = egui::TextStyle::Body.resolve(ui.style());
let shown = layout::cut_left(ui, path, &font, ui.available_width());
ui.add(egui::Label::new(RichText::new(shown).weak()).truncate());
});
let rest = (ui.available_height() - ROW_H - GAP).max(0.0);
layout::fixed_block(ui, rest, body);
layout::fixed_block(ui, ROW_H, |ui| {

View file

@ -2231,3 +2231,26 @@ fn the_summary_shows_learning_growth_when_nothing_is_learned_yet() {
let summary = f.ui.summary.as_ref().unwrap();
assert_eq!((summary.learnt_gain, summary.learning_gain), (0, 2));
}
#[test]
fn the_line_shows_the_moves_to_the_board_without_the_asked_or_a_wrong_move() {
let mut f = Fixture::with(
"1. e4 e5 2. Nf3 Nc6 3. Bb5 *",
LearningSide::White,
&["e2e4", "g1f3", "f1b5"],
&[],
"path-line",
SessionKind::Daily,
);
let at = Instant::now();
tick_with_prime(&mut f.ui, at, Duration::ZERO, NOW);
assert_eq!(f.ui.path_text(), "");
answer_current(&mut f, at, NOW, "e4");
f.ui.debug_settle();
assert_eq!(f.ui.session.current_expected_uci(), Some("g1f3"));
assert_eq!(f.ui.path_text(), "1. e4 e5");
assert!(f.ui.play_uci_with_id_at("d2d4", "nf3-wrong".into(), at, NOW));
assert_eq!(f.ui.path_text(), "1. e4 e5");
tick_with_prime(&mut f.ui, at + WRONG_SHOWN, Duration::ZERO, NOW);
assert_eq!(f.ui.path_text(), "1. e4 e5");
}