diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index f44b1a166b..01c621bebf 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -1296,35 +1296,43 @@ fn body(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> bool { let room = ui.available_width(); // Without the room for both side by side (a narrow window), the list goes under the tabs. let beside = room >= SPEC.min_width + STORAGE_GAP + STORAGE_W; + // The Color Picker that a double-click on a new color or Pick from Swatches asks for opens over + // the dialog after the list is drawn, so the window keeps its size while the picker is open. + let mut picker = None; if !d.bool(GROUP_STORAGE) || !beside { ui.vertical(|ui| { ui.set_width(room.min(MAIN_W)); - main(app, ui, d); - if d.kind == KIND && d.bool(GROUP_STORAGE) { + picker = main(app, ui, d); + if d.bool(GROUP_STORAGE) { ui.add_space(6.0); group_storage(app, ui, d, 3.0 * GROUP_ROW_H); } }); - return false; - } - ui.horizontal_top(|ui| { - ui.vertical(|ui| { - ui.set_width((room - STORAGE_GAP - STORAGE_W).clamp(0.0, MAIN_W)); - main(app, ui, d); - }); - // A double-click on a new color turns the dialog into the Color Picker. - if d.kind == KIND { + } else { + ui.horizontal_top(|ui| { + ui.vertical(|ui| { + ui.set_width((room - STORAGE_GAP - STORAGE_W).clamp(0.0, MAIN_W)); + picker = main(app, ui, d); + }); ui.add_space(STORAGE_GAP); ui.vertical(|ui| { ui.set_width(STORAGE_W); group_storage(app, ui, d, TAB_H - 30.0); }); - } - }); + }); + } + if let Some((i, swatches)) = picker + && let Some(row) = rows(d).get(i) + { + let c = to_color(row).or_else(|| from_colors(row).first().copied()).unwrap_or_default(); + *d = super::color_picker::over_recolor(d, c, i, swatches); + } false } -fn main(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) { +/// The tabs and the controls under them. Returns the row whose new color a double-click or Pick +/// from Swatches asked to pick in the Color Picker, with `true` for Pick from Swatches. +fn main(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) -> Option<(usize, bool)> { sync(app, d); sync_theme(app, d); sync_weights(app, d); @@ -1403,12 +1411,7 @@ fn main(app: &mut VectorcraftApp, ui: &mut Ui, d: &mut Dialog) { None => form::preview(app, ui, d, "Recolor Artwork", CMD, apply_params(d)), } } - if let Some((i, swatches)) = pick - && let Some(row) = rows(d).get(i) - { - let c = to_color(row).or_else(|| from_colors(row).first().copied()).unwrap_or_default(); - *d = super::color_picker::over_recolor(d, c, i, swatches); - } + pick } /// `d` with row `i`'s new colour set to `c` (the Color Picker's OK), snapped to Limit to Library. diff --git a/crates/ui-egui/src/tests/recolor.rs b/crates/ui-egui/src/tests/recolor.rs index f4d2d6e85a..0d5bacd77c 100644 --- a/crates/ui-egui/src/tests/recolor.rs +++ b/crates/ui-egui/src/tests/recolor.rs @@ -1585,3 +1585,29 @@ fn row_context_menu_pick_from_swatches_and_limit_to_library() { assert_eq!(colors(h.state_mut()), 2, "Recolor Cancel restores the original artwork"); } } + +/// With the Color Groups list shown, the Color Picker opened from a row and closed with Cancel +/// leaves Recolor Artwork the size it was and where it was, in every frame. +#[test] +fn the_color_picker_leaves_the_dialog_in_place() { + use egui::accesskit::Role; + + let mut app = app(); + art(&mut app, &["#ff0000", "#0000ff"]); + let mut h = assign_harness(app, json!({})); + assert_eq!(field(h.state(), "groupStorage"), json!(true), "the list is shown"); + let window = egui::Id::unique(("dialog", "recolor")); + let rect = |h: &egui_kittest::Harness<'_, VectorcraftApp>| h.ctx.memory(|m| m.area_rect(window)); + let before = rect(&h).expect("dialog drawn"); + row_context_menu(&mut h, 1); + h.get_by_label(" Pick from Swatches").click(); + h.run_steps(3); + assert_eq!(h.state().ui.dialog.as_ref().map(|d| d.kind.as_str()), Some("colorPicker")); + assert_eq!(rect(&h), Some(before), "the dialog keeps its size while the picker is open"); + h.get_by_role_and_label(Role::Button, "Cancel").click(); + for step in 0..4 { + h.run_steps(1); + assert_eq!(rect(&h), Some(before), "frame {step} after Cancel"); + } + assert_eq!(h.state().ui.dialog.as_ref().map(|d| d.kind.as_str()), Some("recolor")); +}