diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 4c618c83f..bf43775cc 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -6616,7 +6616,7 @@ fn link_toggle(lang: &str, ui: &mut egui::Ui, d: &mut Dialog, key: &str, linked: /// A swatch menu with a colour chip per swatch (hidden swatches left out); returns the swatch /// picked. -fn swatch_menu(ui: &mut egui::Ui, doc: &designcraft_doc::Document, id: impl egui::AsIdSalt, current: &str, width: f32) -> Option { +pub(crate) fn swatch_menu(ui: &mut egui::Ui, doc: &designcraft_doc::Document, id: impl egui::AsIdSalt, current: &str, width: f32) -> Option { swatch_menu_with(ui, doc, id, current, width, None) } diff --git a/crates/ui-egui/src/effects_dialog.rs b/crates/ui-egui/src/effects_dialog.rs index a09b87498..650219bd2 100644 --- a/crates/ui-egui/src/effects_dialog.rs +++ b/crates/ui-egui/src/effects_dialog.rs @@ -337,15 +337,15 @@ fn swatch(app: &DesignApp, ui: &mut egui::Ui, d: &mut Dialog, path: &[&str]) { } v.as_str().unwrap_or("[Black]").to_string() }; - let names: Vec = app - .session - .active() - .map_or_else(Vec::new, |st| st.doc.swatches.iter().filter(|w| !w.hidden || w.name == cur).map(|w| w.name.clone()).collect()); - craft_ui::ComboBox::from_id_salt(("fx_swatch", path.join("."))).selected_text(&cur).width(150.0).show_ui(ui, |ui| { - for n in names { - if ui.selectable_label(n == cur, &n).clicked() { - set(d, path, json!(n)); - } + let Some(doc) = app.session.active().map(|st| &st.doc) else { return }; + // The colour itself beside its name, and a chip per swatch in the menu, as the swatch menus + // elsewhere: a list of bare names hid what the shadow was coloured with. + ui.horizontal(|ui| { + let (c, g) = crate::widgets::swatch_colors(doc, &cur, 1.0); + let (r, _) = ui.allocate_exact_size(egui::vec2(16.0, 16.0), egui::Sense::hover()); + crate::widgets::paint_chip(ui.painter(), r, c, g); + if let Some(n) = crate::dialogs::swatch_menu(ui, doc, ("fx_swatch", path.join(".")), &cur, 128.0) { + set(d, path, json!(n)); } }); } @@ -935,6 +935,44 @@ mod tests { assert_eq!(fx.outer_glow.mode, designcraft_color::BlendMode::Normal); } + #[test] + fn the_shadow_colour_shows_its_swatch_beside_the_name() { + let (mut app, _) = app_with_frame(); + app.run("swatch.create", json!({"name": "Shade", "color": "#12ab34"})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx, "en"); + let shade = crate::widgets::swatch_colors(&app.session.doc().unwrap().doc, "Shade", 1.0).0.unwrap(); + // Does the dialog, once faded in, paint a chip of the colour `c`? + let mut time = 0.0; + let mut painted = |app: &mut DesignApp, c: egui::Color32| { + let mut found = false; + for _ in 0..20 { + time += 0.1; + let input = egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 900.0))), + time: Some(time), + ..Default::default() + }; + let mut out = ctx.run_ui(input, |ui| crate::dialogs::show(app, ui.ctx())); + out.textures_delta.clear(); + fn walk(s: &egui::epaint::Shape, c: egui::Color32) -> bool { + match s { + egui::epaint::Shape::Rect(r) => r.fill == c, + egui::epaint::Shape::Vec(v) => v.iter().any(|s| walk(s, c)), + _ => false, + } + } + found = out.shapes.iter().any(|s| walk(&s.shape, c)); + } + found + }; + open(&mut app, "dropShadow"); + assert!(!painted(&mut app, shade), "not the shadow's colour yet"); + set(app.ui.dialog.as_mut().unwrap(), &["dropShadow", "color"], json!("Shade")); + assert!(painted(&mut app, shade), "the chosen swatch's colour is shown, not only its name"); + assert_eq!(params(app.ui.dialog.as_ref().unwrap())["effects"]["dropShadow"]["color"], "Shade"); + } + #[test] fn offsets_follow_distance_and_angle_as_in_indesign() { let (mut app, _) = app_with_frame(); diff --git a/crates/ui-egui/src/panels/properties/object_panels.rs b/crates/ui-egui/src/panels/properties/object_panels.rs index 194fecc2e..a2756621d 100644 --- a/crates/ui-egui/src/panels/properties/object_panels.rs +++ b/crates/ui-egui/src/panels/properties/object_panels.rs @@ -548,9 +548,11 @@ pub fn effects_panel(app: &mut DesignApp, ui: &mut egui::Ui) { // Distance and Size in the document's unit, as in the Effects dialog: a bare `7` means the // same in both. let u = units(app); + // Room for a measurement with its unit (`35.278 mm`). + const MEASURE_W: f32 = 66.0; egui::Grid::new("dsg").num_columns(4).spacing(vec2(6.0, 4.0)).show(ui, |ui| { caption(ui, crate::i18n::tr(&app.ui.language, "Distance")); - if let Some(v) = measure(ui, "dsd", Some(ds.distance), u, 56.0) { + if let Some(v) = measure(ui, "dsd", Some(ds.distance), u, MEASURE_W) { let _ = app.run("object.dropShadow", json!({"on": true, "distance": v})); } caption(ui, crate::i18n::tr(&app.ui.language, "Angle")); @@ -577,7 +579,7 @@ pub fn effects_panel(app: &mut DesignApp, ui: &mut egui::Ui) { let _ = app.run("object.dropShadow", json!({"on": true, "opacity": v / 100.0})); } caption(ui, crate::i18n::tr(&app.ui.language, "Size")); - if let Some(v) = measure(ui, "dss", Some(ds.size), u, 56.0) { + if let Some(v) = measure(ui, "dss", Some(ds.size), u, MEASURE_W) { let _ = app.run("object.dropShadow", json!({"on": true, "size": v})); } ui.end_row();