2026-10-18 01:54:06 +03:00
|
|
|
|
//! Small shared widgets.
|
|
|
|
|
|
|
|
|
|
|
|
use egui::{Color32, Sense, Stroke, Ui, vec2};
|
|
|
|
|
|
|
2026-11-06 00:26:01 +03:00
|
|
|
|
/// The application's settings action, shared by screen headers.
|
|
|
|
|
|
pub fn settings_button(ui: &mut Ui, compact: bool) -> egui::Response {
|
|
|
|
|
|
let tr = crate::i18n::tr;
|
|
|
|
|
|
ui.button(if compact { "⚙" } else { tr("⚙ Settings") })
|
|
|
|
|
|
.on_hover_text(format!("{} (Ctrl+,)", tr("Settings")))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A section header: reserve global actions before laying out a long title.
|
|
|
|
|
|
/// Returns (back, settings).
|
2026-11-26 17:13:34 +03:00
|
|
|
|
#[allow(dead_code)]
|
2026-11-06 00:26:01 +03:00
|
|
|
|
pub fn section_header(ui: &mut Ui, back: &str, title: &str) -> (bool, bool) {
|
|
|
|
|
|
let mut clicked = (false, false);
|
|
|
|
|
|
let compact = ui.available_width() < 600.0;
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.set_min_height(26.0);
|
|
|
|
|
|
clicked.0 = ui.button(back).clicked();
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
|
|
|
|
|
clicked.1 = settings_button(ui, compact).clicked();
|
|
|
|
|
|
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
|
|
|
|
|
ui.add(egui::Label::new(egui::RichText::new(title).heading()).truncate())
|
|
|
|
|
|
.on_hover_text(title);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
clicked
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-26 17:13:34 +03:00
|
|
|
|
/// A two-line section header in the places of the game's (title and a quiet line under
|
|
|
|
|
|
/// it; an empty subtitle keeps its line, so the header never changes height).
|
|
|
|
|
|
/// Returns (back, settings).
|
|
|
|
|
|
pub fn section_header_sub(ui: &mut Ui, back: &str, title: &str, subtitle: &str) -> (bool, bool) {
|
|
|
|
|
|
let mut clicked = (false, false);
|
|
|
|
|
|
let compact = ui.available_width() < 600.0;
|
|
|
|
|
|
ui.add_space(4.0);
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
clicked.0 = ui.button(back).clicked();
|
|
|
|
|
|
ui.separator();
|
|
|
|
|
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
|
|
|
|
|
clicked.1 = settings_button(ui, compact).clicked();
|
|
|
|
|
|
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
|
2026-11-27 02:13:19 +03:00
|
|
|
|
// The rows of the game screen's header (game_view.rs): the same height.
|
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
|
ui.add(
|
|
|
|
|
|
egui::Label::new(egui::RichText::new(title).strong().size(16.0)).truncate(),
|
|
|
|
|
|
)
|
2026-11-26 17:13:34 +03:00
|
|
|
|
.on_hover_text(title);
|
2026-11-27 02:13:19 +03:00
|
|
|
|
});
|
2026-11-26 17:13:34 +03:00
|
|
|
|
let sub = ui.add(
|
|
|
|
|
|
egui::Label::new(
|
|
|
|
|
|
egui::RichText::new(if subtitle.is_empty() { " " } else { subtitle })
|
|
|
|
|
|
.weak(),
|
|
|
|
|
|
)
|
|
|
|
|
|
.truncate(),
|
|
|
|
|
|
);
|
|
|
|
|
|
if !subtitle.is_empty() {
|
|
|
|
|
|
sub.on_hover_text(subtitle);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2026-11-27 02:13:19 +03:00
|
|
|
|
ui.add_space(4.0);
|
2026-11-26 17:13:34 +03:00
|
|
|
|
clicked
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-24 10:12:10 +03:00
|
|
|
|
/// A dev check (`CP_PANEL_CHECK=1`): a panel whose content is wider than the panel. egui
|
|
|
|
|
|
/// then moves a right panel out (its left part under the central panel, its right part
|
|
|
|
|
|
/// off the window); the content of every panel must fit its least width
|
|
|
|
|
|
/// (docs/design/narrow-windows.md).
|
|
|
|
|
|
pub fn check_panel(name: &str, panel: &egui::Response) {
|
|
|
|
|
|
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
|
|
|
|
|
let on = *ON.get_or_init(|| {
|
|
|
|
|
|
let on = std::env::var_os("CP_PANEL_CHECK").is_some();
|
|
|
|
|
|
// In a debug build egui also marks (red) what makes its parent wider.
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
|
|
if on {
|
|
|
|
|
|
panel
|
|
|
|
|
|
.ctx
|
|
|
|
|
|
.all_styles_mut(|s| s.debug.show_expand_width = true);
|
|
|
|
|
|
}
|
|
|
|
|
|
on
|
|
|
|
|
|
});
|
|
|
|
|
|
if !on {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let window = panel.ctx.content_rect();
|
|
|
|
|
|
let over = (panel.rect.right() - window.right()).max(window.left() - panel.rect.left());
|
|
|
|
|
|
if over > 0.5 {
|
|
|
|
|
|
eprintln!(
|
|
|
|
|
|
"CP_PANEL_CHECK: panel {name} is {over:.0} pt wider than its place (window {:.0} pt)",
|
|
|
|
|
|
window.width()
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
Opponent prep: everything folded at first, every table sortable
The repertoire starts with its roots folded (no automatic expansion, after a
rebuild, a colour or a depth either); the user opens what he wants.
A click on a column's header orders the table by it, a second click turns the
order round, ⏶/⏷ beside the title as in the library's game table (the header
button is now `widgets::sort_header`, shared with it): the games list (all
columns), the openings (families, and the variations inside each, by name,
ECO, games, %, score, last game, errors), the errors tab (repeated errors by
move, ×, score, opening; «By opening» by games and errors) and the repertoire
(the moves of every position by games, %, score, last game; games first by
default). Each table's order is kept in `settings.prep.sorts`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 16:56:43 +03:00
|
|
|
|
/// A sortable column's header: the title in bold, ▲/▼ when the table is ordered by
|
|
|
|
|
|
/// it (`Some(ascending)`); click to sort.
|
|
|
|
|
|
pub fn sort_header(ui: &mut Ui, label: &str, ascending: Option<bool>) -> egui::Response {
|
|
|
|
|
|
let arrow = match ascending {
|
|
|
|
|
|
Some(true) => " ⏶",
|
|
|
|
|
|
Some(false) => " ⏷",
|
|
|
|
|
|
None => "",
|
|
|
|
|
|
};
|
|
|
|
|
|
ui.add(egui::Button::new(egui::RichText::new(format!("{label}{arrow}")).strong()).frame(false))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
/// Compact ✕ (e.g. to cancel a running task); the caller adds the tooltip.
|
|
|
|
|
|
pub fn small_close_button(ui: &mut Ui) -> egui::Response {
|
|
|
|
|
|
x_button(ui, vec2(22.0, 20.0), 4.5)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn x_button(ui: &mut Ui, size: egui::Vec2, d: f32) -> egui::Response {
|
|
|
|
|
|
let (rect, resp) = ui.allocate_exact_size(size, Sense::click());
|
2026-10-18 01:54:06 +03:00
|
|
|
|
if resp.hovered() {
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.rect_filled(rect, 4.0, Color32::from_rgb(0xc4, 0x2b, 0x1c));
|
|
|
|
|
|
}
|
|
|
|
|
|
let color = if resp.hovered() {
|
|
|
|
|
|
Color32::WHITE
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ui.visuals().text_color()
|
|
|
|
|
|
};
|
|
|
|
|
|
let c = rect.center();
|
|
|
|
|
|
let stroke = Stroke::new(1.6, color);
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.line_segment([c + vec2(-d, -d), c + vec2(d, d)], stroke);
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.line_segment([c + vec2(-d, d), c + vec2(d, -d)], stroke);
|
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
|
|
|
|
resp
|
2026-10-18 01:54:06 +03:00
|
|
|
|
}
|
2026-10-19 19:48:14 +03:00
|
|
|
|
|
|
|
|
|
|
/// The quiet "ℹ n" of import notes: minor remarks, so no colour and no frame.
|
|
|
|
|
|
pub fn notes_button(ui: &mut egui::Ui, notes: usize) -> egui::Response {
|
|
|
|
|
|
ui.add(egui::Button::new(egui::RichText::new(format!("ℹ {notes}")).weak().small()).frame(false))
|
|
|
|
|
|
.on_hover_text(crate::i18n::tr("Import notes"))
|
|
|
|
|
|
}
|
2026-10-20 07:55:59 +03:00
|
|
|
|
|
|
|
|
|
|
/// "⬆ Update 0.8.0" (or the download's progress, "⟳ Restart for 0.8.0"): opens the
|
|
|
|
|
|
/// update window.
|
|
|
|
|
|
pub fn update_button(ui: &mut egui::Ui, label: &str) -> egui::Response {
|
|
|
|
|
|
ui.button(egui::RichText::new(label).color(ui.visuals().hyperlink_color))
|
|
|
|
|
|
.on_hover_text(crate::i18n::tr("A new version of ChessPenguin is out"))
|
|
|
|
|
|
}
|
2026-10-20 08:30:31 +03:00
|
|
|
|
|
|
|
|
|
|
/// The main button of a window: filled, a little taller.
|
|
|
|
|
|
pub fn primary(ui: &mut egui::Ui, label: &str) -> egui::Response {
|
2026-10-25 22:20:09 +03:00
|
|
|
|
primary_wide(ui, label, 0.0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-27 17:30:43 +03:00
|
|
|
|
/// The king of a side, `size` points square: White's light with a dark outline,
|
|
|
|
|
|
/// Black's dark with a light one, the same in both themes (task 45; a font's ♔/♚ read
|
|
|
|
|
|
/// the other way round on a dark background). From the classic set, whatever the board's.
|
|
|
|
|
|
pub fn side_king(white: bool, size: f32) -> egui::Image<'static> {
|
|
|
|
|
|
let color = if white {
|
|
|
|
|
|
shakmaty::Color::White
|
|
|
|
|
|
} else {
|
|
|
|
|
|
shakmaty::Color::Black
|
|
|
|
|
|
};
|
|
|
|
|
|
crate::assets::PieceSet::Cburnett
|
|
|
|
|
|
.image(shakmaty::Piece {
|
|
|
|
|
|
color,
|
|
|
|
|
|
role: shakmaty::Role::King,
|
|
|
|
|
|
})
|
|
|
|
|
|
.fit_to_exact_size(egui::vec2(size, size))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-10-25 22:20:09 +03:00
|
|
|
|
/// `primary()` at least `width` wide (a button whose label changes keeps its place).
|
|
|
|
|
|
pub fn primary_wide(ui: &mut egui::Ui, label: &str, width: f32) -> egui::Response {
|
2026-10-20 08:30:31 +03:00
|
|
|
|
ui.add(
|
|
|
|
|
|
egui::Button::new(egui::RichText::new(label).strong())
|
|
|
|
|
|
.fill(ui.visuals().selection.bg_fill)
|
2026-10-25 22:20:09 +03:00
|
|
|
|
.min_size(egui::vec2(width, 30.0)),
|
2026-10-20 08:30:31 +03:00
|
|
|
|
)
|
|
|
|
|
|
}
|
2026-10-25 03:04:00 +03:00
|
|
|
|
|
|
|
|
|
|
/// A 30 × 30 button with a painted ✓ (`check`) or ✕: the font has no such glyphs. The
|
|
|
|
|
|
/// main one (`primary`) is filled like `primary()`.
|
|
|
|
|
|
pub fn icon_button(ui: &mut Ui, check: bool, primary: bool) -> egui::Response {
|
|
|
|
|
|
let (rect, resp) = ui.allocate_exact_size(vec2(30.0, 30.0), Sense::click());
|
|
|
|
|
|
let visuals = ui.style().interact(&resp);
|
|
|
|
|
|
let sel = ui.visuals().selection;
|
|
|
|
|
|
let (fill, color) = if primary {
|
|
|
|
|
|
(
|
|
|
|
|
|
if resp.hovered() {
|
|
|
|
|
|
sel.bg_fill.gamma_multiply(1.15)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
sel.bg_fill
|
|
|
|
|
|
},
|
|
|
|
|
|
sel.stroke.color,
|
|
|
|
|
|
)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
(visuals.weak_bg_fill, visuals.text_color())
|
|
|
|
|
|
};
|
|
|
|
|
|
ui.painter().rect_filled(rect, 4.0, fill);
|
|
|
|
|
|
if !primary {
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.rect_stroke(rect, 4.0, visuals.bg_stroke, egui::StrokeKind::Inside);
|
|
|
|
|
|
}
|
|
|
|
|
|
let c = rect.center();
|
|
|
|
|
|
let stroke = Stroke::new(2.0, color);
|
|
|
|
|
|
if check {
|
|
|
|
|
|
ui.painter().add(egui::Shape::line(
|
|
|
|
|
|
vec![
|
|
|
|
|
|
c + vec2(-5.0, 0.0),
|
|
|
|
|
|
c + vec2(-1.5, 4.0),
|
|
|
|
|
|
c + vec2(5.5, -4.5),
|
|
|
|
|
|
],
|
|
|
|
|
|
stroke,
|
|
|
|
|
|
));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let d = 4.5;
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.line_segment([c + vec2(-d, -d), c + vec2(d, d)], stroke);
|
|
|
|
|
|
ui.painter()
|
|
|
|
|
|
.line_segment([c + vec2(-d, d), c + vec2(d, -d)], stroke);
|
|
|
|
|
|
}
|
|
|
|
|
|
resp
|
|
|
|
|
|
}
|
Review engine and dropped files: fixes after the independent check
- The probe turns down an engine not called «Stockfish 19» right after `uci`, without
a search; a search has a 10 s guard, the probe 30 s; probes stop and their engines
quit (or are killed) when the program quits. Play engines (Rodent, Maia) are never
candidates.
- «Did not start» is its own outcome, said once and tried again next time; verdicts
are kept for the real file with the reference's key; the engine's name is checked
again when a job starts (a wrapper may run another program).
- The wait for a probe belongs to its game or preparation; the game analysis and the
opening errors wait apart; «analyse anew» keeps its `full`.
- The offer says why: another engine (settings / system), a Stockfish 19 that
calculates otherwise, one that did not start; the size line is back.
- Dropped files: missing ones told, known ChessBase parts only, duplicates by the real
file, each folder listed once; drops never replace a database being chosen again,
a cancelled «Choose again» ends it; «Added to the shelf» over a game; a framed
highlight with a card; long names shortened.
- decisions.md: where dropping works (not in a Wayland session: winit 0.30).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 13:42:19 +03:00
|
|
|
|
|
|
|
|
|
|
/// `text` cut to `max` characters, with «…» in the middle when longer (a file's or an
|
|
|
|
|
|
/// engine's name keeps its start and its end, where versions and extensions are).
|
|
|
|
|
|
pub fn shorten(text: &str, max: usize) -> String {
|
|
|
|
|
|
let n = text.chars().count();
|
|
|
|
|
|
if n <= max || max < 3 {
|
|
|
|
|
|
return text.to_owned();
|
|
|
|
|
|
}
|
|
|
|
|
|
let head = (max - 1) / 2;
|
|
|
|
|
|
let tail = max - 1 - head;
|
|
|
|
|
|
let start: String = text.chars().take(head).collect();
|
|
|
|
|
|
let end: String = text.chars().skip(n - tail).collect();
|
|
|
|
|
|
format!("{start}…{end}")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod shorten_tests {
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn long_names_are_cut_in_the_middle() {
|
|
|
|
|
|
assert_eq!(super::shorten("Stockfish 19", 48), "Stockfish 19");
|
|
|
|
|
|
assert_eq!(super::shorten("abcdefghij", 5), "ab…ij");
|
|
|
|
|
|
assert_eq!(super::shorten("абвгдежзик", 7), "абв…зик");
|
|
|
|
|
|
assert_eq!(super::shorten("abcdefghij", 7).chars().count(), 7);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|