From 38841574fb4f351e83da222275eb35a3d21ab5b1 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Sat, 24 Oct 2026 10:39:38 +0300 Subject: [PATCH] =?UTF-8?q?Desktop:=20narrow=20windows=20after=20testing?= =?UTF-8?q?=20=E2=80=94=20Escape=20and=20the=20filters=20over=20the=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The library's Escape waits while a window is open over it (settings, notes); on the board alone it first puts back a picked-up piece. - A condition's chip clicked with the filters over the list keeps them open; widening the window with them open over the board alone keeps the board. - The list's header leaves the database's name out before taking a second line. - The report's long names wrap in a narrow panel. - In the 'Game modified' question Escape is Cancel when quitting the program. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 ++ apps/desktop/src/app.rs | 32 +++++++++++++++++---- apps/desktop/src/board_search.rs | 10 +++++++ apps/desktop/src/large_db.rs | 48 ++++++++++++++++++++++---------- apps/desktop/src/library.rs | 5 ++-- apps/desktop/src/review.rs | 3 +- 6 files changed, 76 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a2fb6..8018b8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ All notable changes are listed here. Versions follow [Semantic Versioning](https - a narrow tall window shows the notation under the board; - the header of the list and the shelf shorten what does not fit, or take a second line; the window can be made as small as 640×480. +- Desktop: Escape in the "Game modified" question quits nothing: when closing the program + it is Cancel (leaving a game, it still goes on without saving). ## [0.16.1] — 2026-10-24 diff --git a/apps/desktop/src/app.rs b/apps/desktop/src/app.rs index d6ff17d..6af87f2 100644 --- a/apps/desktop/src/app.rs +++ b/apps/desktop/src/app.rs @@ -31,6 +31,12 @@ pub const TOAST: &str = "toast"; /// Something is open over the screen — a window, a menu, a dialog — in this frame or the /// last one: Escape is meant for it (it closes itself), not for leaving the screen. pub fn overlay_open(ctx: &egui::Context) -> bool { + overlay_open_besides(ctx, &[]) +} + +/// `overlay_open`, not counting these layers of the screen itself (the filters over +/// the list). +pub fn overlay_open_besides(ctx: &egui::Context, own: &[egui::Id]) -> bool { let passive = [ egui::Id::new(TOAST), egui::Id::new(crate::engine_offer::DOWNLOAD_INDICATOR), @@ -40,6 +46,7 @@ pub fn overlay_open(ctx: &egui::Context) -> bool { .any(|l| { matches!(l.order, egui::Order::Middle | egui::Order::Foreground) && !passive.contains(&l.id) + && !own.contains(&l.id) }) } @@ -761,14 +768,27 @@ impl App { if ui.button(tr("Save as…")).clicked() { choice = Some(0); } - // Escape goes on where the user was going (the owner's choice): the - // second Escape of "Escape, Escape" leaves without saving. Cancel stays. - if ui.button(tr("Don't save")).on_hover_text("Esc").clicked() - || ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, Key::Escape)) - { + // Escape goes on where the user was going back to (the owner's choice): + // the second Escape of "Escape, Escape" leaves the game without saving. + // Quitting the program is not undone that lightly: there it is Cancel. + let leaving = intent != CloseIntent::QuitApp; + let esc = ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, Key::Escape)); + let dont = ui.button(tr("Don't save")); + let dont = if leaving { + dont.on_hover_text("Esc") + } else { + dont + }; + if dont.clicked() || (esc && leaving) { choice = Some(1); } - if ui.button(tr("Cancel")).clicked() { + let cancel = ui.button(tr("Cancel")); + let cancel = if leaving { + cancel + } else { + cancel.on_hover_text("Esc") + }; + if cancel.clicked() || (esc && !leaving) { choice = Some(2); } }); diff --git a/apps/desktop/src/board_search.rs b/apps/desktop/src/board_search.rs index 56aad87..5e9316b 100644 --- a/apps/desktop/src/board_search.rs +++ b/apps/desktop/src/board_search.rs @@ -126,6 +126,16 @@ impl SearchBoard { } /// A position is a search condition once it differs from the usual start. + /// A piece is picked up or dragged, or a promotion is being chosen. + pub fn is_busy(&self) -> bool { + self.board.is_busy() + } + + /// Puts the piece back (Escape). + pub fn drop_pick(&mut self) { + self.board.clear(); + } + pub fn is_set(&self) -> bool { self.cursor > 0 || self.start_fen.is_some() } diff --git a/apps/desktop/src/large_db.rs b/apps/desktop/src/large_db.rs index 265a980..2e689f1 100644 --- a/apps/desktop/src/large_db.rs +++ b/apps/desktop/src/large_db.rs @@ -324,6 +324,8 @@ pub struct LargeView { narrow_filters: bool, narrow_board: bool, drawer_open: bool, + /// Something asked for the filters this frame (it was clicked, not "elsewhere"). + drawer_asked: bool, /// Where the filters open over the table: under its header and conditions. drawer_top: f32, /// The quick search has the keyboard (arrows and Enter go to the table). @@ -408,6 +410,7 @@ impl LargeView { narrow_filters: drawer, narrow_board: false, drawer_open: drawer, + drawer_asked: false, drawer_top: 0.0, } } @@ -459,12 +462,16 @@ impl LargeView { /// The layout the window allows (§2.1). Narrowing closes the filters rather than /// laying them over the table; widening docks the filters opened over it. pub fn set_layout(&mut self, narrow_filters: bool, narrow_board: bool) { + // Called first in each frame: what asked for the filters is this frame's. + self.drawer_asked = false; if narrow_filters && !self.narrow_filters { self.drawer_open = false; } if !narrow_filters && self.narrow_filters && self.drawer_open { + // The filters opened over the list dock; opened over the board, they close + // and the board stays (beside the list now, or alone). self.drawer_open = false; - if self.pane != Pane::Board || !narrow_board { + if self.pane != Pane::Board { self.pane = Pane::Filters; } } @@ -477,8 +484,12 @@ impl LargeView { (self.narrow_filters && self.drawer_open).then_some(self.drawer_top) } - pub fn close_drawer(&mut self) { - self.drawer_open = false; + /// A click elsewhere closes the filters over the list, unless that click asked for + /// them (a condition's chip). + pub fn close_drawer_on_click(&mut self) { + if !self.drawer_asked { + self.drawer_open = false; + } } /// The board takes the place of the table (a narrow window). @@ -489,7 +500,11 @@ impl LargeView { /// Escape in the library with no field typing: the filters over the table close, /// then the board alone gives the place back to the table. pub fn escape(&mut self) -> bool { - if self.drawer().is_some() { + if self.board_alone() && self.board.is_busy() { + // A piece picked up on the board is put back first, as in a game. + self.board.drop_pick(); + true + } else if self.drawer().is_some() { self.drawer_open = false; true } else if self.board_alone() { @@ -505,6 +520,7 @@ impl LargeView { fn open_filters(&mut self) { if self.narrow_filters { self.drawer_open = true; + self.drawer_asked = true; if !self.board_alone() { self.pane = Pane::Filters; } @@ -1655,17 +1671,19 @@ impl LargeView { let avail = ui.available_width(); let right = |field: f32| switch_w + 8.0 + search_w(field); // One line: the widest field that leaves the counter and at least 80 of the name. - let one_line = [(220.0, true), (220.0, false), (140.0, false)] - .into_iter() - .find(|(field, with_format)| { - let rest = - avail - right(*field) - info_w - if *with_format { format_w } else { 0.0 }; - if *with_format { - rest >= name_w - } else { - rest >= 80.0 + gap - } - }); + // (field, format, the name's least room: 0 leaves the name out) + let one_line = [ + (220.0, true, name_w), + (220.0, false, 80.0 + gap), + (140.0, false, 80.0 + gap), + (140.0, false, 0.0), + ] + .into_iter() + .find(|(field, with_format, name_least)| { + let format = if *with_format { format_w } else { 0.0 }; + avail - right(*field) - info_w - format >= *name_least + }) + .map(|(field, with_format, _)| (field, with_format)); let field = match one_line { Some((field, _)) => field, None if avail - right(220.0) >= 80.0 + gap => 220.0, diff --git a/apps/desktop/src/library.rs b/apps/desktop/src/library.rs index c6d920e..e3a2e7b 100644 --- a/apps/desktop/src/library.rs +++ b/apps/desktop/src/library.rs @@ -443,13 +443,14 @@ impl Library { view.panel(ui, &db); }); }); - if area.response.clicked_elsewhere() && !ui.ctx().is_being_dragged(area.response.id) { - view.close_drawer(); + if area.response.clicked_elsewhere() { + view.close_drawer_on_click(); } } // Escape: the filters over the table close, then the board alone gives the place // back to the table (a field takes its own Escape first). if !typing + && !crate::app::overlay_open_besides(ui.ctx(), &[egui::Id::new("filters_drawer")]) && let Some(path) = self.selected_db.clone() && let Some(view) = self.large.get_mut(&path) && ui.input(|i| i.key_pressed(egui::Key::Escape)) diff --git a/apps/desktop/src/review.rs b/apps/desktop/src/review.rs index a6a5699..f295aa6 100644 --- a/apps/desktop/src/review.rs +++ b/apps/desktop/src/review.rs @@ -632,7 +632,8 @@ impl Review { if let Some(c) = color { t = t.color(c); } - ui.label(t); + // A long name ("Average centipawn loss") wraps in a narrow panel. + ui.add(egui::Label::new(t).wrap()); ui.end_row(); }; let dash = || "—".to_string();