PhotoCraft: An open-source, photo editor written by scratch in pure Rust
fix(ui): make Preferences modal resizable on desktop (#5170)
Nigel Ihza Firdausy08def9648ddf
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 0530031f9..b71443ec1 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -104,6 +104,10 @@ fn older_dialog_above(ctx: &egui::Context, live: egui::LayerId, dialogs: &[Dialoctx.memory(|m| m.layer_ids().skip_while(|l| *l != live).skip(1).any(|l| others.contains(&l)))}+fn resizable_dialog(fields: &serde_json::Map<String, Value>) -> bool {+ fields.contains_key("__web") || crate::prefs_ui::is_preferences(fields)+}+fn show_modal<T>(modal: egui::Modal,ctx: &egui::Context,@@ -182,7 +186,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {// Photoshop doesn't dim the window behind dialogs: previews must be judged at true contrast.let web = fields.contains_key("__web");let web_popup_open = web && egui::Popup::is_any_open(ctx);- let modal = show_modal(modal, ctx, id, web, interactive, |ui| {+ let modal = show_modal(modal, ctx, id, resizable_dialog(&fields), interactive, |ui| {sizing = ui.is_sizing_pass();let available = ui.available_size();// A dialog of a few short fields (`__compact`, Fit Image) is narrower (#4673): the title@@ -998,3 +1002,21 @@ mod tests {}}}++#[cfg(test)]+mod preference_resize_tests {+ use super::*;++ #[test]+ fn preferences_can_resize_while_standard_native_dialogs_keep_their_layout() {+ let prefs = json!({"__prefsui": "prefs"});+ let shortcuts = json!({"__prefsui": "shortcuts"});+ let ordinary = json!({});+ let web = json!({"__web": true});++ assert!(resizable_dialog(prefs.as_object().unwrap()));+ assert!(!resizable_dialog(shortcuts.as_object().unwrap()));+ assert!(!resizable_dialog(ordinary.as_object().unwrap()));+ assert!(resizable_dialog(web.as_object().unwrap()));+ }+}