diff --git a/crates/ui-egui/src/panels/color_guide.rs b/crates/ui-egui/src/panels/color_guide.rs index abea906633..bbc1d3db86 100644 --- a/crates/ui-egui/src/panels/color_guide.rs +++ b/crates/ui-egui/src/panels/color_guide.rs @@ -8,7 +8,9 @@ //! without changing the base, and selects it; Shift- or Cmd/Ctrl-click adds //! cells to the selection that Save Colors as Swatches saves as swatches and Save Color Group to //! Swatches saves as one group (without a selection, the group holds the harmony colors). The -//! selection lasts until the guide changes. Limit to Library (the library button, +//! selection lasts until the guide changes. A harmony color or a cell dragged with the primary button +//! carries its color alone, as shown, without applying it or changing the selection; the Swatches +//! panel makes a swatch of it. Limit to Library (the library button, //! `ui.colorGuideLimit`) snaps every colour to a swatch library or the document's swatches; Edit or //! Apply Colors opens Recolor Artwork with the harmony colours, limited the same way. @@ -21,7 +23,7 @@ use vectorcraft_engine::cmd::swatchlib; use super::swatches::{self, colour_libraries, limit_key, limit_name}; use super::{active_paint, apply_click, c32, color_json, library_panel, pstate, set_pstate}; use crate::VectorcraftApp; -use crate::widgets::{self, menu_item}; +use crate::widgets::{self, PanelDrag, menu_item}; /// The base colour before one is set: an orange. const DEFAULT_BASE: Color = Color::Rgb { r: 230.0 / 255.0, g: 120.0 / 255.0, b: 40.0 / 255.0 }; @@ -217,7 +219,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let w = strip.width() / g.colors.len() as f32; for (i, c) in g.colors.iter().enumerate() { let r = Rect::from_min_size(strip.min + vec2(i as f32 * w, 0.0), vec2(w, strip.height())); - let resp = ui.interact(r, ui.scope_id().with(("cg-h", i)), Sense::click()); + let resp = ui.interact(r, ui.scope_id().with(("cg-h", i)), Sense::click_and_drag()); + widgets::drag_source(ui, &resp, || PanelDrag::paint(Paint::solid(*c))); ui.painter().rect_filled(r, 0.0, c32(c)); if resp.on_hover_text(c.to_hex()).clicked() { chosen = Some(*c); @@ -237,7 +240,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let (rr, _) = ui.allocate_exact_size(vec2(ui.available_width(), 18.0), Sense::hover()); for (ci, v) in row.iter().enumerate() { let r = Rect::from_min_size(rr.min + vec2(x(ci), 0.0), vec2(x(ci + 1) - x(ci) - gap, 17.0)); - let resp = ui.interact(r, ui.scope_id().with(("cg-v", ri, ci)), Sense::click()); + let resp = ui.interact(r, ui.scope_id().with(("cg-v", ri, ci)), Sense::click_and_drag()); + widgets::drag_source(ui, &resp, || PanelDrag::paint(Paint::solid(*v))); ui.painter().rect_filled(r, 0.0, c32(v)); if sel.contains(&(ri, ci)) { ui.painter().rect_stroke(r.shrink(1.0), 0.0, egui::Stroke::new(1.0, egui::Color32::WHITE), egui::StrokeKind::Inside); @@ -433,6 +437,119 @@ mod tests { assert_eq!(base_color(&app).to_hex(), variation, "the base chip adopts the current color"); } + /// One frame at `time` with `events` of the Color Guide panel, followed by the Swatches panel when + /// `swatches` is set; → the center of the guide widget `id` as laid out in that frame. + fn guide_frame( + app: &mut VectorcraftApp, + ctx: &egui::Context, + events: Vec, + time: f64, + swatches: bool, + id: impl std::hash::Hash + std::fmt::Debug, + ) -> egui::Pos2 { + let screen_rect = Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(280.0, 900.0))); + let input = egui::RawInput { events, time: Some(time), screen_rect, ..Default::default() }; + let mut at = None; + let mut out = ctx.run_ui(input, |ui| { + show(app, ui); + at = ctx.read_response(ui.scope_id().with(&id)).map(|r| r.rect.center()); + if swatches { + super::swatches::show(app, ui); + } + }); + out.textures_delta.clear(); + at.expect("the guide widget is drawn") + } + + /// Press on the guide widget `id`, move far enough to start a drag, move to `to` (the widget + /// itself when None) and release there, a frame per step from `time`. → the drag the panel + /// started, read before the release. + fn drag_from( + app: &mut VectorcraftApp, + ctx: &egui::Context, + id: (&str, usize, usize), + to: Option, + time: f64, + swatches: bool, + ) -> Option { + let from = match id.0 { + "cg-h" => guide_frame(app, ctx, vec![], time, swatches, ("cg-h", id.1)), + _ => guide_frame(app, ctx, vec![], time, swatches, ("cg-v", id.1, id.2)), + }; + let to = to.unwrap_or(from); + let button = + |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + let step = |app: &mut VectorcraftApp, events, t| { + guide_frame(app, ctx, events, t, swatches, ("cg-h", 0usize)); + }; + step(app, vec![egui::Event::PointerMoved(from), button(from, true)], time + 0.1); + step(app, vec![egui::Event::PointerMoved(from + vec2(8.0, 3.0))], time + 0.2); + let held = egui::DragAndDrop::payload::(ctx).map(|d| (*d).clone()); + step(app, vec![egui::Event::PointerMoved(to)], time + 0.3); + step(app, vec![egui::Event::PointerMoved(to), button(to, false)], time + 0.4); + held + } + + /// A harmony color or a variation dragged from the guide carries that color alone, as a solid + /// paint; the drag applies nothing to the selected art and leaves the base and the selected + /// cells as they were. + #[test] + fn a_dragged_guide_color_carries_its_color_and_applies_nothing() { + let mut app = app(); + app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap(); + app.run("paint.setFill", json!({"color": "#3366cc"})).unwrap(); + let ctx = egui::Context::default(); + frame(&mut app, &ctx); + let g = guide(&app, &ctx); + set_pstate(&ctx, "cg-sel", vec![(0usize, 1usize), (1, 2)]); + let fill = |app: &VectorcraftApp| crate::panels::current_paints(app).0.color().map(|c| c.to_hex()); + let held = drag_from(&mut app, &ctx, ("cg-h", 1, 0), None, 1.0, false); + assert_eq!(held, Some(PanelDrag::paint(Paint::solid(g.colors[1]))), "the harmony color"); + let held = drag_from(&mut app, &ctx, ("cg-v", 0, 4), None, 2.0, false); + assert_eq!(held, Some(PanelDrag::paint(Paint::solid(g.grid[0][4]))), "the grabbed cell only, not the selected ones"); + assert_eq!(held.and_then(|d| d.color()), Some(g.grid[0][4])); + assert!(egui::DragAndDrop::payload::(&ctx).is_none(), "the release ends the drag"); + assert_eq!(fill(&app).as_deref(), Some("#3366cc"), "the drag paints no art"); + assert_eq!(base_color(&app).to_hex(), "#3366cc", "the base stays"); + assert_eq!(selected(&ctx), [(0, 1), (1, 2)], "the selected cells stay"); + } + + /// A variation of a guide limited to a library, dragged onto the Swatches panel, becomes one + /// swatch of the color the cell shows, in its own model in a CMYK document, as one undo step; the + /// same color dragged again is added under another name. + #[test] + fn a_guide_color_dragged_onto_the_swatches_panel_becomes_a_swatch() { + let mut app = app(); + app.run("file.documentColorMode", json!({"mode": "cmyk"})).unwrap(); + app.run("paint.setFill", json!({"color": "#c04020", "keepModel": true})).unwrap(); + app.run("ui.colorGuideLimit", json!({"library": "web-safe-216"})).unwrap(); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + guide_frame(&mut app, &ctx, vec![], 0.0, true, ("cg-h", 0usize)); + let g = guide(&app, &ctx); + let cell = g.grid[0][1]; + assert!(matches!(cell, Color::Rgb { .. }), "{cell:?}"); + assert!(library_hexes(&app, "web-safe-216").contains(&cell.to_hex()), "the cell shows a library color"); + let tile = |ctx: &egui::Context| ctx.read_response(egui::Id::unique(("swatch-tile", "Red"))).expect("the Red swatch is drawn").rect.center(); + let (count, undo) = { + let st = app.session.doc().unwrap(); + (st.doc.swatches_iter().count(), st.history.undo.len()) + }; + drag_from(&mut app, &ctx, ("cg-v", 0, 1), Some(tile(&ctx)), 1.0, true); + let st = app.session.doc().unwrap(); + assert_eq!(st.doc.swatches_iter().count(), count + 1, "{}", app.ui.status); + assert_eq!(st.history.undo.len(), undo + 1, "one undo step"); + let first = st.doc.swatches.last().cloned().expect("a swatch"); + assert_eq!(first.paint, Paint::solid(cell), "the shown color, still RGB"); + assert!(!first.global, "a plain process color"); + drag_from(&mut app, &ctx, ("cg-v", 0, 1), Some(tile(&ctx)), 2.0, true); + let newest = app.session.doc().unwrap().doc.swatches.last().cloned().expect("a swatch"); + assert_eq!(newest.paint, Paint::solid(cell)); + assert_ne!(newest.name, first.name, "another name"); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(app.session.doc().unwrap().doc.swatches_iter().count(), count + 1, "Undo takes the second one off"); + } + #[test] fn save_colors_as_swatches_saves_each_selected_cell() { let mut app = app(); diff --git a/crates/ui-egui/src/panels/swatches/dnd.rs b/crates/ui-egui/src/panels/swatches/dnd.rs index 2adff72887..2c36dabcb3 100644 --- a/crates/ui-egui/src/panels/swatches/dnd.rs +++ b/crates/ui-egui/src/panels/swatches/dnd.rs @@ -59,8 +59,8 @@ pub(super) enum Drop { /// `target` of its kind (neither None, Registration nor a tint swatch; see [`replaces`]), it /// gives that swatch its paint instead of moving. Move { names: Vec, target: Option, after: bool, with: Option }, - /// A paint from elsewhere (a Fill/Stroke proxy, a Recent Colors chip, the Gradient panel's - /// thumbnail) dropped on row `target` (or between rows) becomes a swatch; with Alt held + /// 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 }, diff --git a/crates/ui-egui/src/widgets/drag.rs b/crates/ui-egui/src/widgets/drag.rs index 1a9c280f81..a3df5a4098 100644 --- a/crates/ui-egui/src/widgets/drag.rs +++ b/crates/ui-egui/src/widgets/drag.rs @@ -4,8 +4,8 @@ use super::{Paint, Rect, Response, Stroke, StrokeKind, Tokens, Ui, Vec2}; /// handler for all of them (`canvas::panel_drop`); a chip of a dragged paint follows the pointer. #[derive(Clone, Debug, PartialEq)] pub enum PanelDrag { - /// A paint: Swatches panel tiles, a Fill/Stroke proxy, a Recent Colors chip or the Gradient - /// panel's thumbnail. Art it is dropped on takes `params` (`{swatch}`, `{color}`, `{gradient}`…; + /// A paint: Swatches panel tiles, a Fill/Stroke proxy, a Recent Colors chip, a Color Guide + /// color or the Gradient panel's thumbnail. Art it is dropped on takes `params` (`{swatch}`, `{color}`, `{gradient}`…; /// null for a colour group, which paints nothing) through the active proxy's /// `paint.setFill`/`paint.setStroke`; the Gradient panel's ramp takes its colour as a stop; the /// Swatches panel moves `rows`, or makes a swatch of a paint dragged from elsewhere. `library`: @@ -69,8 +69,8 @@ pub struct SwatchRows { } impl PanelDrag { - /// `paint` dragged from a Fill/Stroke proxy, a Recent Colors chip or the Gradient panel's - /// thumbnail. A gradient carries no placement: it fits the art it lands on (freeform points are + /// `paint` dragged from a Fill/Stroke proxy, a Recent Colors chip, a Color Guide color or the + /// Gradient panel's thumbnail. A gradient carries no placement: it fits the art it lands on (freeform points are /// placed afresh there, coloured like the dragged ones). pub fn paint(mut paint: Paint) -> Self { if let Paint::Gradient(g) = &mut paint { diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index c66ced12c3..c623d375a0 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1691,6 +1691,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Generic CMYK (SWOP-like):** each ink's 40% and 50% tints gain as [CGATS TR 001](https://registry.color.org/cmyk-registry/cgats_tr_001) gives for SWOP printing, and separations stay within SWOP's [300% total ink limit](https://en.wikipedia.org/wiki/Specifications_for_Web_Offset_Publications). The paper, solid and overprint colors, the black-generation curve and the black point are VectorCraft's own values: RGB black separates to 90% black under neutral cyan, magenta and yellow that fill the ink limit (C75 M68 Y67 K90). - **Swatches made from a shown color in a CMYK document:** the Color panel menu's Create New Swatch, an Alt-click on the Swatches panel's New Swatch button, the New Swatch dialog for a gradient, a Fill or Stroke proxy or the Gradient panel's thumbnail dropped on the Swatches panel (or Alt-dropped on a swatch of its kind), and the Gradient panel's Add to Swatches and Save to Swatches keep each color's model, as the Color Guide's and Color Themes' saved colors do: an RGB object's color gives an RGB swatch, and a gradient's RGB stops stay RGB. - **Color Guide color groups:** with variation cells selected, the Color Guide's Save Color Group to Swatches button saves those cells as one swatch group, and with none selected it saves the harmony colors, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes saving several selected variations together (printed page 135). The group takes the cells in grid order (row by row, left to right, each cell once), is named after the harmony rule and is one undo step; these are VectorCraft's own rules. A selection lasts until the base, the Color Guide Options, the variation mode, the harmony rule, the library limit or the colors the grid shows (for example after a new swatch while the guide is limited to the document's swatches) change. + - **Color Guide colors dragged to Swatches:** a variation cell dragged from the Color Guide onto the Swatches panel's list becomes a swatch of that color, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes for saving variations as individual swatches (printed page 135). In VectorCraft a harmony strip color drags the same way, a drag carries only the grabbed color (the selected cells stay selected and the selection is not saved), it carries the color the cell shows (snapped to the Limit to Library colors), keeps the color's model and does not paint the selected art; the swatch follows the panel's rules for a dropped color (`swatch.new`, one undo step, a color that is already a swatch is added again under another name, a drop on a color group joins it). These are VectorCraft's own rules. Tests: `a_dragged_guide_color_carries_its_color_and_applies_nothing` and `a_guide_color_dragged_onto_the_swatches_panel_becomes_a_swatch` in `crates/ui-egui/src/panels/color_guide.rs`. - **Sample Color from Screen:** an eyedropper button in the Color Picker and `ui.sampleScreenColor` (which can be given a key in Keyboard Shortcuts) pick a color anywhere on the screen with the system's sampler: `NSColorSampler` on macOS, the XDG desktop portal's [PickColor](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Screenshot.html) on Linux, and the EyeDropper API in browsers that have it. The color becomes the fill or the stroke as one undo step, or the Color Picker's color, converted from display sRGB into the working RGB space. On Linux, a session without a portal that has PickColor, a portal that does not return from the call within 25 seconds (VectorCraft's own limit) or leaves the bus before it answers, and a portal that ends the request another way each show a status message and end the wait. Windows, the BSDs and other browsers have no sampler yet; the button is gray there. - **Stroke visibility (#1253):** adding paint to a previously unpainted zero-width stroke restores the existing 1 pt default (`PaintDefaults::default`, `Appearance::set_stroke`), for the selected appearance item, the new-art defaults and Swap Fill/Stroke. Positive widths are kept; recoloring a painted zero-width stroke keeps its explicit zero. A real Eyedropper-to-new-shape sequence reproduces the zero-width inheritance. Five engine regressions cover creation, defaults, targeted items, preserved widths and one-step Undo/Redo (`crates/engine/tests/it/stroke_visibility.rs`). - **Gradients:** lossless, validated gradient params; gradients follow rotate, reflect, shear, non-uniform scale and distortions; the Gradient tool edits the fill or stroke of the active proxy, type included; an interactive on-canvas annotator (move, length/angle, rotate, add/move/delete/duplicate stops, midpoints, a stop popover, Delete and arrow keys). The Gradient panel has the Fill/Stroke proxy, a gradient-swatch dropdown with Save to Swatches, midpoint locations, Alt-drag to copy or swap stops, swatch drops on the ramp and a stop eyedropper; copied appearances and graphic styles place gradients on each target's own bounds; gradient handles, both ends of a vector drawn on the art and the start of a clicked one snap as other drawn points do (path segments, construction guides and View › Snap to Glyph's guides included) and honour Constrain Angle. Gradient stops stay linked to global and spot swatches. Freeform gradients (points and lines) are edited on the canvas; radial gradients have an extent ellipse, an aspect handle and an off-centre focal point (SVG `fx`/`fy`, PDF two-point radials). A stroke's gradient runs within, along or across it. Object ▸ Expand turns gradients into N objects or a gradient mesh.