Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

LR-BEHAV-TITLEBAR: a press below the title bar released on it is not a click outside the dialog

Nathaniel Ledforde2ec77b76a2f
diff --git a/crates/ui-egui/src/dialogs/frame.rs b/crates/ui-egui/src/dialogs/frame.rs
index 9bca526ce..ea385f433 100644
--- a/crates/ui-egui/src/dialogs/frame.rs
+++ b/crates/ui-egui/src/dialogs/frame.rs
@@ -32,7 +32,7 @@ pub(super) fn clicked_backdrop(ctx: &egui::Context, window: egui::Rect, title_ba
}
let Some(release) = release else { return false };
let pressed_outside = ctx.data_mut(|d| d.remove_temp::<bool>(press_id)).unwrap_or(false);
- clicked && pressed_outside && !window.contains(release)
+ clicked && pressed_outside && !window.contains(release) && !title_bar.is_some_and(|b| b.contains(release))
}
/// Room kept free above and below a dialog (#781).
diff --git a/crates/ui-egui/src/tests/titlebar.rs b/crates/ui-egui/src/tests/titlebar.rs
index 7cec1c73f..d207fa81d 100644
--- a/crates/ui-egui/src/tests/titlebar.rs
+++ b/crates/ui-egui/src/tests/titlebar.rs
@@ -251,6 +251,21 @@ fn a_dialog_in_the_full_screen_photo_view_has_no_title_bar_handle() {
assert!(!handle, "no title bar handle over the photo");
}
+// Scenario: a press on the backdrop just below the bar, released on the bar, is not a click outside the dialog
+#[test]
+fn a_press_below_the_title_bar_released_on_it_keeps_the_dialog_open() {
+ let mut h = integrated();
+ h.app.ui.settings.close_dialogs_outside = true;
+ let mut h = with_export_dialog(h);
+ let spot = empty_spot(&h);
+ let bar = widget(&h, "region:titlebar");
+ let below = egui::pos2(spot.x, bar.bottom() + 1.0);
+ let on_bar = egui::pos2(spot.x, bar.bottom() - 1.0);
+ h.request("ui.drag", json!({"x": below.x, "y": below.y, "toX": on_bar.x, "toY": on_bar.y}), T);
+ play(&mut h);
+ assert!(h.app.ui.dialog.is_some(), "the release on the bar is not a click on the backdrop");
+}
+
// Scenario: a click on the undimmed bar is not a click outside the dialog
#[test]
fn a_click_on_the_title_bar_keeps_the_dialog_open() {