Skip to content

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

fix(ui): fit Curves dialog width to its graph (#5160)

Ivan · VanTandf10129f6c21
diff --git a/crates/ui-egui/src/adjust_dialog.rs b/crates/ui-egui/src/adjust_dialog.rs
index 5f4334850..eb8f89a68 100644
--- a/crates/ui-egui/src/adjust_dialog.rs
+++ b/crates/ui-egui/src/adjust_dialog.rs
@@ -451,6 +451,30 @@ mod tests {
}
}
+ /// #5113: the dialog should fit its curve graph instead of reserving a blank right column.
+ #[test]
+ fn curves_dialog_fits_its_graph_and_controls() {
+ for language in ["en", "ru"] {
+ let _language = crate::i18n::language_scope(crate::i18n::Lang::from_code(language).unwrap());
+ for theme in crate::theme::ThemeKind::ALL {
+ for size in [egui::vec2(1280.0, 900.0), egui::vec2(900.0, 720.0)] {
+ let mut h = Harness::builder().with_size(size).build_ui_state(|ui, app| crate::dialogs::show(app, ui.ctx()), app_with_image());
+ PhotocraftApp::setup_context(&h.ctx, theme);
+ let id = open(h.state_mut(), "image.adjustments.curves").unwrap();
+ h.run_steps(4);
+ let window = h.ctx.memory(|m| m.area_rect(egui::Id::new(("dialog", id)))).unwrap();
+ let graph = h.ctx.data(|d| d.get_temp::<egui::Rect>(dialog_mem("curves").with("curves-graph"))).unwrap();
+ assert!(window.right() - graph.right() < 40.0, "blank right column: window {window:?}, graph {graph:?}");
+ assert!(graph.width() > 270.0, "keep the graph usable: {graph:?}");
+ assert!(window.contains_rect(graph));
+ for label in ["Channel:", "Input:", "Output:", "Preview", "OK", "Cancel"] {
+ assert!(window.contains_rect(h.get_by_label(crate::i18n::t(label)).rect()), "{label} inside the window");
+ }
+ }
+ }
+ }
+ }
+
#[test]
fn cancel_leaves_the_document_untouched() {
let mut harness =
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index b71443ec1..2930889ba 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -192,8 +192,10 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
// 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");
+ // The curve editor caps its graph allocation at 300 points (#5113).
+ let curves = fields.get("__adjust").and_then(Value::as_str) == Some("curves");
if !compact {
- ui.set_min_width(380.0);
+ ui.set_min_width(if curves { 300.0 } else { 380.0 });
}
let wide = crate::prefs_ui::width(&d.fields, (ctx.content_rect().width() - 48.0).max(380.0));
if let Some(w) = wide {
@@ -215,6 +217,8 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
600.0
} else if compact {
260.0
+ } else if curves {
+ 300.0
} else {
440.0
}));