mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
Merge pull request #8357 from dotCooCoo/feat/swatches-cmd-drop-spot
Swatches: a color dropped with Cmd/Ctrl on the panel makes a spot swatch
This commit is contained in:
@@ -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<String>, 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<String>, 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<u64> },
|
||||
}
|
||||
@@ -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<String>, after: bool, replace: bool) -> Option<Self> {
|
||||
/// 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<String>, after: bool, replace: bool, spot: bool) -> Option<Self> {
|
||||
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,
|
||||
}
|
||||
@@ -182,7 +183,8 @@ 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::<PanelDrag>().is_some() {
|
||||
ev.drop = Drop::of(&d, Some(name.to_string()), after, crate::panels::alt_held(ui));
|
||||
let m = release_modifiers(ui);
|
||||
ev.drop = Drop::of(&d, Some(name.to_string()), after, m.alt, m.command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,10 +196,25 @@ 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::<PanelDrag>().is_some() {
|
||||
ev.drop = Drop::of(&d, None, false, false);
|
||||
ev.drop = Drop::of(&d, None, false, false, release_modifiers(ui).command);
|
||||
}
|
||||
}
|
||||
|
||||
/// The modifiers (Alt; Cmd on macOS, Ctrl on Windows and Linux) held when the primary button was
|
||||
/// released this frame, as the release event carries them, so a key let go later in the same frame
|
||||
/// does not change the drop. Without such an event, the modifiers held at the end of the frame.
|
||||
fn release_modifiers(ui: &Ui) -> egui::Modifiers {
|
||||
ui.input(|i| {
|
||||
i.events
|
||||
.iter()
|
||||
.find_map(|e| match e {
|
||||
egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, modifiers, .. } => Some(*modifiers),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or(i.modifiers)
|
||||
})
|
||||
}
|
||||
|
||||
/// The colour group `name` is, or the one swatch `name` belongs to.
|
||||
pub(super) fn group_of(d: &Document, name: &str) -> Option<String> {
|
||||
if d.swatch_groups.iter().any(|g| g.name == name) {
|
||||
@@ -253,9 +270,20 @@ fn replaces(d: &Document, with: &str, target: &str) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// `paint` as swatch params. A solid color other than Registration is sent as the color the drag
|
||||
/// carries, not as its base swatch and tint, which the command would resolve again at the drop.
|
||||
fn shown_color_params(paint: &Paint) -> Value {
|
||||
match paint.color() {
|
||||
Some(c) if !paint.is_registration() => crate::panels::swatch_paint_params(&Paint::solid(c)),
|
||||
_ => crate::panels::swatch_paint_params(paint),
|
||||
}
|
||||
}
|
||||
|
||||
/// 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). With Alt also held, a color dropped on a swatch it can replace
|
||||
/// replaces that swatch's color with the color the drag shows and makes no spot color.
|
||||
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 {
|
||||
@@ -266,18 +294,24 @@ pub(super) fn apply_drop(app: &mut VectorcraftApp, drop: Drop) {
|
||||
Some(p) => ("swatch.move", p),
|
||||
None => return,
|
||||
},
|
||||
// Alt: an edited gradient (or colour) replaces the swatch it is dropped on.
|
||||
Drop::New { paint, target: Some(t), replace: true }
|
||||
// Alt: an edited gradient (or colour) replaces the swatch it is dropped on. With Cmd/Ctrl also
|
||||
// held, a tint gives the color the drag shows; Alt alone sends the paint as it is.
|
||||
Drop::New { paint, target: Some(t), replace: true, spot }
|
||||
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)}))
|
||||
let p = if spot { shown_color_params(&paint) } else { crate::panels::swatch_paint_params(&paint) };
|
||||
("swatch.edit", json!({"name": t, "paint": p}))
|
||||
}
|
||||
Drop::New { paint, target, .. } => {
|
||||
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);
|
||||
Drop::New { paint, target, spot, .. } => {
|
||||
// Only a spot color needs a color of its own; other drops keep a tint's link to its base.
|
||||
let mut p = if spot { shown_color_params(&paint) } else { crate::panels::swatch_paint_params(&paint) };
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -1119,6 +1119,237 @@ 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<String> = 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::<PanelDrag>(&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 tint Cmd/Ctrl-dropped becomes a spot color of the color the drag showed, even when its base
|
||||
/// swatch changes between the drag start and the drop.
|
||||
#[test]
|
||||
fn a_cmd_dropped_tint_makes_its_spot_from_the_captured_color() {
|
||||
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 tint = app.session.doc().unwrap().doc.tint_paint("Orange", 0.4).expect("a tint of Orange");
|
||||
let shown = tint.color().expect("a color");
|
||||
app.run("swatch.edit", json!({"name": "Orange", "paint": {"color": "#2040c0"}})).unwrap();
|
||||
drop_paint_on(&mut app, &ctx, "Red", tint, Modifiers::COMMAND, 1.0);
|
||||
let newest = newest_swatch(&app);
|
||||
assert_eq!((newest.paint, newest.spot), (Paint::solid(shown), true), "{}", app.ui.status);
|
||||
}
|
||||
|
||||
/// A tint Cmd/Ctrl+Alt-dropped on a solid swatch gives it the color the drag showed, even when the
|
||||
/// tint's base swatch changes between the drag start and the drop.
|
||||
#[test]
|
||||
fn a_tint_alt_dropped_on_a_swatch_replaces_it_with_the_captured_color() {
|
||||
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 tint = app.session.doc().unwrap().doc.tint_paint("Orange", 0.4).expect("a tint of Orange");
|
||||
let shown = tint.color().expect("a color");
|
||||
app.run("swatch.edit", json!({"name": "Orange", "paint": {"color": "#2040c0"}})).unwrap();
|
||||
drop_paint_on(&mut app, &ctx, "Red", tint, Modifiers::COMMAND | Modifiers::ALT, 1.0);
|
||||
let red = app.session.doc().unwrap().doc.swatch("Red").cloned().expect("Red");
|
||||
assert_eq!(red.paint.color(), Some(shown), "{}", app.ui.status);
|
||||
}
|
||||
|
||||
/// A tint Alt-dropped on a solid swatch without Cmd/Ctrl sends the tint as it is, so the swatch takes
|
||||
/// the tint of its base swatch as the base is at the drop.
|
||||
#[test]
|
||||
fn a_tint_alt_dropped_without_cmd_keeps_the_tint_paint() {
|
||||
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 tint = app.session.doc().unwrap().doc.tint_paint("Orange", 0.4).expect("a tint of Orange");
|
||||
let shown = tint.color().expect("a color");
|
||||
app.run("swatch.edit", json!({"name": "Orange", "paint": {"color": "#2040c0"}})).unwrap();
|
||||
let now = app.session.doc().unwrap().doc.tint_paint("Orange", 0.4).and_then(|p| p.color()).expect("a tint of Orange");
|
||||
assert_ne!(now, shown);
|
||||
drop_paint_on(&mut app, &ctx, "Red", tint, Modifiers::ALT, 1.0);
|
||||
let red = app.session.doc().unwrap().doc.swatch("Red").cloned().expect("Red");
|
||||
assert_eq!(red.paint.color(), Some(now), "{}", app.ui.status);
|
||||
}
|
||||
|
||||
/// A drop on the list follows the modifiers the release carries, not the ones held at the end of the
|
||||
/// frame: Cmd/Ctrl let go after the release still makes a spot color, Cmd/Ctrl pressed after it does
|
||||
/// not, and Alt let go after the release still replaces the swatch.
|
||||
#[test]
|
||||
fn a_drop_follows_the_modifiers_of_its_release() {
|
||||
let mut app = app();
|
||||
let ctx = context();
|
||||
frame(&mut app, &ctx, vec![], 0.0, show);
|
||||
let at = tile_center(&ctx, "Red");
|
||||
let drop = |app: &mut VectorcraftApp, color: &str, held: Modifiers, after: Modifiers, time: f64| {
|
||||
egui::DragAndDrop::set_payload(&ctx, PanelDrag::paint(Paint::solid(Color::from_hex(color).unwrap())));
|
||||
let release = Event::PointerButton { pos: at, button: PointerButton::Primary, pressed: false, modifiers: held };
|
||||
frame_with(app, &ctx, vec![Event::PointerMoved(at), release, Event::ModifiersChanged(after)], held, time, show);
|
||||
};
|
||||
let spots = spot_count(&app);
|
||||
drop(&mut app, "#30a050", Modifiers::COMMAND, Modifiers::NONE, 1.0);
|
||||
assert_eq!(spot_count(&app), spots + 1, "Cmd/Ctrl held at the release: {}", app.ui.status);
|
||||
let count = app.session.doc().unwrap().doc.swatches_iter().count();
|
||||
drop(&mut app, "#50a030", Modifiers::NONE, Modifiers::COMMAND, 2.0);
|
||||
let d = &app.session.doc().unwrap().doc;
|
||||
assert_eq!((d.swatches_iter().count(), spot_count(&app)), (count + 1, spots + 1), "{}", app.ui.status);
|
||||
drop(&mut app, "#2040c0", Modifiers::ALT, Modifiers::NONE, 3.0);
|
||||
let d = &app.session.doc().unwrap().doc;
|
||||
assert_eq!(d.swatches_iter().count(), count + 1, "Alt held at the release adds no swatch: {}", app.ui.status);
|
||||
assert_eq!(d.swatch("Red").and_then(|w| w.paint.color()), Color::from_hex("#2040c0"));
|
||||
}
|
||||
|
||||
/// 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]
|
||||
|
||||
@@ -1903,6 +1903,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 Cmd/Ctrl and Alt are read from the release itself, so a key let go in the same frame after the release does not change the drop; 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; a drop uses the color the drag showed, also when the tint's base swatch changes before the release; with Alt also held, a color dropped on a solid swatch replaces it with the color the drag showed and makes no spot color, and one dropped on Registration or a tint swatch becomes a spot color; Alt without Cmd/Ctrl replaces a solid swatch with a dragged tint as before, taking the tint of its base swatch as the base is at the release; 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`, `cmd_drops_of_tints_and_with_alt_follow_the_replacement_rule`, `a_cmd_dropped_tint_makes_its_spot_from_the_captured_color`, `a_tint_alt_dropped_on_a_swatch_replaces_it_with_the_captured_color`, `a_tint_alt_dropped_without_cmd_keeps_the_tint_paint` and `a_drop_follows_the_modifiers_of_its_release` 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`.
|
||||
|
||||
Reference in New Issue
Block a user