2026-10-18 01:54:06 +03:00
|
|
|
|
//! Move list: main line as a two-column table (Lichess style), comments and variations
|
|
|
|
|
|
//! as full-width blocks between rows; nested variations inline in parentheses.
|
|
|
|
|
|
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
2026-10-18 01:54:06 +03:00
|
|
|
|
use crate::i18n::tr;
|
2026-10-28 01:00:29 +03:00
|
|
|
|
use crate::review::{Mark, judgement_name, judgement_symbol, judgement_text_color};
|
Translation of game comments
When a game's comments are in another language, ChessPenguin offers to translate
them into the reader's: with the ChatGPT Plus/Pro subscription (Sign in with
ChatGPT: OAuth with PKCE in the browser, a loopback callback, tokens refreshed
one at a time), or an OpenAI-compatible API key (DeepSeek, OpenAI, Gemini, a
model on this computer with Ollama or LM Studio, another address). After the
first consent, games in other languages are translated as they are opened;
[Original | Translation] (Ctrl+Shift+T) switches back.
Only comment text is sent; the model gets strict instructions and a glossary,
and every answer must keep the moves and squares of the original, or the
comment stays in the original with a mark. Translations are never written to
the PGN; a cache keeps them per language. Keys and tokens live in a 0600 file
apart from the settings. Settings › Translation holds the target language,
when to translate, the connection, permissions and the cache.
Also: the monospace font and three glyphs of Noto Sans Math are text fallbacks,
so arrows and the evaluation signs ⩲ ⩱ ⌓ no longer show as boxes.
Reviewed by the designer and the tester agents (two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:03:03 +03:00
|
|
|
|
use crate::translate_ui::Mark as Translated;
|
2026-10-18 11:45:13 +03:00
|
|
|
|
use chess_core::shakmaty::{Color, Position};
|
Android stage 0: the core opens databases without paths; the mobile-api bridge
chess-import opens a database from its content (PGN, zip, 7z, cbv) and a
ChessBase database from the contents of its files: Android hands over file
descriptors, not paths. The text of comments as shown moves to chess-core
(comment_display_text), so the phone and the desktop show the same.
crates/mobile-api: a thin UniFFI bridge — open a database from a descriptor, a
ChessBase folder's files, or a path (tests); game rows a page at a time; a game
as a tree of moves with positions, last-move squares, NAGs and comments. It
builds for arm64-v8a and x86_64 with cargo-ndk (NDK r30, API 31) and its Kotlin
bindings generate with `cargo run -p mobile-api --features bindgen --bin
uniffi-bindgen`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 00:43:54 +03:00
|
|
|
|
use chess_core::{Game, Nag, NodeId};
|
2026-10-18 01:54:06 +03:00
|
|
|
|
use egui::{Align2, Color32, FontId, RichText, Sense, Stroke, Ui, vec2};
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Notation<'a> {
|
|
|
|
|
|
pub game: &'a Game,
|
|
|
|
|
|
pub cursor: NodeId,
|
|
|
|
|
|
pub scroll_to_cursor: bool,
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
/// Engine assessments of main-line moves (whole-game analysis), shown apart from NAGs.
|
|
|
|
|
|
pub marks: Option<&'a HashMap<NodeId, Mark>>,
|
2026-10-18 11:45:13 +03:00
|
|
|
|
/// Engine line shown on the board: (start node, SAN moves, moves played so far).
|
|
|
|
|
|
pub preview: Option<(NodeId, &'a [String], usize)>,
|
Translation of game comments
When a game's comments are in another language, ChessPenguin offers to translate
them into the reader's: with the ChatGPT Plus/Pro subscription (Sign in with
ChatGPT: OAuth with PKCE in the browser, a loopback callback, tokens refreshed
one at a time), or an OpenAI-compatible API key (DeepSeek, OpenAI, Gemini, a
model on this computer with Ollama or LM Studio, another address). After the
first consent, games in other languages are translated as they are opened;
[Original | Translation] (Ctrl+Shift+T) switches back.
Only comment text is sent; the model gets strict instructions and a glossary,
and every answer must keep the moves and squares of the original, or the
comment stays in the original with a mark. Translations are never written to
the PGN; a cache keeps them per language. Keys and tokens live in a 0600 file
apart from the settings. Settings › Translation holds the target language,
when to translate, the connection, permissions and the cache.
Also: the monospace font and three glyphs of Noto Sans Math are text fallbacks,
so arrows and the evaluation signs ⩲ ⩱ ⌓ no longer show as boxes.
Reviewed by the designer and the tester agents (two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:03:03 +03:00
|
|
|
|
/// Translated comments by their original text (none: the original is shown).
|
|
|
|
|
|
pub translations: Option<&'a HashMap<String, Translated>>,
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// The comment being written, drawn where the comment stands (user-comments.md §3).
|
|
|
|
|
|
pub editor: Option<&'a mut CommentEditor>,
|
Play against Maia: dialog, clocks, game screen, result strip
«⚔ Play» (Ctrl+G) opens «Play against the computer»: name and rating
(optional), strength 600–2600 (or weaker/as me/stronger), colour, Lichess time
controls, custom, no clock. The game screen in play mode: clock cards above
and below the notation (read-only), take back, resign (abort before the first
moves); no engine, analysis or editing. Maia answers in a background thread
with a human-like pause bounded so she never loses on time; stale answers are
dropped. Endings: mate, stalemate, no material, threefold, fifty moves, time
(draw when the other side cannot mate), resignation; then the result strip
(Analyse, Rematch, New game, Save to a database) and an ordinary game with the
tags of a played game and [%clk]. Leaving during a game asks (resign and add /
resign and leave / keep playing), the clocks wait meanwhile. maia reads the
published PyTorch checkpoint directly (zip + a small pickle reader that refuses
everything but tensors); maia_download fetches it on request (pinned revision,
SHA-256). Dev hooks CP_PLAY, CP_PLAY_AUTO, CP_MAIA. Russian texts; the other
languages follow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 04:10:02 +03:00
|
|
|
|
/// A game being played: moves only show their position (no menus, no editing).
|
|
|
|
|
|
pub read_only: bool,
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
/// Main-line moves up to this ply are dimmed (the moves of the game a game against
|
|
|
|
|
|
/// Maia goes on from).
|
|
|
|
|
|
pub dim_until: Option<u32>,
|
|
|
|
|
|
/// Mistakes on main-line moves (learning an opening): how many, the move was shown.
|
|
|
|
|
|
pub mistakes: Option<&'a HashMap<NodeId, (u32, bool)>>,
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Result of a frame of the notation panel.
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
pub struct NotationResponse {
|
|
|
|
|
|
pub clicked: Option<NodeId>,
|
|
|
|
|
|
pub context: Option<(NodeId, NotationCommand)>,
|
2026-10-18 11:45:13 +03:00
|
|
|
|
/// A move of the better line of this marked move was clicked: (marked node, moves to show).
|
|
|
|
|
|
pub best: Option<(NodeId, usize)>,
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// Open the editor for this comment (a double click, the menu).
|
|
|
|
|
|
pub edit: Option<Slot>,
|
|
|
|
|
|
/// Delete this comment (the menu).
|
|
|
|
|
|
pub delete: Option<Slot>,
|
|
|
|
|
|
/// Put or take off this symbol on this move (the menu), at once.
|
|
|
|
|
|
pub nag: Option<(NodeId, Nag)>,
|
|
|
|
|
|
/// The editor's «Done» or «Cancel».
|
|
|
|
|
|
pub editor: Option<EditorOutcome>,
|
2026-10-25 03:22:51 +03:00
|
|
|
|
/// The engine line shown on the board goes into the game as a variation.
|
|
|
|
|
|
pub insert_preview: bool,
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
|
|
pub enum NotationCommand {
|
|
|
|
|
|
Promote,
|
|
|
|
|
|
Delete,
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
/// Paste a line from the clipboard (docs/design/paste-variation.md).
|
|
|
|
|
|
Paste,
|
|
|
|
|
|
/// A game against Maia from this position (docs/design/play-from-position.md).
|
|
|
|
|
|
PlayFrom,
|
|
|
|
|
|
/// Learn the opening up to this move (docs/design/opening-trainer.md).
|
|
|
|
|
|
Train,
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// Which comment of the game: after a move (`After(ROOT)`: the start of the game), or
|
|
|
|
|
|
/// before a move (an introduction to a line, only an existing one).
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
|
|
pub enum Slot {
|
|
|
|
|
|
After(NodeId),
|
|
|
|
|
|
Before(NodeId),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Slot {
|
|
|
|
|
|
pub fn node(self) -> NodeId {
|
|
|
|
|
|
match self {
|
|
|
|
|
|
Slot::After(id) | Slot::Before(id) => id,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
|
|
pub enum EditorOutcome {
|
|
|
|
|
|
Done,
|
|
|
|
|
|
Cancel,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A comment being written: its draft text and symbols (user-comments.md §3.4).
|
|
|
|
|
|
pub struct CommentEditor {
|
|
|
|
|
|
pub slot: Slot,
|
|
|
|
|
|
pub text: String,
|
|
|
|
|
|
/// The text as the editor opened (unchanged: the comment's bytes stay).
|
|
|
|
|
|
pub initial: String,
|
|
|
|
|
|
/// The draft symbols of the move (all of them; the two groups are toggled).
|
|
|
|
|
|
pub nags: Vec<Nag>,
|
|
|
|
|
|
pub initial_nags: Vec<Nag>,
|
|
|
|
|
|
/// «Comment after 4…Nf6», and its short form for a narrow panel.
|
|
|
|
|
|
pub title: String,
|
|
|
|
|
|
pub short_title: String,
|
|
|
|
|
|
/// A translation of this comment was on the screen: the original is edited.
|
|
|
|
|
|
pub translated: bool,
|
|
|
|
|
|
/// Put the keyboard into the field (on opening, on Enter from the game).
|
|
|
|
|
|
pub focus: bool,
|
|
|
|
|
|
/// Scroll the editor into view (on opening).
|
|
|
|
|
|
pub scroll: bool,
|
|
|
|
|
|
/// The text field's id, to know whether it has the keyboard.
|
|
|
|
|
|
pub field_id: Option<egui::Id>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl CommentEditor {
|
|
|
|
|
|
/// Something to write: the text or the symbols changed.
|
|
|
|
|
|
pub fn changed(&self) -> bool {
|
|
|
|
|
|
self.text.trim() != self.initial.trim() || self.nags != self.initial_nags
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn text_changed(&self) -> bool {
|
|
|
|
|
|
self.text.trim() != self.initial.trim()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The six symbols of a move and the eight of a position, as the editor and the move's
|
|
|
|
|
|
/// menu offer them (user-comments.md §3.4): (NAG, symbol, name).
|
|
|
|
|
|
pub const MOVE_NAGS: [(Nag, &str, &str); 6] = [
|
|
|
|
|
|
(Nag(1), "!", "Good move"),
|
|
|
|
|
|
(Nag(2), "?", "Mistake"),
|
|
|
|
|
|
(Nag(3), "!!", "Brilliant move"),
|
|
|
|
|
|
(Nag(4), "??", "Blunder"),
|
|
|
|
|
|
(Nag(5), "!?", "Interesting move"),
|
|
|
|
|
|
(Nag(6), "?!", "Dubious move"),
|
|
|
|
|
|
];
|
|
|
|
|
|
pub const POSITION_NAGS: [(Nag, &str, &str); 8] = [
|
|
|
|
|
|
(Nag(10), "=", "Equal position"),
|
|
|
|
|
|
(Nag(13), "∞", "Unclear position"),
|
|
|
|
|
|
(Nag(14), "⩲", "White is slightly better"),
|
|
|
|
|
|
(Nag(15), "⩱", "Black is slightly better"),
|
|
|
|
|
|
(Nag(16), "±", "White is better"),
|
|
|
|
|
|
(Nag(17), "∓", "Black is better"),
|
|
|
|
|
|
(Nag(18), "+−", "White is winning"),
|
|
|
|
|
|
(Nag(19), "−+", "Black is winning"),
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
fn is_position_nag(n: Nag) -> bool {
|
|
|
|
|
|
(10..=19).contains(&n.0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// `nag` put on or taken off `nags`: one symbol of its group (move or position) at a
|
|
|
|
|
|
/// time; the same symbol again takes it off; the other symbols stay.
|
|
|
|
|
|
pub fn toggle_nag(nags: &[Nag], nag: Nag) -> Vec<Nag> {
|
|
|
|
|
|
let same_group = |n: &Nag| {
|
|
|
|
|
|
if nag.is_move_assessment() {
|
|
|
|
|
|
n.is_move_assessment()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
is_position_nag(*n)
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
let had = nags
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.any(|n| *n == nag || (n.0 >= 10 && n.0 <= 12 && nag.0 == 10));
|
|
|
|
|
|
let mut out: Vec<Nag> = nags.iter().copied().filter(|n| !same_group(n)).collect();
|
|
|
|
|
|
if !had {
|
|
|
|
|
|
out.push(nag);
|
|
|
|
|
|
out.sort();
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The symbol of a group that is on: `=` for $10–$12.
|
|
|
|
|
|
fn group_current(nags: &[Nag], position: bool) -> Option<Nag> {
|
|
|
|
|
|
nags.iter()
|
|
|
|
|
|
.copied()
|
|
|
|
|
|
.find(|n| {
|
|
|
|
|
|
if position {
|
|
|
|
|
|
is_position_nag(*n)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
n.is_move_assessment()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.map(|n| if (10..=12).contains(&n.0) { Nag(10) } else { n })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-18 01:54:06 +03:00
|
|
|
|
const ROW_H: f32 = 26.0;
|
|
|
|
|
|
const NUM_W: f32 = 38.0;
|
2026-10-24 10:34:20 +03:00
|
|
|
|
/// A move's cell is no wider than this: in a wide panel (the notation under the board)
|
|
|
|
|
|
/// the two moves of a row stay together.
|
|
|
|
|
|
const CELL_MAX: f32 = 160.0;
|
2026-10-18 12:10:40 +03:00
|
|
|
|
/// Moves of an engine's better line shown under a marked move.
|
|
|
|
|
|
const MARK_LINE_MOVES: usize = 6;
|
2026-10-18 01:54:06 +03:00
|
|
|
|
|
|
|
|
|
|
impl Notation<'_> {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
pub fn show(mut self, ui: &mut Ui) -> NotationResponse {
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let mut out = NotationResponse::default();
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let mut editor = self.editor.take();
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let game = self.game;
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let editing = editor.as_ref().map(|e| e.slot);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let root_comments = comment_text(
|
|
|
|
|
|
game.node(NodeId::ROOT)
|
|
|
|
|
|
.map(|n| n.comments_after())
|
|
|
|
|
|
.unwrap_or(&[]),
|
|
|
|
|
|
);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
if editing == Some(Slot::After(NodeId::ROOT)) {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
editor_block(ui, &mut editor, false, &mut out);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
} else if !root_comments.is_empty() {
|
|
|
|
|
|
comment_block(
|
|
|
|
|
|
ui,
|
|
|
|
|
|
&self,
|
|
|
|
|
|
&root_comments,
|
|
|
|
|
|
Slot::After(NodeId::ROOT),
|
|
|
|
|
|
&mut out,
|
|
|
|
|
|
);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut row = Row::default();
|
|
|
|
|
|
let mut node = NodeId::ROOT;
|
|
|
|
|
|
while let Some(child) = game.main_child(node) {
|
|
|
|
|
|
let Some(n) = game.node(child) else { break };
|
|
|
|
|
|
let before = comment_text(n.comments_before());
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
if editing == Some(Slot::Before(child)) {
|
2026-10-18 01:54:06 +03:00
|
|
|
|
row.flush(ui, &self, &mut out);
|
2026-10-25 03:04:00 +03:00
|
|
|
|
editor_block(ui, &mut editor, false, &mut out);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
} else if !before.is_empty() {
|
|
|
|
|
|
row.flush(ui, &self, &mut out);
|
|
|
|
|
|
comment_block(ui, &self, &before, Slot::Before(child), &mut out);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
let (num, color) = game.move_number(child).unwrap_or((0, Color::White));
|
|
|
|
|
|
if color == Color::White {
|
|
|
|
|
|
row.flush(ui, &self, &mut out);
|
|
|
|
|
|
row.num = num;
|
|
|
|
|
|
row.white = Some(child);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if row.white.is_none() {
|
|
|
|
|
|
row.num = num;
|
|
|
|
|
|
}
|
|
|
|
|
|
row.black = Some(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
let after = comment_text(n.comments_after());
|
|
|
|
|
|
let vars = game.variations(node);
|
2026-10-28 01:00:29 +03:00
|
|
|
|
// A block under the move only for an error (its better line): !! and ! say
|
|
|
|
|
|
// all they have to say beside the move.
|
|
|
|
|
|
let mark = self
|
|
|
|
|
|
.marks
|
|
|
|
|
|
.and_then(|m| m.get(&child))
|
|
|
|
|
|
.filter(|m| m.judgement.is_error());
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let editing_after = editing == Some(Slot::After(child));
|
|
|
|
|
|
let interrupted = editing_after
|
|
|
|
|
|
|| !after.is_empty()
|
|
|
|
|
|
|| !vars.is_empty()
|
|
|
|
|
|
|| !n.unparsed().is_empty()
|
|
|
|
|
|
|| mark.is_some();
|
2026-10-18 01:54:06 +03:00
|
|
|
|
if interrupted || color == Color::Black {
|
|
|
|
|
|
row.flush(ui, &self, &mut out);
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
if let Some(mark) = mark {
|
2026-10-18 11:45:13 +03:00
|
|
|
|
mark_block(ui, &self, child, mark, &mut out);
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
}
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
if editing_after {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
editor_block(ui, &mut editor, false, &mut out);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
} else if !after.is_empty() {
|
|
|
|
|
|
comment_block(ui, &self, &after, Slot::After(child), &mut out);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
for u in n.unparsed() {
|
|
|
|
|
|
unparsed_block(ui, u);
|
|
|
|
|
|
}
|
|
|
|
|
|
for &v in vars {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
variation_block(ui, &self, v, &mut editor, &mut out);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
node = child;
|
|
|
|
|
|
}
|
|
|
|
|
|
row.flush(ui, &self, &mut out);
|
|
|
|
|
|
|
|
|
|
|
|
let result = game.result().as_str();
|
|
|
|
|
|
if result != "*" {
|
|
|
|
|
|
ui.add_space(6.0);
|
|
|
|
|
|
ui.vertical_centered(|ui| ui.label(RichText::new(result).strong().size(16.0)));
|
|
|
|
|
|
}
|
|
|
|
|
|
out
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
|
struct Row {
|
|
|
|
|
|
num: u32,
|
|
|
|
|
|
white: Option<NodeId>,
|
|
|
|
|
|
black: Option<NodeId>,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Row {
|
|
|
|
|
|
fn flush(&mut self, ui: &mut Ui, n: &Notation, out: &mut NotationResponse) {
|
|
|
|
|
|
if self.white.is_none() && self.black.is_none() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let width = ui.available_width();
|
|
|
|
|
|
let (rect, _) = ui.allocate_exact_size(vec2(width, ROW_H), Sense::hover());
|
|
|
|
|
|
let painter = ui.painter();
|
|
|
|
|
|
let visuals = ui.visuals();
|
|
|
|
|
|
painter.rect_filled(
|
|
|
|
|
|
egui::Rect::from_min_size(rect.min, vec2(NUM_W, ROW_H)),
|
|
|
|
|
|
0.0,
|
|
|
|
|
|
visuals.faint_bg_color,
|
|
|
|
|
|
);
|
|
|
|
|
|
painter.text(
|
|
|
|
|
|
rect.left_center() + vec2(NUM_W - 8.0, 0.0),
|
|
|
|
|
|
Align2::RIGHT_CENTER,
|
|
|
|
|
|
self.num.to_string(),
|
|
|
|
|
|
FontId::proportional(14.0),
|
|
|
|
|
|
visuals.weak_text_color(),
|
|
|
|
|
|
);
|
2026-10-24 10:34:20 +03:00
|
|
|
|
let cell_w = ((width - NUM_W) / 2.0).min(CELL_MAX);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let cells = [(self.white, 0.0), (self.black, cell_w)];
|
|
|
|
|
|
for (id, off) in cells {
|
|
|
|
|
|
let cell =
|
|
|
|
|
|
egui::Rect::from_min_size(rect.min + vec2(NUM_W + off, 0.0), vec2(cell_w, ROW_H));
|
|
|
|
|
|
match id {
|
|
|
|
|
|
Some(id) => {
|
|
|
|
|
|
let resp = ui.interact(cell, ui.id().with(("mv", id.index())), Sense::click());
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
let dim = n
|
|
|
|
|
|
.dim_until
|
|
|
|
|
|
.is_some_and(|p| n.game.node(id).is_some_and(|nd| nd.ply() <= p));
|
2026-10-28 01:00:29 +03:00
|
|
|
|
let mark = n.marks.and_then(|m| m.get(&id));
|
|
|
|
|
|
let text_right = paint_move_cell(
|
|
|
|
|
|
ui,
|
|
|
|
|
|
cell,
|
|
|
|
|
|
n.game,
|
|
|
|
|
|
id,
|
|
|
|
|
|
mark,
|
|
|
|
|
|
id == n.cursor,
|
|
|
|
|
|
resp.hovered(),
|
|
|
|
|
|
dim,
|
|
|
|
|
|
);
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
if let Some(&(count, shown)) = n.mistakes.and_then(|m| m.get(&id)) {
|
|
|
|
|
|
let color = if shown {
|
|
|
|
|
|
ui.visuals().warn_fg_color
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ui.visuals().error_fg_color
|
|
|
|
|
|
};
|
|
|
|
|
|
// A pill right after the move: its own, readable on the selected one.
|
|
|
|
|
|
let galley = ui.painter().layout_no_wrap(
|
|
|
|
|
|
format!("×{count}"),
|
|
|
|
|
|
FontId::proportional(12.0),
|
|
|
|
|
|
Color32::WHITE,
|
|
|
|
|
|
);
|
|
|
|
|
|
let pill = egui::Rect::from_min_size(
|
|
|
|
|
|
egui::pos2(
|
|
|
|
|
|
text_right + 4.0,
|
|
|
|
|
|
cell.center().y - galley.size().y / 2.0 - 1.0,
|
|
|
|
|
|
),
|
|
|
|
|
|
galley.size() + vec2(8.0, 2.0),
|
|
|
|
|
|
);
|
|
|
|
|
|
ui.painter().rect_filled(pill, 7.0, color);
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.galley(pill.min + vec2(4.0, 1.0), galley, Color32::WHITE);
|
|
|
|
|
|
let tip = if shown {
|
|
|
|
|
|
crate::i18n::trf("Mistakes: {n}; the move was shown", &[("n", &count)])
|
|
|
|
|
|
} else {
|
|
|
|
|
|
crate::i18n::trf("Mistakes on this move: {n}", &[("n", &count)])
|
|
|
|
|
|
};
|
|
|
|
|
|
resp.clone().on_hover_text(tip);
|
|
|
|
|
|
}
|
2026-10-18 01:54:06 +03:00
|
|
|
|
handle_move_response(ui, &resp, n, id, out);
|
|
|
|
|
|
}
|
|
|
|
|
|
None => {
|
|
|
|
|
|
ui.painter().text(
|
|
|
|
|
|
cell.left_center() + vec2(10.0, 0.0),
|
|
|
|
|
|
Align2::LEFT_CENTER,
|
|
|
|
|
|
"…",
|
|
|
|
|
|
FontId::proportional(15.0),
|
|
|
|
|
|
ui.visuals().weak_text_color(),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*self = Row::default();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_move_response(
|
|
|
|
|
|
ui: &Ui,
|
|
|
|
|
|
resp: &egui::Response,
|
|
|
|
|
|
n: &Notation,
|
|
|
|
|
|
id: NodeId,
|
|
|
|
|
|
out: &mut NotationResponse,
|
|
|
|
|
|
) {
|
|
|
|
|
|
if resp.clicked() {
|
|
|
|
|
|
out.clicked = Some(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
if n.scroll_to_cursor && id == n.cursor {
|
|
|
|
|
|
resp.scroll_to_me(Some(egui::Align::Center));
|
|
|
|
|
|
}
|
|
|
|
|
|
let is_variation = n.game.child_index(id).is_some_and(|i| i > 0) || !n.game.is_mainline(id);
|
Play against Maia: dialog, clocks, game screen, result strip
«⚔ Play» (Ctrl+G) opens «Play against the computer»: name and rating
(optional), strength 600–2600 (or weaker/as me/stronger), colour, Lichess time
controls, custom, no clock. The game screen in play mode: clock cards above
and below the notation (read-only), take back, resign (abort before the first
moves); no engine, analysis or editing. Maia answers in a background thread
with a human-like pause bounded so she never loses on time; stale answers are
dropped. Endings: mate, stalemate, no material, threefold, fifty moves, time
(draw when the other side cannot mate), resignation; then the result strip
(Analyse, Rematch, New game, Save to a database) and an ordinary game with the
tags of a played game and [%clk]. Leaving during a game asks (resign and add /
resign and leave / keep playing), the clocks wait meanwhile. maia reads the
published PyTorch checkpoint directly (zip + a small pickle reader that refuses
everything but tensors); maia_download fetches it on request (pinned revision,
SHA-256). Dev hooks CP_PLAY, CP_PLAY_AUTO, CP_MAIA. Russian texts; the other
languages follow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 04:10:02 +03:00
|
|
|
|
if n.read_only {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
// The menu is about the move it opens on: the move becomes the current one.
|
|
|
|
|
|
if resp.secondary_clicked() && id != n.cursor {
|
|
|
|
|
|
out.clicked = Some(id);
|
|
|
|
|
|
}
|
2026-10-18 01:54:06 +03:00
|
|
|
|
resp.context_menu(|ui| {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let node = n.game.node(id);
|
|
|
|
|
|
let has_comment = node.is_some_and(|nd| !comment_text(nd.comments_after()).is_empty());
|
|
|
|
|
|
let label = if has_comment {
|
|
|
|
|
|
tr("Edit comment…")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tr("Comment…")
|
|
|
|
|
|
};
|
|
|
|
|
|
if ui
|
|
|
|
|
|
.add(egui::Button::new(label).shortcut_text("Enter"))
|
|
|
|
|
|
.clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
out.edit = Some(Slot::After(id));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
if has_comment && ui.button(tr("Delete comment")).clicked() {
|
|
|
|
|
|
out.delete = Some(Slot::After(id));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
// The symbols act at once and keep the menu open: «?» off, «?!» on.
|
|
|
|
|
|
let nags = node.map(|nd| nd.nags().to_vec()).unwrap_or_default();
|
|
|
|
|
|
symbol_row(ui, &nags, &MOVE_NAGS, true, &mut |nag| {
|
|
|
|
|
|
out.nag = Some((id, nag))
|
|
|
|
|
|
});
|
|
|
|
|
|
symbol_row(ui, &nags, &POSITION_NAGS, false, &mut |nag| {
|
|
|
|
|
|
out.nag = Some((id, nag))
|
|
|
|
|
|
});
|
|
|
|
|
|
if n.game.main_child(NodeId::ROOT) == Some(id) {
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
if ui.button(tr("Comment at the start of the game…")).clicked() {
|
|
|
|
|
|
out.edit = Some(Slot::After(NodeId::ROOT));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.separator();
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
if ui
|
|
|
|
|
|
.add(egui::Button::new(tr("Paste a line from the clipboard")).shortcut_text("Ctrl+V"))
|
|
|
|
|
|
.on_hover_text(tr(
|
|
|
|
|
|
"Moves or a PGN game from the clipboard, as a variation from where they part from this game",
|
|
|
|
|
|
))
|
|
|
|
|
|
.clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
out.context = Some((id, NotationCommand::Paste));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
2026-10-18 01:54:06 +03:00
|
|
|
|
if is_variation && ui.button(tr("Make main line")).clicked() {
|
|
|
|
|
|
out.context = Some((id, NotationCommand::Promote));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
if ui.button(tr("Delete move and continuation")).clicked() {
|
|
|
|
|
|
out.context = Some((id, NotationCommand::Delete));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
ui.separator();
|
|
|
|
|
|
// A finished position has nothing to play.
|
|
|
|
|
|
let over = n.game.position(id).and_then(|p| {
|
|
|
|
|
|
if p.is_checkmate() {
|
|
|
|
|
|
Some(tr("checkmate"))
|
|
|
|
|
|
} else if p.is_stalemate() {
|
|
|
|
|
|
Some(tr("stalemate"))
|
|
|
|
|
|
} else if p.is_insufficient_material() {
|
|
|
|
|
|
Some(tr("neither side can checkmate"))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
None
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
let play = ui
|
|
|
|
|
|
.add_enabled(
|
|
|
|
|
|
over.is_none(),
|
|
|
|
|
|
egui::Button::new(tr("Play on from here…")).shortcut_text("Ctrl+G"),
|
|
|
|
|
|
)
|
2026-10-26 03:39:04 +03:00
|
|
|
|
.on_hover_text(tr("A game against the computer from this position"));
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
let play = match over {
|
|
|
|
|
|
Some(why) => play.on_disabled_hover_text(crate::i18n::trf(
|
|
|
|
|
|
"The game is over here: {why}",
|
|
|
|
|
|
&[("why", &why)],
|
|
|
|
|
|
)),
|
|
|
|
|
|
None => play,
|
|
|
|
|
|
};
|
|
|
|
|
|
if play.clicked() {
|
|
|
|
|
|
out.context = Some((id, NotationCommand::PlayFrom));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
// Learning the opening: the runs of this line so far on the right.
|
|
|
|
|
|
let runs = crate::train::runs_to(n.game, id);
|
|
|
|
|
|
let label = runs
|
|
|
|
|
|
.filter(|&r| r > 0)
|
|
|
|
|
|
.map(|r| crate::i18n::trf("runs: {n}", &[("n", &r)]))
|
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
let learn = ui
|
|
|
|
|
|
.add_enabled(
|
|
|
|
|
|
runs.is_some(),
|
|
|
|
|
|
egui::Button::new(tr("Learn the opening up to this move")).shortcut_text(label),
|
|
|
|
|
|
)
|
|
|
|
|
|
.on_hover_text(tr(
|
|
|
|
|
|
"Replay from memory the moves of both sides from the start of the game up to this move",
|
|
|
|
|
|
))
|
|
|
|
|
|
.on_disabled_hover_text(tr(
|
|
|
|
|
|
"The line has a null move (--): it cannot be played on the board",
|
|
|
|
|
|
));
|
|
|
|
|
|
if learn.clicked() {
|
|
|
|
|
|
out.context = Some((id, NotationCommand::Train));
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
2026-10-18 01:54:06 +03:00
|
|
|
|
});
|
|
|
|
|
|
let _ = ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// A row of symbol toggles: the one on is pressed; `on` gets the symbol clicked.
|
|
|
|
|
|
fn symbol_row(
|
|
|
|
|
|
ui: &mut Ui,
|
|
|
|
|
|
nags: &[Nag],
|
|
|
|
|
|
set: &[(Nag, &str, &'static str)],
|
|
|
|
|
|
moves: bool,
|
|
|
|
|
|
on: &mut dyn FnMut(Nag),
|
2026-10-25 03:04:00 +03:00
|
|
|
|
) {
|
|
|
|
|
|
symbol_row_sized(ui, nags, set, moves, SYMBOL_W, on);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A symbol button's width; the gap between them.
|
|
|
|
|
|
const SYMBOL_W: f32 = 24.0;
|
|
|
|
|
|
const SYMBOL_GAP: f32 = 2.0;
|
|
|
|
|
|
|
|
|
|
|
|
/// `symbol_row` with buttons `w` wide (narrower in a narrow panel). The pressed symbol
|
|
|
|
|
|
/// is drawn in the selection's text colour, not its own: on the selection fill the
|
|
|
|
|
|
/// assessment colours read badly.
|
|
|
|
|
|
fn symbol_row_sized(
|
|
|
|
|
|
ui: &mut Ui,
|
|
|
|
|
|
nags: &[Nag],
|
|
|
|
|
|
set: &[(Nag, &str, &'static str)],
|
|
|
|
|
|
moves: bool,
|
|
|
|
|
|
w: f32,
|
|
|
|
|
|
on: &mut dyn FnMut(Nag),
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
) {
|
|
|
|
|
|
let current = group_current(nags, !moves);
|
|
|
|
|
|
ui.horizontal(|ui| {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
ui.spacing_mut().item_spacing.x = if w < SYMBOL_W { 1.0 } else { SYMBOL_GAP };
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
for (nag, sym, name) in set {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
let pressed = current == Some(*nag);
|
|
|
|
|
|
let mut text = RichText::new(*sym).size(if w < SYMBOL_W { 14.0 } else { 15.0 });
|
|
|
|
|
|
if pressed {
|
|
|
|
|
|
text = text.strong().color(ui.visuals().selection.stroke.color);
|
|
|
|
|
|
} else if moves && let Some(c) = assessment_color(*nag) {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
text = text.color(c);
|
|
|
|
|
|
}
|
|
|
|
|
|
let r = ui
|
2026-10-25 03:04:00 +03:00
|
|
|
|
.add_sized([w, 24.0], egui::Button::selectable(pressed, text))
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
.on_hover_text(symbol_hint(*nag, name));
|
|
|
|
|
|
if r.clicked() {
|
|
|
|
|
|
on(*nag);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// «Good move (Ctrl+1)».
|
|
|
|
|
|
fn symbol_hint(nag: Nag, name: &'static str) -> String {
|
|
|
|
|
|
if nag.is_move_assessment() {
|
|
|
|
|
|
format!("{} (Ctrl+{})", tr(name), nag.0)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
tr(name).to_owned()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-28 01:00:29 +03:00
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
2026-10-18 01:54:06 +03:00
|
|
|
|
fn paint_move_cell(
|
|
|
|
|
|
ui: &Ui,
|
|
|
|
|
|
cell: egui::Rect,
|
|
|
|
|
|
game: &Game,
|
|
|
|
|
|
id: NodeId,
|
2026-10-28 01:00:29 +03:00
|
|
|
|
mark: Option<&Mark>,
|
2026-10-18 01:54:06 +03:00
|
|
|
|
current: bool,
|
|
|
|
|
|
hovered: bool,
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
dim: bool,
|
|
|
|
|
|
) -> f32 {
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let visuals = ui.visuals();
|
|
|
|
|
|
if current {
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.rect_filled(cell, 2.0, visuals.selection.bg_fill);
|
|
|
|
|
|
} else if hovered {
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.rect_filled(cell, 2.0, visuals.widgets.hovered.weak_bg_fill);
|
|
|
|
|
|
}
|
|
|
|
|
|
let node = game.node(id);
|
|
|
|
|
|
let san = game.game_move(id).map(|m| m.san.as_str()).unwrap_or("?");
|
Move notation: Latin letters, figurines or the interface language's letters
Settings › Board & pieces: Nf3, ♘f3 as on Lichess, or Кр Ф Л С К (German
K D T L S, French R D T F C, Spanish and Italian R D T A C; in English the
Latin letters), with a sample per option and a line of a game. Only the shown
label changes (san::show): the game, PGN, copied games, the analysis written
into a game, the reference cache and every comparison stay Latin SAN. Applied
in the move list, engine lines, the reference tab, board search and the
analysis report. The figurines are egui's chess glyphs cut out to a 4.7 KB
font, a little smaller and on the baseline. Latin remains the default.
Reviewed by the designer and the tester agents.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:18:53 +03:00
|
|
|
|
let san = crate::san::show(san);
|
2026-10-28 01:00:29 +03:00
|
|
|
|
let (mut sym, mut color) = node
|
2026-10-18 01:54:06 +03:00
|
|
|
|
.map(|n| move_glyph(n.nags()))
|
|
|
|
|
|
.unwrap_or((String::new(), None));
|
2026-10-28 01:00:29 +03:00
|
|
|
|
// The engine's verdict right after the move, the move in its color (as on Lichess);
|
|
|
|
|
|
// the author's own sign stands instead when there is one.
|
|
|
|
|
|
let authored = node.is_some_and(|n| n.nags().iter().any(|g| g.is_move_assessment()));
|
|
|
|
|
|
if let Some(m) = mark
|
|
|
|
|
|
&& !authored
|
|
|
|
|
|
{
|
|
|
|
|
|
sym.insert_str(0, judgement_symbol(m.judgement));
|
|
|
|
|
|
color = Some(judgement_text_color(m.judgement, visuals.dark_mode));
|
|
|
|
|
|
}
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let text_color = if current {
|
|
|
|
|
|
visuals.selection.stroke.color
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
} else if dim {
|
|
|
|
|
|
visuals.weak_text_color()
|
2026-10-18 01:54:06 +03:00
|
|
|
|
} else {
|
|
|
|
|
|
color.unwrap_or(visuals.text_color())
|
|
|
|
|
|
};
|
Paste a line, play on from here, learn the opening
Paste a line from the clipboard (Ctrl+V on a game, the move menu, ☰):
chess-core paste.rs plans where the text fits without touching the game — a
PGN game where its moves part from this one along any branch, or where one of
its positions occurs (another move order, noted); a fragment (SAN, numbered
or not, «…» for black, UCI) after the selected move, instead of it, or at its
move number — and grafts the new moves with their comments, symbols and
variations (the pasted game's alternatives along the way too) as one undo
step, the players' names after the line. A game with no position in common
is refused with a message; a line going elsewhere than the selected move is
asked about; an impossible move inserts nothing.
Play on from here (the move menu, Ctrl+G on a game, ☰): the play dialog shows
the position on a small board and the game it comes from; the new game holds
the moves up to it (Maia sees the history, repetitions count), dimmed during
play, with a comment saying where it comes from; take-backs, abort and resign
count only the new moves; the source game waits under it («⬅ Back to the
game»); the side to move plays by default, a rematch keeps the colour.
Learn the opening up to this move (the move menu, ☰): a training screen over
the game; the user plays both sides; a wrong move is counted, shown for
400 ms in red with a short sound and taken back; from the third mistake on a
move «Show the move» puts an arrow (the run marked with a hint); at the end
the mistakes by move, the line's runs (last, best, clean in a row, recent),
«Again» (Enter). Runs are kept in training.json by the line (start position
and moves), shared between games; an entry or a file that does not read is
kept aside, not lost. New sounds Wrong (Kenney, CC0) and Success (Lichess
Victory, Kenney).
Keys of the game do nothing under a modal question or dialog. Dev hooks
CP_PASTE_LINE, CP_PLAY_FROM, CP_TRAIN, CP_TRAIN_MOVES, CP_TRAIN_KEEP,
CP_TRAINING_FILE. Texts in nine languages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:51:09 +03:00
|
|
|
|
ui.painter()
|
|
|
|
|
|
.text(
|
|
|
|
|
|
cell.left_center() + vec2(10.0, 0.0),
|
|
|
|
|
|
Align2::LEFT_CENTER,
|
|
|
|
|
|
format!("{san}{sym}"),
|
|
|
|
|
|
FontId::proportional(16.0),
|
|
|
|
|
|
text_color,
|
|
|
|
|
|
)
|
|
|
|
|
|
.right()
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-18 11:45:13 +03:00
|
|
|
|
/// "Mistake. Best: 23…Nf6 24.Nd5 …" under a marked main-line move. Each move opens the line
|
|
|
|
|
|
/// on the board up to it; the move shown on the board is highlighted like the game cursor.
|
|
|
|
|
|
fn mark_block(ui: &mut Ui, n: &Notation, id: NodeId, mark: &Mark, out: &mut NotationResponse) {
|
2026-10-28 00:47:44 +03:00
|
|
|
|
let color = judgement_text_color(mark.judgement, ui.visuals().dark_mode);
|
2026-10-18 11:45:13 +03:00
|
|
|
|
let start = n
|
|
|
|
|
|
.game
|
|
|
|
|
|
.position(mark.base)
|
|
|
|
|
|
.map(|p| (p.fullmoves().get(), p.turn()));
|
|
|
|
|
|
let shown = n
|
|
|
|
|
|
.preview
|
|
|
|
|
|
.filter(|(base, san, _)| *base == mark.base && *san == mark.best_san.as_slice())
|
|
|
|
|
|
.map(|(_, _, shown)| shown);
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
egui::Frame::new()
|
|
|
|
|
|
.fill(ui.visuals().extreme_bg_color)
|
|
|
|
|
|
.inner_margin(egui::Margin {
|
|
|
|
|
|
left: 10,
|
|
|
|
|
|
right: 10,
|
|
|
|
|
|
top: 3,
|
|
|
|
|
|
bottom: 3,
|
|
|
|
|
|
})
|
|
|
|
|
|
.stroke(Stroke::new(1.0, color.gamma_multiply(0.6)))
|
|
|
|
|
|
.show(ui, |ui| {
|
|
|
|
|
|
ui.set_width(ui.available_width());
|
|
|
|
|
|
ui.horizontal_wrapped(|ui| {
|
2026-10-18 11:45:13 +03:00
|
|
|
|
ui.spacing_mut().item_spacing = vec2(3.0, 2.0);
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
ui.label(
|
|
|
|
|
|
RichText::new(format!("{}.", judgement_name(mark.judgement)))
|
|
|
|
|
|
.color(color)
|
|
|
|
|
|
.strong(),
|
|
|
|
|
|
);
|
2026-10-18 11:45:13 +03:00
|
|
|
|
if mark.best_san.is_empty() {
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-10-18 11:45:13 +03:00
|
|
|
|
ui.label(RichText::new(tr("Best:")).weak());
|
2026-10-18 12:10:40 +03:00
|
|
|
|
// Short by default; grows while the line is stepped through on the board.
|
|
|
|
|
|
let visible = MARK_LINE_MOVES.max(shown.unwrap_or(0));
|
|
|
|
|
|
for (i, san) in mark.best_san.iter().enumerate().take(visible) {
|
2026-10-18 11:45:13 +03:00
|
|
|
|
let label = match start {
|
|
|
|
|
|
Some((num, turn)) => {
|
|
|
|
|
|
let ply = i as u32 + u32::from(turn == Color::Black);
|
|
|
|
|
|
let num = num + ply / 2;
|
|
|
|
|
|
if ply.is_multiple_of(2) {
|
|
|
|
|
|
format!("{num}.{san}")
|
|
|
|
|
|
} else if i == 0 {
|
|
|
|
|
|
format!("{num}…{san}")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
san.clone()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
None => san.clone(),
|
|
|
|
|
|
};
|
Move notation: Latin letters, figurines or the interface language's letters
Settings › Board & pieces: Nf3, ♘f3 as on Lichess, or Кр Ф Л С К (German
K D T L S, French R D T F C, Spanish and Italian R D T A C; in English the
Latin letters), with a sample per option and a line of a game. Only the shown
label changes (san::show): the game, PGN, copied games, the analysis written
into a game, the reference cache and every comparison stay Latin SAN. Applied
in the move list, engine lines, the reference tab, board search and the
analysis report. The figurines are egui's chess glyphs cut out to a 4.7 KB
font, a little smaller and on the baseline. Latin remains the default.
Reviewed by the designer and the tester agents.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:18:53 +03:00
|
|
|
|
let label = crate::san::show(&label).into_owned();
|
2026-10-18 11:45:13 +03:00
|
|
|
|
let current = shown == Some(i + 1);
|
2026-10-25 03:17:11 +03:00
|
|
|
|
let resp = move_chip(ui, &label, None, current)
|
2026-10-18 11:45:13 +03:00
|
|
|
|
.on_hover_text(tr("Show this line on the board"));
|
|
|
|
|
|
if current && n.scroll_to_cursor {
|
|
|
|
|
|
resp.scroll_to_me(Some(egui::Align::Center));
|
|
|
|
|
|
}
|
|
|
|
|
|
if resp.clicked() {
|
|
|
|
|
|
out.best = Some((id, i + 1));
|
|
|
|
|
|
}
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
}
|
2026-10-18 12:10:40 +03:00
|
|
|
|
if mark.best_san.len() > visible {
|
|
|
|
|
|
ui.label(RichText::new("…").weak());
|
|
|
|
|
|
}
|
2026-10-25 03:22:51 +03:00
|
|
|
|
// The line being stepped through on the board: added from here (there is
|
|
|
|
|
|
// no separate strip for it).
|
|
|
|
|
|
if shown.is_some()
|
|
|
|
|
|
&& ui
|
|
|
|
|
|
.small_button(tr("+ Add as variation"))
|
|
|
|
|
|
.on_hover_text(tr(
|
|
|
|
|
|
"Puts the line into the game as a variation (Ctrl+Z to undo)",
|
|
|
|
|
|
))
|
|
|
|
|
|
.clicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
out.insert_preview = true;
|
|
|
|
|
|
}
|
Game analysis: whole-game engine review with graph, report and notation marks
- Separate background engine job over the main line (go nodes N), live engine
paused meanwhile; header button with progress/cancel, Shift+A.
- Lichess-method metrics: win %, move/game accuracy, inaccuracy/mistake/blunder,
ACPL, accuracy per game phase.
- Evaluation graph under the board, Report tab, engine badges and better lines
in the notation (preview on click), launch dialog with quality/threads/memory
and time estimate.
- Results cached in ~/.cache/chesspenguin/analysis; [%eval] read from PGN.
- Write analysis to the game as one undo step (chess-core: Game::annotate,
Game::edit_group).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 11:03:23 +03:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-18 14:00:19 +03:00
|
|
|
|
/// Colour of a move-assessment NAG ($1-$6), the Lichess palette.
|
|
|
|
|
|
pub fn assessment_color(nag: Nag) -> Option<Color32> {
|
|
|
|
|
|
Some(match nag.0 {
|
|
|
|
|
|
1 => Color32::from_rgb(0x62, 0x9c, 0x2e),
|
|
|
|
|
|
2 => Color32::from_rgb(0xe6, 0x8f, 0x00),
|
|
|
|
|
|
3 => Color32::from_rgb(0x22, 0xac, 0x9a),
|
|
|
|
|
|
4 => Color32::from_rgb(0xdf, 0x53, 0x53),
|
|
|
|
|
|
5 => Color32::from_rgb(0xea, 0x45, 0xd8),
|
|
|
|
|
|
6 => Color32::from_rgb(0x56, 0xb4, 0xe9),
|
|
|
|
|
|
_ => return None,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-18 01:54:06 +03:00
|
|
|
|
/// Move-assessment glyph (`!`, `?`, …) with its color, plus position assessments.
|
|
|
|
|
|
fn move_glyph(nags: &[Nag]) -> (String, Option<Color32>) {
|
|
|
|
|
|
let mut s = String::new();
|
|
|
|
|
|
let mut color = None;
|
|
|
|
|
|
for nag in nags {
|
|
|
|
|
|
let Some(sym) = nag.symbol() else {
|
|
|
|
|
|
s.push_str(&format!(" ${}", nag.0));
|
|
|
|
|
|
continue;
|
|
|
|
|
|
};
|
|
|
|
|
|
if nag.is_move_assessment() {
|
2026-10-18 14:00:19 +03:00
|
|
|
|
let Some(c) = assessment_color(*nag) else {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
};
|
|
|
|
|
|
color = Some(c);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
s.push_str(sym);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
s.push(' ');
|
|
|
|
|
|
s.push_str(sym);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
(s, color)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Android stage 0: the core opens databases without paths; the mobile-api bridge
chess-import opens a database from its content (PGN, zip, 7z, cbv) and a
ChessBase database from the contents of its files: Android hands over file
descriptors, not paths. The text of comments as shown moves to chess-core
(comment_display_text), so the phone and the desktop show the same.
crates/mobile-api: a thin UniFFI bridge — open a database from a descriptor, a
ChessBase folder's files, or a path (tests); game rows a page at a time; a game
as a tree of moves with positions, last-move squares, NAGs and comments. It
builds for arm64-v8a and x86_64 with cargo-ndk (NDK r30, API 31) and its Kotlin
bindings generate with `cargo run -p mobile-api --features bindgen --bin
uniffi-bindgen`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 00:43:54 +03:00
|
|
|
|
/// The text of comments as shown (see [`chess_core::comment_display_text`]).
|
Translation of game comments
When a game's comments are in another language, ChessPenguin offers to translate
them into the reader's: with the ChatGPT Plus/Pro subscription (Sign in with
ChatGPT: OAuth with PKCE in the browser, a loopback callback, tokens refreshed
one at a time), or an OpenAI-compatible API key (DeepSeek, OpenAI, Gemini, a
model on this computer with Ollama or LM Studio, another address). After the
first consent, games in other languages are translated as they are opened;
[Original | Translation] (Ctrl+Shift+T) switches back.
Only comment text is sent; the model gets strict instructions and a glossary,
and every answer must keep the moves and squares of the original, or the
comment stays in the original with a mark. Translations are never written to
the PGN; a cache keeps them per language. Keys and tokens live in a 0600 file
apart from the settings. Settings › Translation holds the target language,
when to translate, the connection, permissions and the cache.
Also: the monospace font and three glyphs of Noto Sans Math are text fallbacks,
so arrows and the evaluation signs ⩲ ⩱ ⌓ no longer show as boxes.
Reviewed by the designer and the tester agents (two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:03:03 +03:00
|
|
|
|
pub fn comment_text(comments: &[String]) -> String {
|
Android stage 0: the core opens databases without paths; the mobile-api bridge
chess-import opens a database from its content (PGN, zip, 7z, cbv) and a
ChessBase database from the contents of its files: Android hands over file
descriptors, not paths. The text of comments as shown moves to chess-core
(comment_display_text), so the phone and the desktop show the same.
crates/mobile-api: a thin UniFFI bridge — open a database from a descriptor, a
ChessBase folder's files, or a path (tests); game rows a page at a time; a game
as a tree of moves with positions, last-move squares, NAGs and comments. It
builds for arm64-v8a and x86_64 with cargo-ndk (NDK r30, API 31) and its Kotlin
bindings generate with `cargo run -p mobile-api --features bindgen --bin
uniffi-bindgen`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 00:43:54 +03:00
|
|
|
|
chess_core::comment_display_text(comments)
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn block_frame(ui: &Ui) -> egui::Frame {
|
|
|
|
|
|
egui::Frame::new()
|
|
|
|
|
|
.fill(ui.visuals().extreme_bg_color)
|
|
|
|
|
|
.inner_margin(egui::Margin::symmetric(10, 6))
|
|
|
|
|
|
.stroke(Stroke::new(
|
|
|
|
|
|
1.0,
|
|
|
|
|
|
ui.visuals().widgets.noninteractive.bg_stroke.color,
|
|
|
|
|
|
))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Translation of game comments
When a game's comments are in another language, ChessPenguin offers to translate
them into the reader's: with the ChatGPT Plus/Pro subscription (Sign in with
ChatGPT: OAuth with PKCE in the browser, a loopback callback, tokens refreshed
one at a time), or an OpenAI-compatible API key (DeepSeek, OpenAI, Gemini, a
model on this computer with Ollama or LM Studio, another address). After the
first consent, games in other languages are translated as they are opened;
[Original | Translation] (Ctrl+Shift+T) switches back.
Only comment text is sent; the model gets strict instructions and a glossary,
and every answer must keep the moves and squares of the original, or the
comment stays in the original with a mark. Translations are never written to
the PGN; a cache keeps them per language. Keys and tokens live in a 0600 file
apart from the settings. Settings › Translation holds the target language,
when to translate, the connection, permissions and the cache.
Also: the monospace font and three glyphs of Noto Sans Math are text fallbacks,
so arrows and the evaluation signs ⩲ ⩱ ⌓ no longer show as boxes.
Reviewed by the designer and the tester agents (two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:03:03 +03:00
|
|
|
|
/// The text to show for a comment and its translation mark.
|
|
|
|
|
|
fn translated<'a>(n: &'a Notation, text: &'a str) -> (&'a str, Option<&'a Translated>) {
|
|
|
|
|
|
match n.translations.and_then(|t| t.get(text)) {
|
|
|
|
|
|
Some(m @ Translated::Translated(t)) => (t.as_str(), Some(m)),
|
|
|
|
|
|
m => (text, m),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// "⇄" (machine translation, the original in the tooltip), "⋯" (on its way), "⚠" (failed).
|
2026-10-21 23:00:20 +03:00
|
|
|
|
/// "⇄" (machine translation, the original in the tooltip), "⋯" (on its way), "⚠" (failed),
|
|
|
|
|
|
/// drawn at `at` without taking part in the layout (it may not widen the panel).
|
|
|
|
|
|
fn translation_mark(ui: &mut Ui, at: egui::Pos2, mark: &Translated, original: &str) {
|
|
|
|
|
|
let (sym, color, tip, name) = mark_info(ui, mark, original);
|
|
|
|
|
|
let rect = ui.painter().text(
|
|
|
|
|
|
at,
|
|
|
|
|
|
Align2::RIGHT_TOP,
|
|
|
|
|
|
sym,
|
|
|
|
|
|
FontId::proportional(13.0),
|
|
|
|
|
|
color,
|
|
|
|
|
|
);
|
|
|
|
|
|
let id = ui.id().with(("mark", at.x as i32, at.y as i32));
|
|
|
|
|
|
let r = ui.interact(rect.expand(2.0), id, Sense::hover());
|
|
|
|
|
|
r.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, name));
|
|
|
|
|
|
r.on_hover_ui(|ui| {
|
|
|
|
|
|
ui.set_max_width(360.0);
|
|
|
|
|
|
ui.label(tip);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The mark after a comment inside a line of text (a variation): part of the flow.
|
|
|
|
|
|
fn inline_mark(ui: &mut Ui, mark: &Translated, original: &str) {
|
|
|
|
|
|
let (sym, color, tip, name) = mark_info(ui, mark, original);
|
|
|
|
|
|
let r =
|
|
|
|
|
|
ui.add(egui::Label::new(RichText::new(sym).size(13.0).color(color)).sense(Sense::hover()));
|
|
|
|
|
|
r.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, true, name));
|
|
|
|
|
|
r.on_hover_ui(|ui| {
|
|
|
|
|
|
ui.set_max_width(360.0);
|
|
|
|
|
|
ui.label(tip);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn mark_info(
|
|
|
|
|
|
ui: &Ui,
|
|
|
|
|
|
mark: &Translated,
|
|
|
|
|
|
original: &str,
|
|
|
|
|
|
) -> (&'static str, Color32, String, &'static str) {
|
|
|
|
|
|
match mark {
|
Translation of game comments
When a game's comments are in another language, ChessPenguin offers to translate
them into the reader's: with the ChatGPT Plus/Pro subscription (Sign in with
ChatGPT: OAuth with PKCE in the browser, a loopback callback, tokens refreshed
one at a time), or an OpenAI-compatible API key (DeepSeek, OpenAI, Gemini, a
model on this computer with Ollama or LM Studio, another address). After the
first consent, games in other languages are translated as they are opened;
[Original | Translation] (Ctrl+Shift+T) switches back.
Only comment text is sent; the model gets strict instructions and a glossary,
and every answer must keep the moves and squares of the original, or the
comment stays in the original with a mark. Translations are never written to
the PGN; a cache keeps them per language. Keys and tokens live in a 0600 file
apart from the settings. Settings › Translation holds the target language,
when to translate, the connection, permissions and the cache.
Also: the monospace font and three glyphs of Noto Sans Math are text fallbacks,
so arrows and the evaluation signs ⩲ ⩱ ⌓ no longer show as boxes.
Reviewed by the designer and the tester agents (two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:03:03 +03:00
|
|
|
|
Translated::Translated(_) => {
|
|
|
|
|
|
let mut o: String = original.chars().take(1000).collect();
|
|
|
|
|
|
if original.chars().count() > 1000 {
|
|
|
|
|
|
o.push('…');
|
|
|
|
|
|
}
|
|
|
|
|
|
(
|
|
|
|
|
|
"⇄",
|
|
|
|
|
|
ui.visuals().weak_text_color(),
|
|
|
|
|
|
format!("{}\n{o}", tr("Machine translation. Original:")),
|
|
|
|
|
|
tr("Machine translation"),
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
Translated::Pending => (
|
|
|
|
|
|
"⋯",
|
|
|
|
|
|
ui.visuals().weak_text_color(),
|
|
|
|
|
|
tr("Translating…").to_owned(),
|
|
|
|
|
|
tr("Translating…"),
|
|
|
|
|
|
),
|
|
|
|
|
|
Translated::Bad => (
|
|
|
|
|
|
"⚠",
|
|
|
|
|
|
ui.visuals().warn_fg_color,
|
|
|
|
|
|
tr("This comment could not be translated — the original is shown. Press “Retry” in the line above the notation.").to_owned(),
|
|
|
|
|
|
tr("Not translated"),
|
|
|
|
|
|
),
|
2026-10-21 23:00:20 +03:00
|
|
|
|
}
|
Translation of game comments
When a game's comments are in another language, ChessPenguin offers to translate
them into the reader's: with the ChatGPT Plus/Pro subscription (Sign in with
ChatGPT: OAuth with PKCE in the browser, a loopback callback, tokens refreshed
one at a time), or an OpenAI-compatible API key (DeepSeek, OpenAI, Gemini, a
model on this computer with Ollama or LM Studio, another address). After the
first consent, games in other languages are translated as they are opened;
[Original | Translation] (Ctrl+Shift+T) switches back.
Only comment text is sent; the model gets strict instructions and a glossary,
and every answer must keep the moves and squares of the original, or the
comment stays in the original with a mark. Translations are never written to
the PGN; a cache keeps them per language. Keys and tokens live in a 0600 file
apart from the settings. Settings › Translation holds the target language,
when to translate, the connection, permissions and the cache.
Also: the monospace font and three glyphs of Noto Sans Math are text fallbacks,
so arrows and the evaluation signs ⩲ ⩱ ⌓ no longer show as boxes.
Reviewed by the designer and the tester agents (two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:03:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-21 23:00:20 +03:00
|
|
|
|
/// Room kept on the right of a comment for its translation mark.
|
|
|
|
|
|
const MARK_ROOM: f32 = 18.0;
|
|
|
|
|
|
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
fn comment_block(ui: &mut Ui, n: &Notation, text: &str, slot: Slot, out: &mut NotationResponse) {
|
Translation of game comments
When a game's comments are in another language, ChessPenguin offers to translate
them into the reader's: with the ChatGPT Plus/Pro subscription (Sign in with
ChatGPT: OAuth with PKCE in the browser, a loopback callback, tokens refreshed
one at a time), or an OpenAI-compatible API key (DeepSeek, OpenAI, Gemini, a
model on this computer with Ollama or LM Studio, another address). After the
first consent, games in other languages are translated as they are opened;
[Original | Translation] (Ctrl+Shift+T) switches back.
Only comment text is sent; the model gets strict instructions and a glossary,
and every answer must keep the moves and squares of the original, or the
comment stays in the original with a mark. Translations are never written to
the PGN; a cache keeps them per language. Keys and tokens live in a 0600 file
apart from the settings. Settings › Translation holds the target language,
when to translate, the connection, permissions and the cache.
Also: the monospace font and three glyphs of Noto Sans Math are text fallbacks,
so arrows and the evaluation signs ⩲ ⩱ ⌓ no longer show as boxes.
Reviewed by the designer and the tester agents (two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:03:03 +03:00
|
|
|
|
let (shown, mark) = translated(n, text);
|
2026-10-21 23:00:20 +03:00
|
|
|
|
let mut frame = block_frame(ui);
|
|
|
|
|
|
if mark.is_some() {
|
|
|
|
|
|
frame = frame.inner_margin(egui::Margin {
|
|
|
|
|
|
left: 10,
|
|
|
|
|
|
right: 10 + MARK_ROOM as i8,
|
|
|
|
|
|
top: 6,
|
|
|
|
|
|
bottom: 6,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-10-25 03:04:00 +03:00
|
|
|
|
// The whole block, not only its text, takes the double click and the right button,
|
|
|
|
|
|
// and lights up under the mouse (known from the last frame).
|
|
|
|
|
|
let id = ui.id().with((
|
|
|
|
|
|
"comment",
|
|
|
|
|
|
slot.node().index(),
|
|
|
|
|
|
matches!(slot, Slot::Before(_)),
|
|
|
|
|
|
));
|
|
|
|
|
|
if ui.ctx().read_response(id).is_some_and(|r| r.hovered()) {
|
|
|
|
|
|
frame = frame.fill(ui.visuals().widgets.hovered.weak_bg_fill);
|
|
|
|
|
|
}
|
2026-10-21 23:00:20 +03:00
|
|
|
|
let r = frame.show(ui, |ui| {
|
2026-10-18 01:54:06 +03:00
|
|
|
|
ui.set_width(ui.available_width());
|
2026-10-25 02:54:13 +03:00
|
|
|
|
ui.label(RichText::new(shown).color(comment_color(ui)).size(14.5));
|
2026-10-18 01:54:06 +03:00
|
|
|
|
});
|
2026-10-25 03:04:00 +03:00
|
|
|
|
let resp = ui.interact(r.response.rect, id, Sense::click());
|
2026-10-25 02:54:13 +03:00
|
|
|
|
comment_response(&resp, slot, out);
|
2026-10-21 23:00:20 +03:00
|
|
|
|
if let Some(m) = mark {
|
|
|
|
|
|
let at = r.response.rect.right_top() + vec2(-8.0, 7.0);
|
|
|
|
|
|
translation_mark(ui, at, m, text);
|
|
|
|
|
|
}
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// A double click opens the comment for editing; the right button offers that and
|
|
|
|
|
|
/// deleting (user-comments.md §5.2).
|
|
|
|
|
|
fn comment_response(resp: &egui::Response, slot: Slot, out: &mut NotationResponse) {
|
|
|
|
|
|
if resp.hovered() {
|
|
|
|
|
|
resp.ctx.set_cursor_icon(egui::CursorIcon::Text);
|
|
|
|
|
|
}
|
|
|
|
|
|
if resp.double_clicked() {
|
|
|
|
|
|
out.edit = Some(slot);
|
|
|
|
|
|
}
|
|
|
|
|
|
resp.context_menu(|ui| {
|
|
|
|
|
|
if ui.button(tr("Edit comment…")).clicked() {
|
|
|
|
|
|
out.edit = Some(slot);
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
if ui.button(tr("Delete comment")).clicked() {
|
|
|
|
|
|
out.delete = Some(slot);
|
|
|
|
|
|
ui.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The comment editor on the spot of its comment (user-comments.md §3.4).
|
2026-10-25 03:04:00 +03:00
|
|
|
|
/// `in_variation`: inside a variation's frame (tighter margins).
|
|
|
|
|
|
fn editor_block(
|
|
|
|
|
|
ui: &mut Ui,
|
|
|
|
|
|
editor: &mut Option<&mut CommentEditor>,
|
|
|
|
|
|
in_variation: bool,
|
|
|
|
|
|
out: &mut NotationResponse,
|
|
|
|
|
|
) {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let Some(ed) = editor.as_deref_mut() else {
|
|
|
|
|
|
return;
|
|
|
|
|
|
};
|
|
|
|
|
|
let focused = ed
|
|
|
|
|
|
.field_id
|
|
|
|
|
|
.is_some_and(|id| ui.ctx().memory(|m| m.focused() == Some(id)));
|
|
|
|
|
|
let sel = ui.visuals().selection;
|
|
|
|
|
|
let stroke = if focused {
|
|
|
|
|
|
Stroke::new(1.5, sel.stroke.color)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Stroke::new(1.0, ui.visuals().weak_text_color())
|
|
|
|
|
|
};
|
|
|
|
|
|
let width = ui.available_width();
|
|
|
|
|
|
let narrow = width < 360.0;
|
2026-10-25 03:04:00 +03:00
|
|
|
|
let margin = if narrow {
|
|
|
|
|
|
egui::Margin::symmetric(6, 6)
|
|
|
|
|
|
} else if in_variation {
|
|
|
|
|
|
egui::Margin::symmetric(8, 6)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
egui::Margin::symmetric(10, 6)
|
|
|
|
|
|
};
|
|
|
|
|
|
// The notation's visible height: the field is capped so that the title, the buttons
|
|
|
|
|
|
// and a notation row above and below stay in view (user-comments.md §12).
|
|
|
|
|
|
let viewport_h = ui.clip_rect().height();
|
|
|
|
|
|
let frame_top = ui.cursor().top();
|
|
|
|
|
|
let has_symbols = ed.slot != Slot::After(NodeId::ROOT) && !matches!(ed.slot, Slot::Before(_));
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let r = egui::Frame::new()
|
|
|
|
|
|
.fill(ui.visuals().extreme_bg_color)
|
2026-10-25 03:04:00 +03:00
|
|
|
|
.inner_margin(margin)
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
.stroke(stroke)
|
|
|
|
|
|
.show(ui, |ui| {
|
|
|
|
|
|
ui.set_width(ui.available_width());
|
2026-10-25 03:04:00 +03:00
|
|
|
|
// The title and the buttons: «Done» at the far right, as in every dialog.
|
|
|
|
|
|
let mut title_id = None;
|
|
|
|
|
|
// A row 30 high (the buttons' height), the title centred on it.
|
|
|
|
|
|
let row_w = ui.available_width();
|
|
|
|
|
|
ui.allocate_ui_with_layout(
|
|
|
|
|
|
vec2(row_w, 30.0),
|
|
|
|
|
|
egui::Layout::left_to_right(egui::Align::Center),
|
|
|
|
|
|
|ui| {
|
|
|
|
|
|
let buttons = if narrow {
|
|
|
|
|
|
2.0 * 30.0 + 6.0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
crate::game_view::text_width(ui, tr("Done"), egui::TextStyle::Button)
|
|
|
|
|
|
+ crate::game_view::text_width(
|
|
|
|
|
|
ui,
|
|
|
|
|
|
tr("Cancel"),
|
|
|
|
|
|
egui::TextStyle::Button,
|
|
|
|
|
|
)
|
|
|
|
|
|
+ 4.0 * ui.spacing().button_padding.x
|
|
|
|
|
|
+ 3.0 * ui.spacing().item_spacing.x
|
|
|
|
|
|
};
|
|
|
|
|
|
let room = ui.available_width() - buttons;
|
|
|
|
|
|
let title = if narrow
|
|
|
|
|
|
|| crate::game_view::text_width(ui, &ed.title, egui::TextStyle::Body) > room
|
|
|
|
|
|
{
|
|
|
|
|
|
&ed.short_title
|
|
|
|
|
|
} else {
|
|
|
|
|
|
&ed.title
|
|
|
|
|
|
};
|
|
|
|
|
|
title_id = Some(ui.add(egui::Label::new(title).truncate()).id);
|
|
|
|
|
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
|
|
|
|
|
ui.spacing_mut().item_spacing.x = 6.0;
|
|
|
|
|
|
let (done, cancel) = if narrow {
|
|
|
|
|
|
(
|
|
|
|
|
|
crate::widgets::icon_button(ui, true, true)
|
|
|
|
|
|
.on_hover_text(tr("Done (Enter)")),
|
|
|
|
|
|
crate::widgets::icon_button(ui, false, false)
|
|
|
|
|
|
.on_hover_text(tr("Cancel (Esc)")),
|
|
|
|
|
|
)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
(
|
|
|
|
|
|
crate::widgets::primary(ui, tr("Done")).on_hover_text("Enter"),
|
|
|
|
|
|
ui.add(egui::Button::new(tr("Cancel")).min_size(vec2(0.0, 30.0)))
|
|
|
|
|
|
.on_hover_text("Esc"),
|
|
|
|
|
|
)
|
|
|
|
|
|
};
|
|
|
|
|
|
if done.clicked() {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
out.editor = Some(EditorOutcome::Done);
|
|
|
|
|
|
}
|
2026-10-25 03:04:00 +03:00
|
|
|
|
if cancel.clicked() {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
out.editor = Some(EditorOutcome::Cancel);
|
|
|
|
|
|
}
|
2026-10-25 03:04:00 +03:00
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
// The symbols: the move's six, then the position's eight (a «±▾» menu when
|
|
|
|
|
|
// they do not fit on the line). Not for the start of the game.
|
2026-10-25 03:04:00 +03:00
|
|
|
|
if has_symbols {
|
|
|
|
|
|
let group = |n: f32| n * SYMBOL_W + (n - 1.0) * SYMBOL_GAP;
|
|
|
|
|
|
// The two groups, the separator and the gaps around it.
|
|
|
|
|
|
let both = group(6.0) + 4.0 + 12.0 + 4.0 + group(8.0) <= ui.available_width();
|
|
|
|
|
|
// In a narrow panel (240 wide, less inside a variation) the six buttons
|
|
|
|
|
|
// are 22 wide: the row must not widen the panel.
|
|
|
|
|
|
let w = if ui.available_width() < 300.0 {
|
|
|
|
|
|
22.0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
SYMBOL_W
|
|
|
|
|
|
};
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
ui.horizontal(|ui| {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
ui.spacing_mut().item_spacing.x = 4.0;
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let mut toggled = None;
|
2026-10-25 03:04:00 +03:00
|
|
|
|
symbol_row_sized(ui, &ed.nags, &MOVE_NAGS, true, w, &mut |nag| {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
toggled = Some(nag)
|
|
|
|
|
|
});
|
|
|
|
|
|
if both {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
ui.add(egui::Separator::default().spacing(12.0));
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
symbol_row(ui, &ed.nags, &POSITION_NAGS, false, &mut |nag| {
|
|
|
|
|
|
toggled = Some(nag)
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let current = group_current(&ed.nags, true)
|
|
|
|
|
|
.and_then(|n| n.symbol())
|
|
|
|
|
|
.unwrap_or("±");
|
|
|
|
|
|
ui.menu_button(format!("{current}▾"), |ui| {
|
|
|
|
|
|
symbol_row(ui, &ed.nags, &POSITION_NAGS[..4], false, &mut |nag| {
|
|
|
|
|
|
toggled = Some(nag)
|
|
|
|
|
|
});
|
|
|
|
|
|
symbol_row(ui, &ed.nags, &POSITION_NAGS[4..], false, &mut |nag| {
|
|
|
|
|
|
toggled = Some(nag)
|
|
|
|
|
|
});
|
|
|
|
|
|
})
|
|
|
|
|
|
.response
|
|
|
|
|
|
.on_hover_text(tr("Position assessment"));
|
|
|
|
|
|
}
|
|
|
|
|
|
if let Some(nag) = toggled {
|
|
|
|
|
|
ed.nags = toggle_nag(&ed.nags, nag);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-10-25 03:04:00 +03:00
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
|
// The text in its own box: 2 to 12 lines, then it scrolls inside; in a low
|
|
|
|
|
|
// window fewer lines, so that a notation row stays above and below.
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let color = comment_color(ui);
|
2026-10-25 03:04:00 +03:00
|
|
|
|
let font = FontId::proportional(14.5);
|
|
|
|
|
|
let row_h = ui.fonts_mut(|f| f.row_height(&font));
|
|
|
|
|
|
let overhead = ui.cursor().top() - frame_top;
|
|
|
|
|
|
let below =
|
|
|
|
|
|
if narrow { 0.0 } else { 22.0 } + f32::from(margin.bottom) + 2.0 * ROW_H + 8.0;
|
|
|
|
|
|
let cap = (12.0 * row_h + 8.0)
|
|
|
|
|
|
.min(viewport_h - overhead - below)
|
|
|
|
|
|
.max(2.0 * row_h + 8.0);
|
|
|
|
|
|
let focus_now = std::mem::take(&mut ed.focus);
|
|
|
|
|
|
let field_fill = if ui.visuals().dark_mode {
|
|
|
|
|
|
ui.visuals().panel_fill
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Color32::WHITE
|
|
|
|
|
|
};
|
|
|
|
|
|
let mut border = ui.visuals().widgets.inactive.bg_stroke;
|
|
|
|
|
|
if border.color.a() == 0 {
|
|
|
|
|
|
border = Stroke::new(1.0, ui.visuals().weak_text_color().gamma_multiply(0.35));
|
|
|
|
|
|
}
|
|
|
|
|
|
let resp = egui::Frame::new()
|
|
|
|
|
|
.fill(field_fill)
|
|
|
|
|
|
.stroke(border)
|
|
|
|
|
|
.corner_radius(4)
|
|
|
|
|
|
.inner_margin(egui::Margin::symmetric(6, 4))
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
.show(ui, |ui| {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
ui.set_width(ui.available_width());
|
|
|
|
|
|
ui.spacing_mut().scroll = egui::style::ScrollStyle::solid();
|
|
|
|
|
|
egui::ScrollArea::vertical()
|
|
|
|
|
|
.id_salt("comment_editor_scroll")
|
|
|
|
|
|
.max_height(cap)
|
|
|
|
|
|
.auto_shrink([false, true])
|
|
|
|
|
|
.show(ui, |ui| {
|
|
|
|
|
|
let o = egui::TextEdit::multiline(&mut ed.text)
|
|
|
|
|
|
.id_salt("comment_editor")
|
|
|
|
|
|
.frame(egui::Frame::NONE)
|
|
|
|
|
|
.desired_rows(2)
|
|
|
|
|
|
.desired_width(f32::INFINITY)
|
|
|
|
|
|
.font(font.clone())
|
|
|
|
|
|
.text_color(color)
|
|
|
|
|
|
.hint_text(tr("Your comment…"))
|
|
|
|
|
|
.show(ui);
|
|
|
|
|
|
if focus_now {
|
|
|
|
|
|
// The cursor at the end, and the end in view: one adds to a
|
|
|
|
|
|
// comment more often than replaces it.
|
|
|
|
|
|
o.response.request_focus();
|
|
|
|
|
|
let end = egui::text::CCursor::new(ed.text.chars().count());
|
|
|
|
|
|
let mut state = o.state.clone();
|
|
|
|
|
|
state
|
|
|
|
|
|
.cursor
|
|
|
|
|
|
.set_char_range(Some(egui::text::CCursorRange::one(end)));
|
|
|
|
|
|
state.store(ui.ctx(), o.response.id);
|
|
|
|
|
|
let caret = o
|
|
|
|
|
|
.galley
|
|
|
|
|
|
.pos_from_cursor(end)
|
|
|
|
|
|
.translate(o.galley_pos.to_vec2());
|
|
|
|
|
|
ui.scroll_to_rect(caret, Some(egui::Align::Max));
|
|
|
|
|
|
}
|
|
|
|
|
|
o.response.response
|
|
|
|
|
|
})
|
|
|
|
|
|
.inner
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
})
|
|
|
|
|
|
.inner;
|
|
|
|
|
|
ed.field_id = Some(resp.id);
|
2026-10-25 03:04:00 +03:00
|
|
|
|
if let Some(t) = title_id {
|
|
|
|
|
|
resp.clone().labelled_by(t);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
if !narrow {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
ui.add_space(4.0);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
ui.label(
|
|
|
|
|
|
RichText::new(tr(
|
|
|
|
|
|
"Enter — done · Esc — cancel · Shift+Enter — new paragraph",
|
|
|
|
|
|
))
|
2026-10-25 03:04:00 +03:00
|
|
|
|
.size(11.5)
|
|
|
|
|
|
.color(ui.visuals().weak_text_color()),
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
if ed.translated {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
ui.add_space(2.0);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
ui.label(
|
|
|
|
|
|
RichText::new(tr(
|
|
|
|
|
|
"⇄ You are editing the original; its translation will be dropped",
|
|
|
|
|
|
))
|
2026-10-25 03:04:00 +03:00
|
|
|
|
.size(11.5)
|
|
|
|
|
|
.color(ui.visuals().weak_text_color()),
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if std::mem::take(&mut ed.scroll) {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
// The move's own row above the frame stays in view too.
|
|
|
|
|
|
let rect = r.response.rect;
|
|
|
|
|
|
let with_row = egui::Rect::from_min_max(rect.min - vec2(0.0, ROW_H + 8.0), rect.max);
|
|
|
|
|
|
ui.scroll_to_rect(with_row, None);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-18 01:54:06 +03:00
|
|
|
|
fn unparsed_block(ui: &mut Ui, text: &str) {
|
|
|
|
|
|
block_frame(ui).show(ui, |ui| {
|
|
|
|
|
|
ui.set_width(ui.available_width());
|
|
|
|
|
|
ui.label(
|
|
|
|
|
|
RichText::new(text)
|
|
|
|
|
|
.monospace()
|
|
|
|
|
|
.color(ui.visuals().warn_fg_color),
|
|
|
|
|
|
)
|
|
|
|
|
|
.on_hover_text(tr("PGN fragment that could not be parsed; kept as is"));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn comment_color(ui: &Ui) -> Color32 {
|
|
|
|
|
|
if ui.visuals().dark_mode {
|
|
|
|
|
|
Color32::from_rgb(0x9e, 0xc4, 0xe0)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Color32::from_rgb(0x2a, 0x5b, 0x8a)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// One piece of a variation's flowing text.
|
|
|
|
|
|
enum Token {
|
|
|
|
|
|
Move {
|
|
|
|
|
|
id: NodeId,
|
|
|
|
|
|
label: String,
|
2026-10-25 03:04:00 +03:00
|
|
|
|
/// The label with the move number, for the move that starts a piece of the flow.
|
|
|
|
|
|
numbered: String,
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
color: Option<Color32>,
|
|
|
|
|
|
},
|
|
|
|
|
|
Comment {
|
|
|
|
|
|
slot: Slot,
|
|
|
|
|
|
text: String,
|
|
|
|
|
|
},
|
|
|
|
|
|
Unparsed(String),
|
|
|
|
|
|
Open,
|
|
|
|
|
|
Close,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn variation_block(
|
|
|
|
|
|
ui: &mut Ui,
|
|
|
|
|
|
n: &Notation,
|
|
|
|
|
|
start: NodeId,
|
|
|
|
|
|
editor: &mut Option<&mut CommentEditor>,
|
|
|
|
|
|
out: &mut NotationResponse,
|
|
|
|
|
|
) {
|
|
|
|
|
|
let mut tokens = Vec::new();
|
|
|
|
|
|
line_tokens(n, start, &mut tokens);
|
|
|
|
|
|
let editing = editor.as_ref().map(|e| e.slot);
|
|
|
|
|
|
// The flow is cut where the editor stands: after the move for «after», before it
|
|
|
|
|
|
// for «before»; a comment being edited is replaced by the editor.
|
|
|
|
|
|
let cut = editing.and_then(|slot| {
|
|
|
|
|
|
tokens
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.position(|t| matches!(t, Token::Comment { slot: s, .. } if *s == slot))
|
|
|
|
|
|
.map(|i| (i, true))
|
|
|
|
|
|
.or_else(|| match slot {
|
|
|
|
|
|
Slot::After(id) => tokens
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.position(|t| matches!(t, Token::Move { id: m, .. } if *m == id))
|
|
|
|
|
|
.map(|i| (i + 1, false)),
|
|
|
|
|
|
Slot::Before(id) => tokens
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.position(|t| matches!(t, Token::Move { id: m, .. } if *m == id))
|
|
|
|
|
|
.map(|i| (i, false)),
|
|
|
|
|
|
})
|
|
|
|
|
|
});
|
2026-10-18 01:54:06 +03:00
|
|
|
|
block_frame(ui).show(ui, |ui| {
|
|
|
|
|
|
ui.set_width(ui.available_width());
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
match cut {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
None => flow(ui, n, &tokens, false, out),
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
Some((at, replaces)) => {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
flow(ui, n, &tokens[..at], false, out);
|
|
|
|
|
|
editor_block(ui, editor, true, out);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let rest = if replaces { at + 1 } else { at };
|
2026-10-25 03:04:00 +03:00
|
|
|
|
flow(ui, n, &tokens[rest..], true, out);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-25 03:09:23 +03:00
|
|
|
|
/// A move in flowing text: the current one highlighted as in the main-line table,
|
|
|
|
|
|
/// the others lit under the mouse. Painted by hand, so its size never changes with the
|
|
|
|
|
|
/// mouse (a button's frame does).
|
|
|
|
|
|
fn move_chip(ui: &mut Ui, label: &str, color: Option<Color32>, current: bool) -> egui::Response {
|
|
|
|
|
|
let sel = ui.visuals().selection;
|
|
|
|
|
|
let font = FontId::proportional(15.0);
|
|
|
|
|
|
let text_color = if current {
|
|
|
|
|
|
sel.stroke.color
|
|
|
|
|
|
} else {
|
|
|
|
|
|
color.unwrap_or_else(|| ui.visuals().text_color())
|
|
|
|
|
|
};
|
|
|
|
|
|
let galley = ui
|
|
|
|
|
|
.painter()
|
|
|
|
|
|
.layout_no_wrap(label.to_owned(), font, text_color);
|
|
|
|
|
|
let pad = vec2(4.0, 2.0);
|
|
|
|
|
|
let (rect, resp) = ui.allocate_exact_size(galley.size() + 2.0 * pad, Sense::click());
|
|
|
|
|
|
if current {
|
|
|
|
|
|
ui.painter().rect(
|
|
|
|
|
|
rect,
|
|
|
|
|
|
2.0,
|
|
|
|
|
|
sel.bg_fill,
|
|
|
|
|
|
Stroke::new(1.0, sel.stroke.color),
|
|
|
|
|
|
egui::StrokeKind::Inside,
|
|
|
|
|
|
);
|
|
|
|
|
|
} else if resp.hovered() {
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.rect_filled(rect, 2.0, ui.visuals().widgets.hovered.weak_bg_fill);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.painter().galley(rect.min + pad, galley, text_color);
|
|
|
|
|
|
resp
|
|
|
|
|
|
}
|
|
|
|
|
|
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// Lays out tokens as flowing text.
|
2026-10-25 03:04:00 +03:00
|
|
|
|
fn flow(
|
|
|
|
|
|
ui: &mut Ui,
|
|
|
|
|
|
n: &Notation,
|
|
|
|
|
|
tokens: &[Token],
|
|
|
|
|
|
numbered_first: bool,
|
|
|
|
|
|
out: &mut NotationResponse,
|
|
|
|
|
|
) {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
if tokens.is_empty() {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
ui.horizontal_wrapped(|ui| {
|
|
|
|
|
|
ui.spacing_mut().item_spacing = vec2(3.0, 2.0);
|
2026-10-25 03:04:00 +03:00
|
|
|
|
for (k, t) in tokens.iter().enumerate() {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
match t {
|
2026-10-25 03:04:00 +03:00
|
|
|
|
Token::Move {
|
|
|
|
|
|
id,
|
|
|
|
|
|
label,
|
|
|
|
|
|
numbered,
|
|
|
|
|
|
color,
|
|
|
|
|
|
} => {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
let current = *id == n.cursor;
|
2026-10-25 03:04:00 +03:00
|
|
|
|
// After the editor the flow starts anew: with the move number.
|
|
|
|
|
|
let label = if k == 0 && numbered_first {
|
|
|
|
|
|
numbered
|
|
|
|
|
|
} else {
|
|
|
|
|
|
label
|
|
|
|
|
|
};
|
2026-10-25 03:09:23 +03:00
|
|
|
|
let resp = move_chip(ui, label, *color, current);
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
handle_move_response(ui, &resp, n, *id, out);
|
|
|
|
|
|
}
|
|
|
|
|
|
Token::Comment { slot, text } => {
|
|
|
|
|
|
let (shown, mark) = translated(n, text);
|
|
|
|
|
|
let resp = ui.add(
|
|
|
|
|
|
egui::Label::new(RichText::new(shown).color(comment_color(ui)).size(14.5))
|
|
|
|
|
|
.sense(Sense::click()),
|
|
|
|
|
|
);
|
|
|
|
|
|
comment_response(&resp, *slot, out);
|
|
|
|
|
|
if let Some(m) = mark {
|
|
|
|
|
|
inline_mark(ui, m, text);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Token::Unparsed(u) => {
|
|
|
|
|
|
ui.label(
|
|
|
|
|
|
RichText::new(u)
|
|
|
|
|
|
.monospace()
|
|
|
|
|
|
.color(ui.visuals().warn_fg_color),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
Token::Open => {
|
|
|
|
|
|
ui.label(RichText::new("(").weak());
|
|
|
|
|
|
}
|
|
|
|
|
|
Token::Close => {
|
|
|
|
|
|
ui.label(RichText::new(")").weak());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-10-18 01:54:06 +03:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
/// The tokens of a line starting at `first` (a variation move), nested lines inside.
|
|
|
|
|
|
fn line_tokens(n: &Notation, first: NodeId, tokens: &mut Vec<Token>) {
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let game = n.game;
|
|
|
|
|
|
let mut node = first;
|
|
|
|
|
|
let mut need_number = true;
|
|
|
|
|
|
loop {
|
|
|
|
|
|
let Some(nd) = game.node(node) else { return };
|
|
|
|
|
|
let before = comment_text(nd.comments_before());
|
|
|
|
|
|
if !before.is_empty() {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
tokens.push(Token::Comment {
|
|
|
|
|
|
slot: Slot::Before(node),
|
|
|
|
|
|
text: before,
|
|
|
|
|
|
});
|
2026-10-18 01:54:06 +03:00
|
|
|
|
need_number = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
let (num, color) = game.move_number(node).unwrap_or((0, Color::White));
|
|
|
|
|
|
let san = game.game_move(node).map(|m| m.san.as_str()).unwrap_or("?");
|
Move notation: Latin letters, figurines or the interface language's letters
Settings › Board & pieces: Nf3, ♘f3 as on Lichess, or Кр Ф Л С К (German
K D T L S, French R D T F C, Spanish and Italian R D T A C; in English the
Latin letters), with a sample per option and a line of a game. Only the shown
label changes (san::show): the game, PGN, copied games, the analysis written
into a game, the reference cache and every comparison stay Latin SAN. Applied
in the move list, engine lines, the reference tab, board search and the
analysis report. The figurines are egui's chess glyphs cut out to a 4.7 KB
font, a little smaller and on the baseline. Latin remains the default.
Reviewed by the designer and the tester agents.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 21:18:53 +03:00
|
|
|
|
let san = crate::san::show(san);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let (sym, sym_color) = move_glyph(nd.nags());
|
|
|
|
|
|
let label = match (color, need_number) {
|
|
|
|
|
|
(Color::White, _) => format!("{num}.{san}{sym}"),
|
|
|
|
|
|
(Color::Black, true) => format!("{num}…{san}{sym}"),
|
|
|
|
|
|
(Color::Black, false) => format!("{san}{sym}"),
|
|
|
|
|
|
};
|
|
|
|
|
|
need_number = false;
|
2026-10-25 03:04:00 +03:00
|
|
|
|
let numbered = match color {
|
|
|
|
|
|
Color::White => label.clone(),
|
|
|
|
|
|
Color::Black => format!("{num}…{san}{sym}"),
|
|
|
|
|
|
};
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
tokens.push(Token::Move {
|
|
|
|
|
|
id: node,
|
|
|
|
|
|
label,
|
2026-10-25 03:04:00 +03:00
|
|
|
|
numbered,
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
color: sym_color,
|
|
|
|
|
|
});
|
2026-10-18 01:54:06 +03:00
|
|
|
|
let after = comment_text(nd.comments_after());
|
|
|
|
|
|
if !after.is_empty() {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
tokens.push(Token::Comment {
|
|
|
|
|
|
slot: Slot::After(node),
|
|
|
|
|
|
text: after,
|
|
|
|
|
|
});
|
2026-10-18 01:54:06 +03:00
|
|
|
|
need_number = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
for u in nd.unparsed() {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
tokens.push(Token::Unparsed(u.clone()));
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
// Alternatives to this move are printed right after it (PGN order),
|
|
|
|
|
|
// except for the line's own first move whose siblings belong to the outer level.
|
|
|
|
|
|
if node != first
|
|
|
|
|
|
&& let Some(parent) = game.parent(node)
|
|
|
|
|
|
{
|
|
|
|
|
|
for &v in game.variations(parent) {
|
User comments: an editor in the notation, symbols, arrows on the board
Enter on a move (the move's menu, a double click on a comment, the ☰ menu) opens
the editor where the comment stands: after any move, in a variation too (the
flow is cut at the move), or at the start of the game; Enter — done, Esc —
cancel, Shift+Enter — a paragraph; another move writes the draft; one edit —
one undo step. Symbols of the move (! ? !! ?? !? ?!, Ctrl+1…6) and of the
position in the editor and in the menu. The right mouse button draws arrows
and circles on the board ([%cal]/[%csl] of the current move; colours by
modifiers). Existing comments are edited and deleted; their commands and
untouched bytes are kept. chess_core: with_text, with_shapes, shapes,
Game::set_comments_before. Dev hooks CP_COMMENT_EDIT, CP_TYPE, CP_SHAPE.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 02:35:54 +03:00
|
|
|
|
tokens.push(Token::Open);
|
|
|
|
|
|
line_tokens(n, v, tokens);
|
|
|
|
|
|
tokens.push(Token::Close);
|
2026-10-18 01:54:06 +03:00
|
|
|
|
need_number = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
match game.main_child(node) {
|
|
|
|
|
|
Some(next) => node = next,
|
|
|
|
|
|
None => return,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|