Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Fit Image: the dialog is as narrow as its few fields (fixes #4673) (#4692)

Marco Arnulfo139f4cf01d83
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 7633242d8..bb39e6d02 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -179,7 +179,12 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
let modal = show_modal(modal, ctx, id, web, interactive, |ui| {
sizing = ui.is_sizing_pass();
let available = ui.available_size();
- ui.set_min_width(380.0);
+ // A dialog of a few short fields (`__compact`, Fit Image) is narrower (#4673): the title
+ // rule and the button row fill the width they are given, so it needs its own maximum too.
+ let compact = d.fields.contains_key("__compact");
+ if !compact {
+ ui.set_min_width(380.0);
+ }
let wide = crate::prefs_ui::width(&d.fields, (ctx.content_rect().width() - 48.0).max(380.0));
if let Some(w) = wide {
ui.set_min_width(w.min(460.0));
@@ -198,6 +203,8 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
700.0
} else if d.kind == DialogKind::LayerStyle || d.fields.contains_key("__export") || crate::color_picker_ui::owns(&d.fields) {
600.0
+ } else if compact {
+ 260.0
} else {
440.0
}));
@@ -913,4 +920,23 @@ mod tests {
h.run_steps(2);
assert_eq!(radius(&h), Some(5.0), "a cancelled 9 is not remembered");
}
+
+ /// #4673: File › Automate › Fit Image holds two numbers and a check box, so its window is as
+ /// wide as that content and its buttons, not the 380-point floor of the larger dialogs.
+ #[test]
+ fn fit_image_is_as_narrow_as_its_content() {
+ use egui_kittest::kittest::Queryable;
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
+ let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state(|ui, app| show(app, ui.ctx()), app);
+ PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
+ let ctx = h.ctx.clone();
+ let d = crate::menus::invoke(h.state_mut(), &ctx, "file.automate.fitImage", json!({})).unwrap()["dialog"].as_u64().unwrap();
+ h.run_steps(4);
+ let window = h.ctx.memory(|m| m.area_rect(egui::Id::new(("dialog", d)))).expect("the Fit Image window");
+ assert!(window.width() < 300.0, "Fit Image is {} points wide", window.width());
+ for label in ["Fit Image", "Width", "Height", "OK", "Cancel"] {
+ assert!(window.contains_rect(h.get_by_label(label).rect()), "{label} inside the window");
+ }
+ }
}
diff --git a/crates/ui-egui/src/view_cmds.rs b/crates/ui-egui/src/view_cmds.rs
index eb510eb47..c50397c49 100644
--- a/crates/ui-egui/src/view_cmds.rs
+++ b/crates/ui-egui/src/view_cmds.rs
@@ -1222,7 +1222,7 @@ fn front(app: &mut PhotocraftApp, id: &str, params: &Value) -> Option<Result<Val
}
"file.automate.fitImage" => {
let (w, h, _) = doc?;
- dialog(app, json!({"width": w, "height": h, "dontEnlarge": false}), json!({}))
+ dialog(app, json!({"width": w, "height": h, "dontEnlarge": false, "__compact": true}), json!({}))
}
"file.automate.conditionalModeChange" => dialog(
app,