From e920ce2b18435c804e69129f5c8de814c9f38d1a Mon Sep 17 00:00:00 2001 From: VoiceLessQ Date: Thu, 29 Oct 2026 18:47:04 -0200 Subject: [PATCH 1/3] fix(ui): keep the custom title bar's buttons above dialogs (#853) With a dialog, the app details drawer or the screenshot lightbox open, the first click on the header's Close (or Minimize, Maximize) landed on the overlay's backdrop and only dismissed it; a second click closed the window. The launcher-update prompt opens at every start while a newer launcher is out, so an outdated install meets this on its first close. egui lets only layers at or above the top modal take input, and these backdrops cover the whole window, header included. The caption buttons keep their room in the header but are drawn in their own tooltip-order area, moved to the top each frame so the lightbox (tooltip order too) stays under them, as it would under a system title bar. --- crates/ui-egui/src/widgets.rs | 38 ++++++++++++++++++++++++----------- crates/ui-egui/tests/ui.rs | 18 +++++++++++++++++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 5442b638..6f1409b0 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -134,6 +134,8 @@ pub fn nav_icon(ui: &mut Ui, glyph: Glyph, tip: &str, height: f32, busy: bool) - /// How far in from the window's edges a custom title bar's window resizes ([`window_edges`]). /// The title bar's own controls leave this band alone. const RESIZE_EDGE: f32 = 5.0; +/// Width of one caption button, as Windows' own. +const CAPTION_W: f32 = 46.0; /// How wide the resize band along the window's edges is right now: nothing while the window is /// maximized or full screen, when `window_edges` offers no resizing and the edges are the screen's, @@ -169,20 +171,32 @@ enum WindowButton { } /// Minimize, maximize (or restore) and close, `height` tall, for a right-to-left layout: close -/// ends up at the right. +/// ends up at the right. They take their room in the header but are drawn in a layer above the +/// dialogs, the details drawer and the lightbox, as a system title bar is, so a click on them is +/// not spent closing one of those first (#853). pub fn window_buttons(ui: &mut Ui, height: f32) { let ctx = ui.ctx().clone(); let maximized = ctx.input(|i| i.viewport().maximized.unwrap_or(false)); - if window_button(ui, WindowButton::Close, height).clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Close); - } - let size = if maximized { WindowButton::Restore } else { WindowButton::Maximize }; - if window_button(ui, size, height).clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized)); - } - if window_button(ui, WindowButton::Minimize, height).clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true)); - } + let (rect, _) = ui.allocate_exact_size(vec2(3.0 * CAPTION_W, height), Sense::hover()); + let area = egui::Area::new(egui::Id::unique("window-buttons")).order(egui::Order::Tooltip).fixed_pos(rect.min); + // The lightbox is a tooltip-order layer too, opened later. + ctx.move_to_top(area.layer()); + area.show(&ctx, |ui| { + // Left to right: a right-to-left layout would widen the area over the header. + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing.x = 0.0; + if window_button(ui, WindowButton::Minimize, height).clicked() { + ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true)); + } + let size = if maximized { WindowButton::Restore } else { WindowButton::Maximize }; + if window_button(ui, size, height).clicked() { + ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized)); + } + if window_button(ui, WindowButton::Close, height).clicked() { + ctx.send_viewport_cmd(egui::ViewportCommand::Close); + } + }); + }); rule(ui, height); } @@ -192,7 +206,7 @@ pub fn window_buttons(ui: &mut Ui, height: f32) { /// corner. fn window_button(ui: &mut Ui, button: WindowButton, height: f32) -> Response { let t = Tokens::get(ui.ctx()); - let (rect, _) = ui.allocate_exact_size(vec2(46.0, height), Sense::hover()); + let (rect, _) = ui.allocate_exact_size(vec2(CAPTION_W, height), Sense::hover()); // Clickable below the resize band along the top (and, for close, the right edge); maximized, // there is no band and the close button takes the screen's corner, as Windows' own does. let band = resize_band(ui.ctx()); diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs index 7725a4c6..d89d3060 100644 --- a/crates/ui-egui/tests/ui.rs +++ b/crates/ui-egui/tests/ui.rs @@ -2060,6 +2060,24 @@ fn custom_title_bar_has_window_buttons() { assert!(closes, "the close button asks the window to close (the shell decides whether that hides it to the tray)"); } +/// With a dialog open, one click on the custom title bar's Close closes the window: the caption +/// buttons sit above the dialog's backdrop, as a system title bar does, so the click isn't spent +/// dismissing the dialog first (#853). The header's own controls beside them still take clicks. +#[test] +fn close_button_closes_with_a_dialog_open() { + let (mut h, _) = harness_with_title_bar(events(), ViewMode::Grid, egui::Theme::Dark, true, 1.0, artcraft_launcher_ui_egui::TitleBar::Custom); + h.run_steps(6); + h.get_by_label("Settings").click(); + h.run_steps(2); + h.get_by_label("Done"); + h.get_by_label("Close").click(); + h.step(); + let closes = h.output().viewport_output.values().any(|v| v.commands.contains(&egui::ViewportCommand::Close)); + assert!(closes, "the first click on Close closes the window"); + h.run_steps(2); + h.get_by_label("Done"); +} + /// Maximized, the window's top-right pixel is the screen's corner: there is no resize band there, /// so it belongs to the close button, as it does with Windows' own caption buttons (#374). #[test] From 101d5e5a4404abfcd22cb4a7904ff4ba02baa043 Mon Sep 17 00:00:00 2001 From: VoiceLessQ Date: Thu, 29 Oct 2026 19:21:22 -0200 Subject: [PATCH 2/3] fix(ui): lift the caption buttons only while a dialog is open (#853) Drawn above every overlay, the caption buttons covered the screenshot lightbox's own Close (x 1070-1104, y 16-50 in a 1120-wide window), so a click on it closed the window. An app's menu that opens up into the title bar would lose its corner to them as well. Now they move above the backdrop only while a dialog blocks the header (egui's modal layer); the rest of the time they stay in the header, under every overlay, as on main. They are drawn with `UiBuilder::layer_id` rather than an `Area`: a new area spends its first frame on an invisible sizing pass, which would hide the buttons for a frame the first time a dialog opens. --- crates/ui-egui/src/widgets.rs | 40 +++++++++++++++++------------------ crates/ui-egui/tests/ui.rs | 20 ++++++++++++++++++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 6f1409b0..fccecc68 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -171,31 +171,29 @@ enum WindowButton { } /// Minimize, maximize (or restore) and close, `height` tall, for a right-to-left layout: close -/// ends up at the right. They take their room in the header but are drawn in a layer above the -/// dialogs, the details drawer and the lightbox, as a system title bar is, so a click on them is -/// not spent closing one of those first (#853). +/// ends up at the right. Under a dialog egui ignores the header, so there they are drawn in a +/// layer above the dialog's backdrop, as a system title bar is: the first click on Close closes +/// the window, not the dialog (#853). The details drawer and the lightbox still cover them, since +/// their own controls and the apps' menus can sit in that corner. pub fn window_buttons(ui: &mut Ui, height: f32) { let ctx = ui.ctx().clone(); let maximized = ctx.input(|i| i.viewport().maximized.unwrap_or(false)); let (rect, _) = ui.allocate_exact_size(vec2(3.0 * CAPTION_W, height), Sense::hover()); - let area = egui::Area::new(egui::Id::unique("window-buttons")).order(egui::Order::Tooltip).fixed_pos(rect.min); - // The lightbox is a tooltip-order layer too, opened later. - ctx.move_to_top(area.layer()); - area.show(&ctx, |ui| { - // Left to right: a right-to-left layout would widen the area over the header. - ui.horizontal(|ui| { - ui.spacing_mut().item_spacing.x = 0.0; - if window_button(ui, WindowButton::Minimize, height).clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true)); - } - let size = if maximized { WindowButton::Restore } else { WindowButton::Maximize }; - if window_button(ui, size, height).clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized)); - } - if window_button(ui, WindowButton::Close, height).clicked() { - ctx.send_viewport_cmd(egui::ViewportCommand::Close); - } - }); + let mut row = egui::UiBuilder::new().max_rect(rect).layout(egui::Layout::left_to_right(egui::Align::Center)); + if !ctx.memory(|m| m.is_above_modal_layer(ui.layer_id())) { + row = row.layer_id(egui::LayerId::new(egui::Order::Tooltip, egui::Id::unique("window-buttons"))); + } + ui.scope_builder(row, |ui| { + if window_button(ui, WindowButton::Minimize, height).clicked() { + ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true)); + } + let size = if maximized { WindowButton::Restore } else { WindowButton::Maximize }; + if window_button(ui, size, height).clicked() { + ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized)); + } + if window_button(ui, WindowButton::Close, height).clicked() { + ctx.send_viewport_cmd(egui::ViewportCommand::Close); + } }); rule(ui, height); } diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs index d89d3060..82aff8e3 100644 --- a/crates/ui-egui/tests/ui.rs +++ b/crates/ui-egui/tests/ui.rs @@ -2078,6 +2078,26 @@ fn close_button_closes_with_a_dialog_open() { h.get_by_label("Done"); } +/// The enlarged picture's own Close sits under the custom title bar's Close. With no dialog open +/// the caption buttons stay in the header, under the picture, so that click closes the picture +/// and not the window. +#[test] +fn the_enlarged_pictures_close_closes_the_picture_not_the_window() { + let (mut h, _) = harness_with_title_bar(events(), ViewMode::Grid, egui::Theme::Dark, true, 1.0, artcraft_launcher_ui_egui::TitleBar::Custom); + h.run_steps(8); + h.get_by_label("PhotoCraft details").click(); + h.run_steps(10); + h.get_by_label("Enlarge picture").click(); + h.run_steps(4); + // The drawer's Close is lower down; the picture's is at the top right, under the title bar. + h.query_all_by_label("Close (Esc)").min_by(|a, b| a.rect().top().total_cmp(&b.rect().top())).unwrap().click(); + h.step(); + let closes = h.output().viewport_output.values().any(|v| v.commands.contains(&egui::ViewportCommand::Close)); + assert!(!closes, "the click reached the window's Close"); + h.run_steps(4); + assert_eq!(h.query_all_by_label("Close (Esc)").count(), 1, "the enlarged picture is still open"); +} + /// Maximized, the window's top-right pixel is the screen's corner: there is no resize band there, /// so it belongs to the close button, as it does with Windows' own caption buttons (#374). #[test] From 3309187e716a44de4862d23ae7fe81dd4d940afa Mon Sep 17 00:00:00 2001 From: VoiceLessQ Date: Sun, 1 Nov 2026 11:59:20 -0200 Subject: [PATCH 3/3] fix(ui): Tab stays in a dialog while the caption buttons sit above it (#853) Lifting the row put Minimize, Maximize and Close first in the dialog's Tab order, so Tab then Enter minimized the window. Above a dialog they now sense clicks only. The new tests also cover a click just beside the row and the details drawer, and the lightbox test presses where the two Close buttons overlap. --- crates/ui-egui/src/widgets.rs | 13 ++++--- crates/ui-egui/tests/ui.rs | 69 +++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index fccecc68..ab7a8d05 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -180,18 +180,21 @@ pub fn window_buttons(ui: &mut Ui, height: f32) { let maximized = ctx.input(|i| i.viewport().maximized.unwrap_or(false)); let (rect, _) = ui.allocate_exact_size(vec2(3.0 * CAPTION_W, height), Sense::hover()); let mut row = egui::UiBuilder::new().max_rect(rect).layout(egui::Layout::left_to_right(egui::Align::Center)); + let mut sense = Sense::click(); if !ctx.memory(|m| m.is_above_modal_layer(ui.layer_id())) { row = row.layer_id(egui::LayerId::new(egui::Order::Tooltip, egui::Id::unique("window-buttons"))); + // Pointer only: Tab stays in the dialog. + sense = Sense::CLICK; } ui.scope_builder(row, |ui| { - if window_button(ui, WindowButton::Minimize, height).clicked() { + if window_button(ui, WindowButton::Minimize, height, sense).clicked() { ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(true)); } let size = if maximized { WindowButton::Restore } else { WindowButton::Maximize }; - if window_button(ui, size, height).clicked() { + if window_button(ui, size, height, sense).clicked() { ctx.send_viewport_cmd(egui::ViewportCommand::Maximized(!maximized)); } - if window_button(ui, WindowButton::Close, height).clicked() { + if window_button(ui, WindowButton::Close, height, sense).clicked() { ctx.send_viewport_cmd(egui::ViewportCommand::Close); } }); @@ -202,7 +205,7 @@ pub fn window_buttons(ui: &mut Ui, height: f32) { /// command. Hit-testing excludes the top resize band (and, for close, the right-edge band) so /// the window edges stay resizable; when maximized there is no band and close reaches the /// corner. -fn window_button(ui: &mut Ui, button: WindowButton, height: f32) -> Response { +fn window_button(ui: &mut Ui, button: WindowButton, height: f32, sense: Sense) -> Response { let t = Tokens::get(ui.ctx()); let (rect, _) = ui.allocate_exact_size(vec2(CAPTION_W, height), Sense::hover()); // Clickable below the resize band along the top (and, for close, the right edge); maximized, @@ -210,7 +213,7 @@ fn window_button(ui: &mut Ui, button: WindowButton, height: f32) -> Response { let band = resize_band(ui.ctx()); let right = if button == WindowButton::Close { band } else { 0.0 }; let hit = Rect::from_min_max(rect.min + vec2(0.0, band), rect.max - vec2(right, 0.0)); - let resp = ui.interact(hit, ui.scope_id().with(("window-button", button as u8)), Sense::click()); + let resp = ui.interact(hit, ui.scope_id().with(("window-button", button as u8)), sense); let (fill, ink) = match (button, resp.hovered()) { (WindowButton::Close, true) => (Color32::from_rgb(0xc4, 0x2b, 0x1c), Color32::WHITE), (_, true) => (t.line, t.ink_strong), diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs index 3242587e..8d54e188 100644 --- a/crates/ui-egui/tests/ui.rs +++ b/crates/ui-egui/tests/ui.rs @@ -2077,6 +2077,66 @@ fn close_button_closes_with_a_dialog_open() { h.get_by_label("Done"); } +/// Presses and releases at `pos`, and returns what the window was asked to do. +fn click_at(h: &mut Harness<'_, Option>, pos: egui::Pos2) -> Vec { + let mut asked = Vec::new(); + for pressed in [true, false] { + let input = h.input_mut(); + input.events.push(egui::Event::PointerMoved(pos)); + input.events.push(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }); + h.step(); + asked.extend(h.output().viewport_output.values().flat_map(|v| v.commands.iter().cloned())); + } + h.run_steps(2); + asked +} + +/// Above a dialog the caption buttons are for the pointer alone: Tab stays in the dialog, and a +/// click just beside them is still the backdrop's (#853). +#[test] +fn the_lifted_caption_buttons_leave_tab_and_the_backdrop_to_the_dialog() { + let (mut h, _) = harness_with_title_bar(events(), ViewMode::Grid, egui::Theme::Dark, true, 1.0, artcraft_launcher_ui_egui::TitleBar::Custom); + h.run_steps(6); + let tab = |h: &mut Harness<'_, Option>| -> String { + h.key_press(egui::Key::Tab); + h.run_steps(2); + let focused = h.root().query_all(egui_kittest::kittest::by()).find(|n| n.accesskit_node().is_focused()); + focused.map_or(String::new(), |n| n.accesskit_node().label().unwrap_or_default().to_string()) + }; + let caption = ["Minimize", "Maximize", "Close"]; + let reached: Vec = (0..4).map(|_| tab(&mut h)).filter(|l| caption.contains(&l.as_str())).collect(); + assert_eq!(reached, caption, "without a dialog Tab reaches them in the order they're drawn"); + h.get_by_label("Settings").click(); + h.run_steps(3); + assert_eq!(tab(&mut h), "Language", "the first Tab goes to the dialog"); + for _ in 0..40 { + let focused = tab(&mut h); + assert!(!caption.contains(&focused.as_str()), "Tab left the dialog for {focused}"); + } + let close = h.get_by_label("Close").rect(); + let asked = click_at(&mut h, egui::pos2(close.center().x, close.bottom() + 3.0)); + assert!(asked.is_empty(), "below Close: {asked:?}"); + assert!(h.query_by_label("Done").is_none(), "a click below Close dismisses the dialog"); + h.get_by_label("Settings").click(); + h.run_steps(3); + let minimize = h.get_by_label("Minimize").rect(); + let asked = click_at(&mut h, egui::pos2(minimize.left() - 3.0, minimize.center().y)); + assert!(asked.is_empty(), "left of Minimize: {asked:?}"); + assert!(h.query_by_label("Done").is_none(), "a click left of Minimize dismisses the dialog"); +} + +/// The details drawer covers the header, and the window's Close stays under it. +#[test] +fn the_details_drawer_keeps_the_caption_buttons_under_it() { + let (mut h, _) = harness_with_title_bar(events(), ViewMode::Grid, egui::Theme::Dark, true, 1.0, artcraft_launcher_ui_egui::TitleBar::Custom); + h.run_steps(8); + let close = h.get_by_label("Close").rect().center(); + h.get_by_label("PhotoCraft details").click(); + h.run_steps(10); + let asked = click_at(&mut h, close); + assert!(!asked.contains(&egui::ViewportCommand::Close), "the click reached the window's Close: {asked:?}"); +} + /// The enlarged picture's own Close sits under the custom title bar's Close. With no dialog open /// the caption buttons stay in the header, under the picture, so that click closes the picture /// and not the window. @@ -2089,10 +2149,11 @@ fn the_enlarged_pictures_close_closes_the_picture_not_the_window() { h.get_by_label("Enlarge picture").click(); h.run_steps(4); // The drawer's Close is lower down; the picture's is at the top right, under the title bar. - h.query_all_by_label("Close (Esc)").min_by(|a, b| a.rect().top().total_cmp(&b.rect().top())).unwrap().click(); - h.step(); - let closes = h.output().viewport_output.values().any(|v| v.commands.contains(&egui::ViewportCommand::Close)); - assert!(!closes, "the click reached the window's Close"); + let picture = h.query_all_by_label("Close (Esc)").map(|n| n.rect()).min_by(|a, b| a.top().total_cmp(&b.top())).unwrap(); + let spot = picture.intersect(h.get_by_label("Close").rect()); + assert!(spot.is_positive(), "the two buttons don't overlap: {picture:?}"); + let asked = click_at(&mut h, spot.center()); + assert!(!asked.contains(&egui::ViewportCommand::Close), "the click reached the window's Close: {asked:?}"); h.run_steps(4); assert_eq!(h.query_all_by_label("Close (Esc)").count(), 1, "the enlarged picture is still open"); }