Comment editor: the reviewers' fixes
Shift+Enter is a paragraph (checked before Enter); the editor does not widen the
narrow panel (22-wide symbols, tighter margins); a variation's continuation after
the editor starts with the move number; 💾, «Add to database…», quitting and a
line preview write the draft first; Ctrl+1…6 with the editor open change its
draft; the ☰ item sits after «Game data…». Look: «Done» at the far right, Cancel
as tall; painted ✓/✕ in a narrow panel; 24-wide symbols with both groups on one
line at 1400; the pressed symbol in the selection's text colour; the field in its
own box; a readable hint line; the field capped so a notation row stays above
and below; the end of a long comment in view; the comment block lights up under
the mouse; the field is named after the title.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
7aee0467db
commit
fbb5233395
5 changed files with 315 additions and 117 deletions
|
|
@ -555,6 +555,10 @@ impl App {
|
|||
/// Ctrl+S: a game from a PGN that takes games is saved back into it; any other game
|
||||
/// is added to a database of the user's choice.
|
||||
fn save_current(&mut self, ctx: &egui::Context, then_close: Option<CloseIntent>) {
|
||||
// A comment being written goes into the game first.
|
||||
if let Some(g) = self.game.as_mut() {
|
||||
g.commit_editor();
|
||||
}
|
||||
let target = self.current_target();
|
||||
let Some(g) = &self.game else { return };
|
||||
self.own.then_close = then_close;
|
||||
|
|
@ -1992,6 +1996,14 @@ impl eframe::App for App {
|
|||
});
|
||||
self.applied_dark = Some(self.settings.dark_mode);
|
||||
}
|
||||
// Quitting: a comment being written goes into the game first, so the question
|
||||
// about unsaved changes counts it.
|
||||
if ctx.input(|i| i.viewport().close_requested())
|
||||
&& !self.allow_quit
|
||||
&& let Some(g) = self.game.as_mut()
|
||||
{
|
||||
g.commit_editor();
|
||||
}
|
||||
// Quitting with a modified game left for another (reference tab): show that one,
|
||||
// so the question "save?" is about the game that has the changes.
|
||||
if ctx.input(|i| i.viewport().close_requested())
|
||||
|
|
@ -2123,6 +2135,9 @@ impl eframe::App for App {
|
|||
}
|
||||
GameAction::Save => self.save_current(&ctx, None),
|
||||
GameAction::AddToDatabase => {
|
||||
if let Some(g) = self.game.as_mut() {
|
||||
g.commit_editor();
|
||||
}
|
||||
self.own.then_close = None;
|
||||
self.open_chooser(&ctx, ChooserFor::CurrentGame);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,9 +397,12 @@ impl GameView {
|
|||
}
|
||||
let ctrl = |k| KeyboardShortcut::new(Modifiers::COMMAND, k);
|
||||
let (done, paragraph, cancel, save, back, nag) = ui.input_mut(|i| {
|
||||
let done =
|
||||
i.consume_key(Modifiers::NONE, Key::Enter) || i.consume_shortcut(&ctrl(Key::Enter));
|
||||
// Shift+Enter first: a plain Enter would match it too (an extra Shift is
|
||||
// ignored by egui's key match).
|
||||
let paragraph = i.consume_key(Modifiers::SHIFT, Key::Enter);
|
||||
let done = !paragraph
|
||||
&& (i.consume_key(Modifiers::NONE, Key::Enter)
|
||||
|| i.consume_shortcut(&ctrl(Key::Enter)));
|
||||
let cancel = i.consume_key(Modifiers::NONE, Key::Escape);
|
||||
let save = i.consume_shortcut(&ctrl(Key::S));
|
||||
let back = i.consume_shortcut(&ctrl(Key::W));
|
||||
|
|
@ -1329,6 +1332,9 @@ impl GameView {
|
|||
if let Some((id, nag)) = resp.nag {
|
||||
self.toggle_nag_on(id, nag);
|
||||
}
|
||||
if resp.best.is_some() {
|
||||
self.commit_editor();
|
||||
}
|
||||
if let Some((id, shown)) = resp.best
|
||||
&& let Some(mark) = self.review.analysis.marks.get(&id)
|
||||
&& let Some(root) = self.game.position(mark.base)
|
||||
|
|
@ -1540,6 +1546,7 @@ impl GameView {
|
|||
if resp.clicked()
|
||||
&& let Some(root) = &root
|
||||
{
|
||||
self.commit_editor();
|
||||
self.preview = Some(Preview {
|
||||
base,
|
||||
root: root.clone(),
|
||||
|
|
@ -1701,6 +1708,15 @@ impl GameView {
|
|||
actions.push(GameAction::EditGameData);
|
||||
ui.close();
|
||||
}
|
||||
let comment = if self.cursor == NodeId::ROOT {
|
||||
tr("Comment at the start of the game… (Enter)")
|
||||
} else {
|
||||
tr("Comment on the move… (Enter)")
|
||||
};
|
||||
if ui.button(comment).clicked() {
|
||||
self.open_editor(Slot::After(self.cursor));
|
||||
ui.close();
|
||||
}
|
||||
let writable_source = self.source.as_ref().is_some_and(|s| s.block.is_none());
|
||||
if (writable_source || (self.source.is_none() && self.target.is_some()))
|
||||
&& ui.button(self.save_hint()).clicked()
|
||||
|
|
@ -1712,15 +1728,6 @@ impl GameView {
|
|||
actions.push(GameAction::AddToDatabase);
|
||||
ui.close();
|
||||
}
|
||||
let comment = if self.cursor == NodeId::ROOT {
|
||||
tr("Comment at the start of the game… (Enter)")
|
||||
} else {
|
||||
tr("Comment on the move… (Enter)")
|
||||
};
|
||||
if ui.button(comment).clicked() {
|
||||
self.open_editor(Slot::After(self.cursor));
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button(tr("Copy PGN")).clicked() {
|
||||
actions.push(self.copy_pgn());
|
||||
|
|
@ -1804,6 +1811,7 @@ impl GameView {
|
|||
.mainline()
|
||||
.into_iter()
|
||||
.find_map(|id| self.review.analysis.marks.get(&id).cloned());
|
||||
self.commit_editor();
|
||||
if let Some(mark) = mark
|
||||
&& let Some(root) = self.game.position(mark.base)
|
||||
&& !mark.best.is_empty()
|
||||
|
|
@ -2056,7 +2064,7 @@ impl GameView {
|
|||
}
|
||||
}
|
||||
// Taken: the Enter that closed a dialog this frame must not open the editor.
|
||||
if i.key_pressed(Key::Enter) && !overlay {
|
||||
if i.key_pressed(Key::Enter) && !overlay && i.modifiers.is_none() {
|
||||
i.consume_key(Modifiers::NONE, Key::Enter);
|
||||
cmds.push("comment");
|
||||
}
|
||||
|
|
@ -2074,7 +2082,13 @@ impl GameView {
|
|||
"nag1" | "nag2" | "nag3" | "nag4" | "nag5" | "nag6" => {
|
||||
if self.preview.is_none() {
|
||||
let k: u8 = cmd[3..].parse().unwrap_or(1);
|
||||
self.toggle_nag_on(self.cursor, Nag(k));
|
||||
// With the editor open the symbol is part of its draft.
|
||||
match self.editor.as_mut() {
|
||||
Some(ed) if ed.slot == Slot::After(self.cursor) => {
|
||||
ed.nags = toggle_nag(&ed.nags, Nag(k));
|
||||
}
|
||||
_ => self.toggle_nag_on(self.cursor, Nag(k)),
|
||||
}
|
||||
}
|
||||
}
|
||||
"copy" => actions.push(self.copy_pgn()),
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ impl Notation<'_> {
|
|||
.unwrap_or(&[]),
|
||||
);
|
||||
if editing == Some(Slot::After(NodeId::ROOT)) {
|
||||
editor_block(ui, &mut editor, &mut out);
|
||||
editor_block(ui, &mut editor, false, &mut out);
|
||||
} else if !root_comments.is_empty() {
|
||||
comment_block(
|
||||
ui,
|
||||
|
|
@ -200,7 +200,7 @@ impl Notation<'_> {
|
|||
let before = comment_text(n.comments_before());
|
||||
if editing == Some(Slot::Before(child)) {
|
||||
row.flush(ui, &self, &mut out);
|
||||
editor_block(ui, &mut editor, &mut out);
|
||||
editor_block(ui, &mut editor, false, &mut out);
|
||||
} else if !before.is_empty() {
|
||||
row.flush(ui, &self, &mut out);
|
||||
comment_block(ui, &self, &before, Slot::Before(child), &mut out);
|
||||
|
|
@ -231,7 +231,7 @@ impl Notation<'_> {
|
|||
mark_block(ui, &self, child, mark, &mut out);
|
||||
}
|
||||
if editing_after {
|
||||
editor_block(ui, &mut editor, &mut out);
|
||||
editor_block(ui, &mut editor, false, &mut out);
|
||||
} else if !after.is_empty() {
|
||||
comment_block(ui, &self, &after, Slot::After(child), &mut out);
|
||||
}
|
||||
|
|
@ -384,20 +384,38 @@ fn symbol_row(
|
|||
set: &[(Nag, &str, &'static str)],
|
||||
moves: bool,
|
||||
on: &mut dyn FnMut(Nag),
|
||||
) {
|
||||
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),
|
||||
) {
|
||||
let current = group_current(nags, !moves);
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 2.0;
|
||||
ui.spacing_mut().item_spacing.x = if w < SYMBOL_W { 1.0 } else { SYMBOL_GAP };
|
||||
for (nag, sym, name) in set {
|
||||
let mut text = RichText::new(*sym).size(15.0);
|
||||
if moves && let Some(c) = assessment_color(*nag) {
|
||||
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) {
|
||||
text = text.color(c);
|
||||
}
|
||||
let r = ui
|
||||
.add_sized(
|
||||
[28.0, 24.0],
|
||||
egui::Button::selectable(current == Some(*nag), text),
|
||||
)
|
||||
.add_sized([w, 24.0], egui::Button::selectable(pressed, text))
|
||||
.on_hover_text(symbol_hint(*nag, name));
|
||||
if r.clicked() {
|
||||
on(*nag);
|
||||
|
|
@ -688,20 +706,21 @@ fn comment_block(ui: &mut Ui, n: &Notation, text: &str, slot: Slot, out: &mut No
|
|||
bottom: 6,
|
||||
});
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
let r = frame.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
ui.label(RichText::new(shown).color(comment_color(ui)).size(14.5));
|
||||
});
|
||||
// The whole block, not only its text, takes the double click and the right button.
|
||||
let resp = ui.interact(
|
||||
r.response.rect,
|
||||
ui.id().with((
|
||||
"comment",
|
||||
slot.node().index(),
|
||||
matches!(slot, Slot::Before(_)),
|
||||
)),
|
||||
Sense::click(),
|
||||
);
|
||||
let resp = ui.interact(r.response.rect, id, Sense::click());
|
||||
comment_response(&resp, slot, out);
|
||||
if let Some(m) = mark {
|
||||
let at = r.response.rect.right_top() + vec2(-8.0, 7.0);
|
||||
|
|
@ -731,7 +750,13 @@ fn comment_response(resp: &egui::Response, slot: Slot, out: &mut NotationRespons
|
|||
}
|
||||
|
||||
/// The comment editor on the spot of its comment (user-comments.md §3.4).
|
||||
fn editor_block(ui: &mut Ui, editor: &mut Option<&mut CommentEditor>, out: &mut NotationResponse) {
|
||||
/// `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,
|
||||
) {
|
||||
let Some(ed) = editor.as_deref_mut() else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -746,67 +771,99 @@ fn editor_block(ui: &mut Ui, editor: &mut Option<&mut CommentEditor>, out: &mut
|
|||
};
|
||||
let width = ui.available_width();
|
||||
let narrow = width < 360.0;
|
||||
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(_));
|
||||
let r = egui::Frame::new()
|
||||
.fill(ui.visuals().extreme_bg_color)
|
||||
.inner_margin(egui::Margin::symmetric(10, 6))
|
||||
.inner_margin(margin)
|
||||
.stroke(stroke)
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
// The title and the buttons.
|
||||
ui.horizontal(|ui| {
|
||||
let buttons = if narrow { 2.0 * 30.0 } else { 150.0 };
|
||||
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
|
||||
};
|
||||
ui.add(egui::Label::new(RichText::new(title).strong()).truncate());
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
if narrow {
|
||||
if ui
|
||||
.add(egui::Button::new("×").min_size(vec2(0.0, 30.0)))
|
||||
.on_hover_text(tr("Cancel (Esc)"))
|
||||
.clicked()
|
||||
{
|
||||
out.editor = Some(EditorOutcome::Cancel);
|
||||
}
|
||||
if crate::widgets::primary(ui, "✔")
|
||||
.on_hover_text(tr("Done (Enter)"))
|
||||
.clicked()
|
||||
{
|
||||
out.editor = Some(EditorOutcome::Done);
|
||||
}
|
||||
// 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 {
|
||||
if ui
|
||||
.add(egui::Button::new(tr("Cancel")).min_size(vec2(0.0, 30.0)))
|
||||
.on_hover_text("Esc")
|
||||
.clicked()
|
||||
{
|
||||
out.editor = Some(EditorOutcome::Cancel);
|
||||
}
|
||||
if crate::widgets::primary(ui, tr("Done"))
|
||||
.on_hover_text("Enter")
|
||||
.clicked()
|
||||
{
|
||||
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() {
|
||||
out.editor = Some(EditorOutcome::Done);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if cancel.clicked() {
|
||||
out.editor = Some(EditorOutcome::Cancel);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
// 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.
|
||||
if ed.slot != Slot::After(NodeId::ROOT) && !matches!(ed.slot, Slot::Before(_)) {
|
||||
let both = 14.0 * 30.0 + 24.0 <= ui.available_width();
|
||||
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
|
||||
};
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 4.0;
|
||||
let mut toggled = None;
|
||||
symbol_row(ui, &ed.nags, &MOVE_NAGS, true, &mut |nag| {
|
||||
symbol_row_sized(ui, &ed.nags, &MOVE_NAGS, true, w, &mut |nag| {
|
||||
toggled = Some(nag)
|
||||
});
|
||||
if both {
|
||||
ui.separator();
|
||||
ui.add(egui::Separator::default().spacing(12.0));
|
||||
symbol_row(ui, &ed.nags, &POSITION_NAGS, false, &mut |nag| {
|
||||
toggled = Some(nag)
|
||||
});
|
||||
|
|
@ -830,58 +887,101 @@ fn editor_block(ui: &mut Ui, editor: &mut Option<&mut CommentEditor>, out: &mut
|
|||
}
|
||||
});
|
||||
}
|
||||
// The text: 2 to 12 lines, then it scrolls inside.
|
||||
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.
|
||||
let color = comment_color(ui);
|
||||
let row_h = ui.fonts_mut(|f| f.row_height(&FontId::proportional(14.5)));
|
||||
let resp = egui::ScrollArea::vertical()
|
||||
.id_salt("comment_editor_scroll")
|
||||
.max_height(12.0 * row_h + 8.0)
|
||||
.auto_shrink([false, true])
|
||||
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))
|
||||
.show(ui, |ui| {
|
||||
ui.add(
|
||||
egui::TextEdit::multiline(&mut ed.text)
|
||||
.id_salt("comment_editor")
|
||||
.desired_rows(2)
|
||||
.desired_width(f32::INFINITY)
|
||||
.font(FontId::proportional(14.5))
|
||||
.text_color(color)
|
||||
.hint_text(tr("Your comment…")),
|
||||
)
|
||||
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
|
||||
})
|
||||
.inner;
|
||||
ed.field_id = Some(resp.id);
|
||||
if std::mem::take(&mut ed.focus) {
|
||||
resp.request_focus();
|
||||
// The cursor at the end: one adds to a comment more often than replaces it.
|
||||
if let Some(mut state) = egui::TextEdit::load_state(ui.ctx(), resp.id) {
|
||||
let end = egui::text::CCursor::new(ed.text.chars().count());
|
||||
state
|
||||
.cursor
|
||||
.set_char_range(Some(egui::text::CCursorRange::one(end)));
|
||||
state.store(ui.ctx(), resp.id);
|
||||
}
|
||||
if let Some(t) = title_id {
|
||||
resp.clone().labelled_by(t);
|
||||
}
|
||||
if !narrow {
|
||||
ui.add_space(4.0);
|
||||
ui.label(
|
||||
RichText::new(tr(
|
||||
"Enter — done · Esc — cancel · Shift+Enter — new paragraph",
|
||||
))
|
||||
.weak()
|
||||
.small(),
|
||||
.size(11.5)
|
||||
.color(ui.visuals().weak_text_color()),
|
||||
);
|
||||
}
|
||||
if ed.translated {
|
||||
ui.add_space(2.0);
|
||||
ui.label(
|
||||
RichText::new(tr(
|
||||
"⇄ You are editing the original; its translation will be dropped",
|
||||
))
|
||||
.weak()
|
||||
.small(),
|
||||
.size(11.5)
|
||||
.color(ui.visuals().weak_text_color()),
|
||||
);
|
||||
}
|
||||
});
|
||||
if std::mem::take(&mut ed.scroll) {
|
||||
r.response.scroll_to_me(None);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -910,6 +1010,8 @@ enum Token {
|
|||
Move {
|
||||
id: NodeId,
|
||||
label: String,
|
||||
/// The label with the move number, for the move that starts a piece of the flow.
|
||||
numbered: String,
|
||||
color: Option<Color32>,
|
||||
},
|
||||
Comment {
|
||||
|
|
@ -952,28 +1054,45 @@ fn variation_block(
|
|||
block_frame(ui).show(ui, |ui| {
|
||||
ui.set_width(ui.available_width());
|
||||
match cut {
|
||||
None => flow(ui, n, &tokens, out),
|
||||
None => flow(ui, n, &tokens, false, out),
|
||||
Some((at, replaces)) => {
|
||||
flow(ui, n, &tokens[..at], out);
|
||||
editor_block(ui, editor, out);
|
||||
flow(ui, n, &tokens[..at], false, out);
|
||||
editor_block(ui, editor, true, out);
|
||||
let rest = if replaces { at + 1 } else { at };
|
||||
flow(ui, n, &tokens[rest..], out);
|
||||
flow(ui, n, &tokens[rest..], true, out);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Lays out tokens as flowing text.
|
||||
fn flow(ui: &mut Ui, n: &Notation, tokens: &[Token], out: &mut NotationResponse) {
|
||||
fn flow(
|
||||
ui: &mut Ui,
|
||||
n: &Notation,
|
||||
tokens: &[Token],
|
||||
numbered_first: bool,
|
||||
out: &mut NotationResponse,
|
||||
) {
|
||||
if tokens.is_empty() {
|
||||
return;
|
||||
}
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = vec2(3.0, 2.0);
|
||||
for t in tokens {
|
||||
for (k, t) in tokens.iter().enumerate() {
|
||||
match t {
|
||||
Token::Move { id, label, color } => {
|
||||
Token::Move {
|
||||
id,
|
||||
label,
|
||||
numbered,
|
||||
color,
|
||||
} => {
|
||||
let current = *id == n.cursor;
|
||||
// After the editor the flow starts anew: with the move number.
|
||||
let label = if k == 0 && numbered_first {
|
||||
numbered
|
||||
} else {
|
||||
label
|
||||
};
|
||||
let mut text = RichText::new(label).size(15.0);
|
||||
if let Some(c) = color
|
||||
&& !current
|
||||
|
|
@ -1047,9 +1166,14 @@ fn line_tokens(n: &Notation, first: NodeId, tokens: &mut Vec<Token>) {
|
|||
(Color::Black, false) => format!("{san}{sym}"),
|
||||
};
|
||||
need_number = false;
|
||||
let numbered = match color {
|
||||
Color::White => label.clone(),
|
||||
Color::Black => format!("{num}…{san}{sym}"),
|
||||
};
|
||||
tokens.push(Token::Move {
|
||||
id: node,
|
||||
label,
|
||||
numbered,
|
||||
color: sym_color,
|
||||
});
|
||||
let after = comment_text(nd.comments_after());
|
||||
|
|
|
|||
|
|
@ -78,3 +78,47 @@ pub fn primary(ui: &mut egui::Ui, label: &str) -> egui::Response {
|
|||
.min_size(egui::vec2(0.0, 30.0)),
|
||||
)
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -497,3 +497,4 @@
|
|||
4. **Абзацы (§8.3):** делать правку записи PGN сейчас? От неё зависят Shift+Enter и сохранность абзацев книжных комментариев при любом сохранении.
|
||||
5. **Стрелки и поля** — следующим шагом после комментариев или позже?
|
||||
- 2026-10-25: решения владельца (`decisions.md` п. 20): вариант A, Esc — отмена, значки мышью в меню и редакторе плюс Ctrl+1…6, стрелки и поля на доске — в первую версию (см. «Потом» п. 1 — перенесено в первую версию).
|
||||
- 2026-10-25, после проверки реализации (тестировщик + дизайнер): кнопки — «Готово» у правого края, «Отмена» слева от неё, обе 30 высотой (как во всех окнах); в узкой панели — нарисованные ✓/✕ 30 × 30 (в шрифте нет таких глифов); значки 24 × 24, порог для двух групп в одну строку — 154 + 4 + 12 + 4 + 206 = 380 (в панели 240 — 22 × 24 и «±▾»); нажатый значок — цветом текста выделения, не цветом оценки; поле в собственной рамке (фон панели / белый, обводка 1); подсказка под полем 11,5 с отступом 4; высота поля ограничена так, чтобы над и под редактором оставалось по строке нотации, при открытии в вид прокручивается и строка хода; у длинного комментария конец (с курсором) виден сразу; продолжение варианта после редактора начинается с номера хода; Shift+Enter — абзац (проверяется раньше Enter); блок комментария подсвечивается под мышью и целиком принимает двойной и правый щелчок; заметка на языке интерфейса в чужой книге не идёт в перевод.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue