diff --git a/crates/ui-egui/src/panels/swatches/dnd.rs b/crates/ui-egui/src/panels/swatches/dnd.rs index 1d1227ba8a..05ff15e78d 100644 --- a/crates/ui-egui/src/panels/swatches/dnd.rs +++ b/crates/ui-egui/src/panels/swatches/dnd.rs @@ -62,8 +62,9 @@ pub(super) enum Drop { /// A paint from elsewhere (a Fill/Stroke proxy, a Recent Colors chip, a Color Guide color, the /// Gradient panel's thumbnail) dropped on row `target` (or between rows) becomes a swatch; with Alt held /// (`replace`) it replaces swatch `target` when that is of its kind and neither Registration - /// nor a tint swatch. - New { paint: Paint, target: Option, replace: bool }, + /// nor a tint swatch. With Cmd/Ctrl held (`spot`), a solid color other than Registration + /// becomes a spot color swatch. + New { paint: Paint, target: Option, replace: bool, spot: bool }, /// Art dragged off the canvas becomes a pattern swatch made of a copy of it (the art stays). Pattern { ids: Vec }, } @@ -71,15 +72,15 @@ pub(super) enum Drop { impl Drop { /// What releasing `d` before or `after` row `target` (`None`: at the end) does: move the rows /// it carries (with Alt held, `replace`, a swatch grabbed may replace `target`), make a swatch of - /// a paint dragged from elsewhere, or a pattern swatch of art dragged off the canvas (appearances: - /// nothing). - fn of(d: &PanelDrag, target: Option, after: bool, replace: bool) -> Option { + /// a paint dragged from elsewhere (a spot color with Cmd/Ctrl held, `spot`), or a pattern swatch + /// of art dragged off the canvas (appearances: nothing). + fn of(d: &PanelDrag, target: Option, after: bool, replace: bool, spot: bool) -> Option { match d { PanelDrag::Paint { rows: Some(r), .. } => { let with = (replace && !r.groups).then(|| r.grabbed.clone()); Some(Drop::Move { names: r.names.clone(), target, after, with }) } - PanelDrag::Paint { paint, .. } => Some(Drop::New { paint: paint.clone(), target, replace }), + PanelDrag::Paint { paint, .. } => Some(Drop::New { paint: paint.clone(), target, replace, spot }), PanelDrag::Art(ids) => Some(Drop::Pattern { ids: ids.iter().map(|id| id.0).collect() }), _ => None, } @@ -179,7 +180,7 @@ fn tile_drop(ui: &Ui, resp: &Response, e: &Entry, list: bool, ev: &mut TileEvent ui.painter().line_segment([pos2(x, r.top() - 1.0), pos2(x, r.bottom() + 1.0)], Stroke::new(2.0, t.accent)); } if resp.dnd_release_payload::().is_some() { - ev.drop = Drop::of(&d, Some(name.to_string()), after, crate::panels::alt_held(ui)); + ev.drop = Drop::of(&d, Some(name.to_string()), after, crate::panels::alt_held(ui), command_held(ui)); } } @@ -191,10 +192,15 @@ pub(super) fn zone_input(ui: &Ui, zone: &Response, ev: &mut TileEvents) { ui.painter().rect_stroke(zone.rect, 0.0, Stroke::new(1.5, Tokens::get(ui.ctx()).accent), StrokeKind::Inside); } if zone.dnd_release_payload::().is_some() { - ev.drop = Drop::of(&d, None, false, false); + ev.drop = Drop::of(&d, None, false, false, command_held(ui)); } } +/// Is Cmd (macOS) or Ctrl (Windows, Linux) held? +fn command_held(ui: &Ui) -> bool { + ui.input(|i| i.modifiers.command) +} + /// The colour group `name` is, or the one swatch `name` belongs to. pub(super) fn group_of(d: &Document, name: &str) -> Option { if d.swatch_groups.iter().any(|g| g.name == name) { @@ -252,7 +258,8 @@ fn replaces(d: &Document, with: &str, target: &str) -> bool { /// Run a drop on the panel: move the swatches, give the paint of a swatch Alt-dropped on another of /// its kind to that one, or make a swatch of the proxy's paint (a color dropped on a folder or a -/// grouped swatch joins that group). +/// grouped swatch joins that group; a color Cmd/Ctrl-dropped becomes a new spot color of the color +/// the drag shows, tints included). pub(super) fn apply_drop(app: &mut VectorcraftApp, drop: Drop) { let Some(d) = app.session.active().map(|st| &st.doc) else { return }; let (cmd, params) = match drop { @@ -264,17 +271,20 @@ pub(super) fn apply_drop(app: &mut VectorcraftApp, drop: Drop) { None => return, }, // Alt: an edited gradient (or colour) replaces the swatch it is dropped on. - Drop::New { paint, target: Some(t), replace: true } + Drop::New { paint, target: Some(t), replace: true, .. } if d.swatch(&t).is_some_and(|w| !w.is_reserved() && w.tint_of().is_none() && same_kind(&w.paint, &paint)) => { ("swatch.edit", json!({"name": t, "paint": crate::panels::swatch_paint_params(&paint)})) } - Drop::New { paint, target, .. } => { + Drop::New { paint, target, spot, .. } => { let mut p = crate::panels::swatch_paint_params(&paint); - if paint.color().is_some() - && let Some(g) = target.and_then(|t| group_of(d, &t)) - { - p["group"] = json!(g); + if paint.color().is_some() { + if let Some(g) = target.and_then(|t| group_of(d, &t)) { + p["group"] = json!(g); + } + if spot && !paint.is_registration() { + p["spot"] = json!(true); + } } ("swatch.new", p) } diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index c8e9755cd6..f745b83b1f 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -1039,6 +1039,160 @@ fn a_color_alt_dropped_on_registration_becomes_a_new_swatch() { assert_eq!(d.swatch(REGISTRATION).map(|w| w.paint.clone()), registration, "Registration is unchanged"); } +/// Release a drag of `paint` from elsewhere at `at` with `m` held (a layout frame at `time`, the +/// release at `time + 0.5`). +fn drop_paint_at(app: &mut VectorcraftApp, ctx: &egui::Context, at: Pos2, paint: Paint, m: Modifiers, time: f64) { + egui::DragAndDrop::set_payload(ctx, PanelDrag::paint(paint)); + let release = Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: m }; + frame_with(app, ctx, vec![Event::PointerMoved(at), release], m, time + 0.5, show); +} + +/// [`drop_paint_at`] on the tile of swatch `name`. +fn drop_paint_on(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, paint: Paint, m: Modifiers, time: f64) { + frame(app, ctx, vec![], time, show); + let at = tile_center(ctx, name); + drop_paint_at(app, ctx, at, paint, m, time); +} + +/// The newest ungrouped swatch. +fn newest_swatch(app: &VectorcraftApp) -> Swatch { + app.session.doc().unwrap().doc.swatches.last().cloned().expect("a swatch") +} + +/// How many swatches are spot colors. +fn spot_count(app: &VectorcraftApp) -> usize { + app.session.doc().unwrap().doc.swatches_iter().filter(|w| w.spot).count() +} + +/// A color Cmd/Ctrl-dropped on the panel becomes a global spot color swatch in the color's own +/// model, in the group it is dropped into, as one undo step that paints no art; without the +/// modifier it stays a process color. +#[test] +fn a_color_cmd_dropped_on_the_panel_becomes_a_spot_swatch() { + let mut app = app(); + let ctx = context(); + let (id, cmyk) = art_with_two_recent_colors(&mut app); + app.run("select.set", json!({"ids": [id.0]})).unwrap(); + frame(&mut app, &ctx, vec![], 0.0, show); + let art = fill_of(&app, id); + let undo = app.session.doc().unwrap().history.undo.len(); + // A proxy's RGB color onto a grouped swatch: a spot color in that group. + let rgb = Color::from_hex("#123456").unwrap(); + drop_paint_on(&mut app, &ctx, "Bright Red", Paint::solid(rgb), Modifiers::COMMAND, 1.0); + let d = &app.session.doc().unwrap().doc; + let made = names_of(&app, Some("Brights")).last().and_then(|n| d.swatch(n).cloned()).expect("a swatch"); + assert_eq!((made.paint, made.spot, made.global), (Paint::solid(rgb), true, true), "{}", app.ui.status); + assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 1, "one undo step"); + assert_eq!(fill_of(&app, id), art, "the drop paints no art"); + // A CMYK Recent Colors chip dragged with Cmd/Ctrl in an RGB document: a CMYK spot color. + frame(&mut app, &ctx, vec![], 2.0, show); + let chip = recent_chip(&mut app, &ctx, 1, 2.5, show, false); + drag_with(&mut app, &ctx, chip, tile_center(&ctx, "Red"), Modifiers::COMMAND, 3.0); + let newest = newest_swatch(&app); + assert_eq!((newest.paint, newest.spot), (Paint::solid(cmyk), true), "{}", app.ui.status); + // Without the modifier: a process color. + let spots = spot_count(&app); + drop_paint_on(&mut app, &ctx, "Red", Paint::solid(Color::from_hex("#654321").unwrap()), Modifiers::NONE, 4.0); + let newest = newest_swatch(&app); + assert_eq!((newest.spot, newest.global, spot_count(&app)), (false, false, spots)); + // An RGB color in a CMYK document stays RGB; the document stays CMYK. + app.run("file.documentColorMode", json!({"mode": "cmyk"})).unwrap(); + drop_paint_on(&mut app, &ctx, "Red", Paint::solid(rgb), Modifiers::COMMAND, 5.0); + let newest = newest_swatch(&app); + assert_eq!((newest.paint, newest.spot), (Paint::solid(rgb), true), "{}", app.ui.status); + assert_eq!(app.session.doc().unwrap().doc.color_mode, vectorcraft_doc::ColorMode::Cmyk); + // Undo takes the spot color off. + let count = app.session.doc().unwrap().doc.swatches_iter().count(); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(app.session.doc().unwrap().doc.swatches_iter().count(), count - 1); +} + +/// A color Cmd/Ctrl-dropped in the list's empty space becomes an ungrouped spot color swatch. +#[test] +fn a_color_cmd_dropped_on_empty_list_space_becomes_a_spot_swatch() { + let mut app = app(); + let ctx = context(); + // Leave Red the only ungrouped swatch besides None and Registration, so the row it ends has + // empty space after it (each colour group starts a new row). + let d = &app.session.doc().unwrap().doc; + let others: Vec = names_of(&app, None).into_iter().filter(|n| n != "Red" && d.swatch(n).is_some_and(|w| !w.is_reserved())).collect(); + app.run("swatch.delete", json!({"names": others})).unwrap(); + frame(&mut app, &ctx, vec![], 0.0, show); + frame(&mut app, &ctx, vec![], 0.5, show); + let red = ctx.read_response(egui::Id::unique(("swatch-tile", "Red"))).expect("Red's tile").rect; + let at = pos2(red.right() + 60.0, red.center().y); + let d = &app.session.doc().unwrap().doc; + let names = d.swatches_iter().map(|w| w.name.clone()).chain(d.swatch_groups.iter().map(|g| g.name.clone())).chain([REGISTRATION.to_string()]); + for n in names { + let hit = ctx.read_response(egui::Id::unique(("swatch-tile", n.as_str()))).is_some_and(|r| r.rect.expand(8.0).contains(at)); + assert!(!hit, "{at:?} is clear of the tile of {n}"); + } + let count = d.swatches_iter().count(); + let rgb = Color::from_hex("#123456").unwrap(); + drop_paint_at(&mut app, &ctx, at, Paint::solid(rgb), Modifiers::COMMAND, 1.0); + let newest = newest_swatch(&app); + assert_eq!((newest.paint, newest.spot, newest.global), (Paint::solid(rgb), true, true), "{}", app.ui.status); + assert_eq!(app.session.doc().unwrap().doc.swatches_iter().count(), count + 1); + assert!(egui::DragAndDrop::payload::(&ctx).is_none()); +} + +/// Cmd/Ctrl makes a spot color only of a solid color dragged from elsewhere: a gradient and +/// Registration make no spot color, and swatches dragged within the panel move. +#[test] +fn a_cmd_drop_of_other_paints_or_rows_makes_no_spot_color() { + let mut app = app(); + let ctx = context(); + let spots = spot_count(&app); + let count = app.session.doc().unwrap().doc.swatches_iter().count(); + let stops = + vec![vectorcraft_color::GradientStop::new(0.0, Color::from_hex("#ff0000").unwrap()), vectorcraft_color::GradientStop::new(1.0, Color::WHITE)]; + let grad = Paint::Gradient(Box::new(vectorcraft_color::GradientPaint::new(vectorcraft_color::Gradient::new(GradientKind::Radial, stops)))); + drop_paint_on(&mut app, &ctx, "Red", grad, Modifiers::COMMAND, 1.0); + assert!(matches!(newest_swatch(&app).paint, Paint::Gradient(_)), "a gradient swatch: {}", app.ui.status); + assert_eq!((app.session.doc().unwrap().doc.swatches_iter().count(), spot_count(&app)), (count + 1, spots)); + drop_paint_on(&mut app, &ctx, "Red", Paint::registration(), Modifiers::COMMAND, 2.0); + assert_eq!(spot_count(&app), spots, "Registration makes no spot color"); + // A swatch dragged with Cmd/Ctrl within the panel moves. + frame(&mut app, &ctx, vec![], 3.0, show); + frame(&mut app, &ctx, vec![], 3.5, show); + let count = app.session.doc().unwrap().doc.swatches_iter().count(); + drag_with(&mut app, &ctx, tile_center(&ctx, "Lime"), tile_center(&ctx, "Red") - vec2(4.0, 0.0), Modifiers::COMMAND, 4.0); + let n = names_of(&app, None); + assert_eq!(n[n.iter().position(|x| x == "Red").unwrap() - 1], "Lime", "{}", app.ui.status); + assert_eq!((app.session.doc().unwrap().doc.swatches_iter().count(), spot_count(&app)), (count, spots)); +} + +/// A tint of a global color Cmd/Ctrl-dropped becomes a new spot color of the tinted color, and its +/// base stays as it is. With Alt also held, a color dropped on a solid swatch replaces it; dropped on +/// a tint swatch, which only takes a new name, it becomes a spot color. +#[test] +fn cmd_drops_of_tints_and_with_alt_follow_the_replacement_rule() { + let mut app = app(); + let ctx = context(); + app.run("swatch.edit", json!({"name": "Orange", "global": true})).unwrap(); + app.run("swatch.new", json!({"swatch": "Orange", "tint": 40})).unwrap(); + let orange = app.session.doc().unwrap().doc.swatch("Orange").cloned(); + let tint = app.session.doc().unwrap().doc.tint_paint("Orange", 0.4).expect("a tint of Orange"); + let shown = tint.color().expect("a color"); + drop_paint_on(&mut app, &ctx, "Red", tint, Modifiers::COMMAND, 1.0); + let newest = newest_swatch(&app); + assert_eq!((newest.paint, newest.spot, newest.global), (Paint::solid(shown), true, true), "{}", app.ui.status); + assert_eq!(app.session.doc().unwrap().doc.swatch("Orange").cloned(), orange, "Orange is unchanged"); + // Cmd/Ctrl and Alt on a solid swatch: it takes the color, and no swatch is added. + let count = app.session.doc().unwrap().doc.swatches_iter().count(); + let blue = Color::from_hex("#2040c0").unwrap(); + drop_paint_on(&mut app, &ctx, "Red", Paint::solid(blue), Modifiers::COMMAND | Modifiers::ALT, 2.0); + let red = app.session.doc().unwrap().doc.swatch("Red").cloned().expect("Red"); + assert_eq!((red.paint.color(), red.spot), (Some(blue), false), "{}", app.ui.status); + assert_eq!(app.session.doc().unwrap().doc.swatches_iter().count(), count); + // Cmd/Ctrl and Alt on a tint swatch: a new spot color, the tint swatch unchanged. + let green = Color::from_hex("#20a040").unwrap(); + drop_paint_on(&mut app, &ctx, "Orange 40%", Paint::solid(green), Modifiers::COMMAND | Modifiers::ALT, 3.0); + let newest = newest_swatch(&app); + assert_eq!((newest.paint, newest.spot), (Paint::solid(green), true), "{}", app.ui.status); + assert!(app.session.doc().unwrap().doc.swatch("Orange 40%").is_some_and(|w| w.tint_of().is_some())); +} + /// A Recent Colors chip of the Color panel dragged onto the Swatches panel becomes a swatch; a click /// on it still paints the selected art. #[test] diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index e667daf73e..3f4c7b0dcb 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1695,6 +1695,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Unchecking Show Recent Colors in the Color panel's menu hides its Recent Colors row, and checking it shows the row again ([Select colors using the Color panel](https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/select-colors-using-the-color-panel.html)). In VectorCraft the item is checked by default and kept between sessions, applied colors still join the list while the row is hidden, Hide Options hides the row either way, and the Swatches panel keeps its row (`ui.colorPanel {recentColors}`). Tests: `show_recent_colors_hides_and_shows_the_row` in `crates/ui-egui/src/panels/color/tests.rs`. The Swatches panel's menu has its own Show Recent Colors item: unchecking it hides the panel's Recent Colors row and checking it shows the row again ([Color Enhancements in Illustrator](https://community.adobe.com/announcements-651/color-enhancements-in-illustrator-816797) puts recent colors in the Color and Swatches panels; [Select colors using the Color panel](https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/select-colors-using-the-color-panel.html) hides them with Show Recent Colors in the panel menu; a [community thread](https://community.adobe.com/questions-652/swatches-disappear-in-swatches-panel-when-switching-between-documents-in-29-7-1-on-macos-816823) turns it off from the Swatches panel). In VectorCraft it is checked by default, kept between sessions apart from the Color panel's, and applied colors still join the list while the row is hidden (#6617). Tests: `show_recent_colors_hides_and_shows_the_swatches_row` in `crates/ui-egui/src/panels/swatches/tests.rs`. A Recent Colors chip in the Color or Swatches panel drags into the Swatches panel's list to become a swatch of its color, in its color model, as one undo step ([Select colors using the Color panel](https://helpx.adobe.com/illustrator/desktop/manage-colors/select-and-adjust-colors/select-colors-using-the-color-panel.html)). In VectorCraft a chip dropped on a color group or one of its swatches joins that group, anywhere else in the list it joins the ungrouped swatches at the end, a color that is already a swatch is added again under another name, and dragging a chip does not paint the selected art (`swatch.new`). Tests: `a_recent_color_dragged_onto_the_list_becomes_a_swatch` and `a_recent_color_dragged_from_the_color_panel_becomes_a_swatch` in `crates/ui-egui/src/panels/swatches/tests.rs`. + A color dragged into the Swatches panel with Cmd (macOS) or Ctrl (Windows) held becomes a spot color swatch ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/create-spot-color-swatches.html) gives this drag from the Color panel as one way to make a spot color). VectorCraft's own rules: Ctrl works on Linux too, and the modifier is read on release; the Fill and Stroke squares, Recent Colors chips and Color Guide colors drag the same way; the new swatch is global, keeps the dragged color's model, joins the color group it is dropped on (anywhere else, the ungrouped swatches at the end), takes a name of its own and is one undo step that paints no art; a tint dragged this way becomes a new spot color of the tinted color, and its base swatch stays as it is; with Alt also held, a color dropped on a solid swatch replaces it, and one dropped on Registration or a tint swatch becomes a spot color; gradients, patterns, Registration and swatches dragged within the panel are not made spot colors (`swatch.new {spot: true}`). Tests: `a_color_cmd_dropped_on_the_panel_becomes_a_spot_swatch`, `a_color_cmd_dropped_on_empty_list_space_becomes_a_spot_swatch`, `a_cmd_drop_of_other_paints_or_rows_makes_no_spot_color` and `cmd_drops_of_tints_and_with_alt_follow_the_replacement_rule` in `crates/ui-egui/src/panels/swatches/tests.rs`. A Cmd/Ctrl-click on the Color panel's spectrum applies Complement and a Cmd/Ctrl+Shift-click applies Invert to the active Fill or Stroke (`paint.complement`, `paint.invert`); with Alt also held, the click recolors the inactive one, as the reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) list them. The Color panel spectrum grows into the vertical space of a resized panel, with Show Options or Hide Options (#8005); compact auto-fit flyouts and embedded mixers retain their previous height. Regression: panels::color::tests::the_spectrum_grows_with_the_color_panel. Scores and estimates unchanged. A double-click right of an RGB field switches the Color panel's R, G and B between percent and 0 to 255 ([Default keyboard shortcuts](https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html), Color panel). In VectorCraft the color does not change, Web Safe RGB and the hex field stay in 0 to 255, and the panel keeps the choice between sessions (`ui.colorPanel {rgbPercent}`); the color mixer of the Fill and Stroke chips and the gradient stop dialog follow the same setting. Toggle RGB Percent (`ui.colorRgbPercent`) in the command palette and Keyboard Shortcuts switches the units from the keyboard. Tests: `rgb_percent_switches_the_rgb_fields_between_percent_and_0_to_255`, `rgb_percent_does_not_switch_while_the_rows_are_disabled`, `rgb_percent_comes_back_after_a_restart` and `toggle_rgb_percent_switches_the_units_from_the_keyboard` in `crates/ui-egui/src/panels/color/tests.rs`.