Merge pull request #8244 from dotCooCoo/feat/graphic-styles-drag-to-delete

Graphic Styles: a style dragged onto Delete Graphic Style is deleted
This commit is contained in:
BFlat
2026-11-17 09:48:00 +07:00
committed by GitHub
3 changed files with 132 additions and 10 deletions
+127 -9
View File
@@ -595,11 +595,13 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
new_style(app, alt_held(ui));
}
drop_on_new(app, ui, &new, &sel);
if widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Graphic Style (Alt-click: without asking)"), false, !sel.is_empty(), 24.0)
.clicked()
{
// So is Delete Graphic Style, which deletes a style dropped on it.
let trash_enabled = !sel.is_empty() || dragged_style(ui.ctx(), &doc).is_some();
let trash = widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Graphic Style (Alt-click: without asking)"), false, trash_enabled, 24.0);
if trash.clicked() && !sel.is_empty() {
delete(app, &sel, alt_held(ui));
}
drop_on_delete(app, ui, &trash, &sel);
});
}
@@ -673,6 +675,22 @@ fn drop_on_new(app: &mut VectorcraftApp, ui: &Ui, button: &Response, sel: &[Stri
}
}
/// A style dragged onto Delete Graphic Style (`button`): the button is outlined while the style is
/// held over it, and on release the style, with the styles highlighted with it (`sel`), is deleted
/// as the button deletes ([`delete`]): after asking, or at once with Alt held. Other drags are left
/// to their own targets.
fn drop_on_delete(app: &mut VectorcraftApp, ui: &Ui, button: &Response, sel: &[String]) {
let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return };
let Some(name) = dragged_style(ui.ctx(), &doc) else { return };
if button.dnd_hover_payload::<PanelDrag>().is_none() {
return;
}
widgets::drop_target_outline(ui, button.rect);
if button.dnd_release_payload::<PanelDrag>().is_some() {
delete(app, &carried(&doc, sel, &name), alt_held(ui));
}
}
/// Duplicates `names` (`graphicStyle.duplicate`, each copy at the end of the list) in one undo
/// step and highlights the copies. A failure is shown in the status bar and changes nothing.
fn duplicate(app: &mut VectorcraftApp, ctx: &egui::Context, names: &[String]) {
@@ -1223,7 +1241,6 @@ mod tests {
/// A style dropped on New Graphic Style is duplicated at the end of the list, also with no art
/// selected; a highlighted style carries the other highlighted styles with it, in one undo step.
/// A style dropped on the Delete button is not moved in the list.
#[test]
fn a_style_dropped_on_new_graphic_style_is_duplicated_at_the_end() {
let mut app = app();
@@ -1307,11 +1324,112 @@ mod tests {
new_button(&mut app, release(at));
assert_eq!(names(&app), n);
}
// A style dropped on the Delete button below the list is not moved in the list.
let (trash, _) = button(&mut app, vec![], "Delete Graphic Style (Alt-click: without asking)");
egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[1].clone()));
button(&mut app, release(trash), "Delete Graphic Style (Alt-click: without asking)");
assert_eq!(names(&app), n);
}
/// A style dropped on Delete Graphic Style is deleted as the button deletes: after asking, or at
/// once with Alt held, also with no style highlighted, and the button is outlined while the style
/// is held over it. A highlighted style carries the other highlighted styles with it, in one undo
/// step. Art linked to a deleted style keeps its look and is unlinked. Other drags delete nothing.
#[test]
fn a_style_dropped_on_delete_graphic_style_is_deleted_as_the_button_deletes() {
let mut app = app();
app.run("graphicStyle.new", json!({"name": "Mine"})).unwrap();
app.run("select.none", json!({})).unwrap();
let ctx = egui::Context::default();
ctx.enable_accesskit();
let screen = Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(260.0, 600.0)));
const DELETE: &str = "Delete Graphic Style (Alt-click: without asking)";
// One frame of the panel with `events` and `modifiers` held: the center of the Delete
// button, whether it is enabled, and whether a drop-target outline is drawn around it.
let trash = |app: &mut VectorcraftApp, events: Vec<egui::Event>, modifiers: egui::Modifiers| {
let events = std::iter::once(egui::Event::ModifiersChanged(modifiers)).chain(events).collect();
let mut out = ctx.run_ui(egui::RawInput { screen_rect: screen, events, ..Default::default() }, |ui| show(app, ui));
out.textures_delta.clear();
let nodes = &out.platform_output.accesskit_update.as_ref().expect("accessibility tree").nodes;
let (_, node) = nodes.iter().find(|(_, n)| n.label() == Some(DELETE)).expect("the Delete button");
let b = node.bounds().expect("visible button");
let at = pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32);
let accent = Tokens::get(&ctx).accent;
let outlined = out.shapes.iter().any(|c| match &c.shape {
egui::Shape::Rect(r) => r.stroke.width == 1.5 && r.stroke.color == accent && r.rect.contains(at),
_ => false,
});
(at, !node.is_disabled(), outlined)
};
let release = |at: egui::Pos2, modifiers: egui::Modifiers| {
let up = egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed: false, modifiers };
vec![egui::Event::PointerMoved(at), up]
};
let none = egui::Modifiers::default();
let rect = app.session.active().unwrap().doc.layers[0].children().unwrap()[0].id;
let node = |app: &VectorcraftApp| app.session.active().unwrap().doc.node(rect).unwrap().clone();
let mine_id = app.session.active().unwrap().doc.graphic_style("Mine").unwrap().id;
assert_eq!(node(&app).extras().graphic_style, Some(mine_id));
let look = node(&app).appearance;
for view in [View::SmallList, View::Thumbnail] {
app.ui.graphic_styles_view = view;
set_pstate(&ctx, "gs-sel", Vec::<String>::new());
let n = names(&app);
// With no style highlighted the button is off until a style is held over it.
let (at, on, outlined) = trash(&mut app, vec![], none);
assert!(!on && !outlined, "{view:?}: off with no style highlighted");
egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle("Mine".into()));
let (_, on, outlined) = trash(&mut app, vec![egui::Event::PointerMoved(at)], none);
assert!(on && outlined, "{view:?}: on and outlined while a style is held over it");
assert_eq!(names(&app), n, "{view:?}: holding it there changes nothing");
// Released on it: the button's question, and nothing is deleted or moved until OK.
egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle("Mine".into()));
trash(&mut app, release(at, none), none);
assert_eq!(names(&app), n, "{view:?}");
assert_eq!(app.ui.dialog.as_ref().unwrap().str("message"), "Delete the graphic style “Mine”?", "{view:?}");
crate::dialogs::confirm(&mut app).unwrap();
let rest: Vec<String> = n.iter().filter(|s| *s != "Mine").cloned().collect();
assert_eq!(names(&app), rest, "{view:?}");
assert_eq!(node(&app).extras().graphic_style, None, "{view:?}: the art is unlinked");
assert_eq!(node(&app).appearance, look, "{view:?}: and keeps its look");
app.run("edit.undo", json!({})).unwrap();
assert_eq!(names(&app), n, "{view:?}: one undo step");
assert_eq!(node(&app).extras().graphic_style, Some(mine_id), "{view:?}: undo links the art again");
}
// Two highlighted styles, one of them dragged, with Alt held: both go at once, in one step.
app.ui.graphic_styles_view = View::SmallList;
let n = names(&app);
let (at, _, _) = trash(&mut app, vec![], none);
set_pstate(&ctx, "gs-sel", vec![n[3].clone(), n[0].clone()]);
egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[3].clone()));
trash(&mut app, release(at, egui::Modifiers::ALT), egui::Modifiers::ALT);
assert!(app.ui.dialog.is_none(), "Alt deletes without asking");
let rest: Vec<String> = n.iter().filter(|s| **s != n[0] && **s != n[3]).cloned().collect();
assert_eq!(names(&app), rest);
assert!(selected(&ctx, &app.session.active().unwrap().doc.clone()).is_empty(), "the deleted styles are no longer highlighted");
app.run("edit.undo", json!({})).unwrap();
assert_eq!(names(&app), n, "the group goes in one undo step");
app.run("edit.redo", json!({})).unwrap();
assert_eq!(names(&app), rest);
app.run("edit.undo", json!({})).unwrap();
// A style that is not highlighted is deleted alone, and the highlight stays.
set_pstate(&ctx, "gs-sel", vec![n[3].clone(), n[0].clone()]);
egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(n[2].clone()));
trash(&mut app, release(at, none), none);
assert_eq!(app.ui.dialog.as_ref().unwrap().str("message"), format!("Delete the graphic style “{}”?", n[2]));
crate::dialogs::confirm(&mut app).unwrap();
let rest: Vec<String> = n.iter().filter(|s| **s != n[2]).cloned().collect();
assert_eq!(names(&app), rest);
assert_eq!(selected(&ctx, &app.session.active().unwrap().doc.clone()), [n[3].clone(), n[0].clone()]);
app.run("edit.undo", json!({})).unwrap();
// Other drags dropped on the button delete nothing and ask nothing.
set_pstate(&ctx, "gs-sel", Vec::<String>::new());
for payload in [PanelDrag::Art(vec![rect]), PanelDrag::Appearance(rect), PanelDrag::GraphicStyle("No such style".into())] {
egui::DragAndDrop::set_payload(&ctx, payload);
let (_, on, outlined) = trash(&mut app, vec![egui::Event::PointerMoved(at)], none);
assert!(!on && !outlined);
trash(&mut app, release(at, egui::Modifiers::ALT), egui::Modifiers::ALT);
assert_eq!(names(&app), n);
assert!(app.ui.dialog.is_none());
}
}
#[test]
+4 -1
View File
@@ -4313,7 +4313,10 @@ style is applied to gets them at the same place relative to its own bounds.
(each on top of the ones before it) with the first one's transparency; `graphicStyle.move {name, to}` reorders the
list (what dragging a style in the panel does). `graphicStyle.duplicate {name}` adds a copy of the style at the end
of the list, named `<name> copy` (`<name> copy 2` and so on when that is taken), with no object linked to it; the
panel menu's Duplicate Graphic Style and a style dropped on the panel's New Graphic Style button run it. Override Character Color (`graphicStyle.setOptions
panel menu's Duplicate Graphic Style and a style dropped on the panel's New Graphic Style button run it.
`graphicStyle.delete {name}` or `{names}` deletes styles in one undo step; objects linked to them keep their look and
are no longer linked. The panel's Delete Graphic Style button and menu item, and a style dropped on the button, run it
after asking; Alt held on the button, or on the drop, deletes without asking. Override Character Color (`graphicStyle.setOptions
{overrideCharColor}`, the preference `overrideCharColor`, on by default) makes a style applied to type replace its
characters' fill and stroke with the style's fills and strokes; off, the characters keep their colour under them.
+1
View File
@@ -1815,6 +1815,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
The built-in Textures graphic style library (`graphicStyle.addFromLibrary {library: "textures"}`) has eight styles that paint their fills and strokes with the texture effects: Fine Grain (Grain), Canvas Weave and Burlap Sack (Texturizer), Cracked Glaze (Craquelure), Mosaic Floor (Mosaic Tiles), Quilted Squares (Patchwork), Leaded Glass (Stained Glass) and Damp Paper (Water Paper). The help page names new graphic styles for textures ([What's new](https://helpx.adobe.com/illustrator/desktop/new-features/whats-new.html)) without naming them, so the styles, their names and their settings are VectorCraft's own (`tests::stylelib::textures_styles_apply_their_texture_effects_and_keep_their_params_through_save_and_open`).
In the Graphic Styles panel, Shift-click selects a range of styles and Ctrl/Cmd-click adds or removes one.
A graphic style dragged onto the Graphic Styles panel's New Graphic Style button is duplicated, as the panel menu's Duplicate Graphic Style does, and both put the copy at the end of the list, as the help page describes ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=391)). VectorCraft's own rules: the button takes the drop with no art selected; a dragged style that is highlighted brings the other highlighted styles, copied in panel order in one undo step, and the copies are highlighted; the copy is named `<name> copy`, with a number when that is taken, and no art is linked to it (`a_style_dropped_on_new_graphic_style_is_duplicated_at_the_end` in `crates/ui-egui/src/panels/graphic_styles.rs`, `tests::styles::duplicate_puts_the_copy_at_the_end_of_the_list_in_one_undo_step`).
A graphic style dragged onto the Graphic Styles panel's Delete Graphic Style button is deleted, which the help page gives as another way to delete a style besides the panel menu's Delete Graphic Style; art that used the style keeps its look and is no longer linked to it ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=392)). VectorCraft's own rules: the drop asks first as the button does, and with Alt held it deletes without asking; the button takes the drop with no style highlighted; a dragged style that is highlighted brings the other highlighted styles, deleted in one undo step (`a_style_dropped_on_delete_graphic_style_is_deleted_as_the_button_deletes` in `crates/ui-egui/src/panels/graphic_styles.rs`).
In the Graphic Styles panel's thumbnail and list views, a style with no fill and no stroke, one with only effects or transparency included, shows its preview shape with a black outline, a white fill and a red slash, as the help page describes for the panel's thumbnails ([Graphic styles](https://helpx.adobe.com/illustrator/using/graphic-styles.html)); its effects still draw on that shape. The Control bar's Style picker and chip, graphic style library panels and the large preview on the selected object show the same marker. A fill or stroke row that paints None does not count as a fill or stroke, and a hidden row or one with zero opacity does; these rules, the marker outside the panel's thumbnails and the slash's direction and size are VectorCraft's own (`a_style_with_no_fill_and_no_stroke_shows_an_outlined_shape_and_a_red_slash` in `crates/ui-egui/src/panels/graphic_styles.rs`).
Applying a style to several objects, and Redefine Graphic Style, give the objects one shared copy of the style's appearance instead of a copy each; an object that is edited later gets its own copy, and an object whose placed gradients are fitted to its own bounds gets its own. The undo history's memory estimate counts a shared appearance once. Saved files are unchanged (`crates/engine/src/tests/styles.rs`).
- **Several text styles at once:** in the Character Styles and Paragraph Styles panels, Shift-click highlights a range of styles and Ctrl/Cmd-click adds or removes one, without applying them; the panel menu's Select All Unused (`charStyle.unused`, `paraStyle.unused`) highlights the styles no type uses (in the layers, opacity masks, symbols, graph designs, pattern tiles and the art of brushes), never the Normal style; Delete, the button or the menu item, deletes every highlighted style but Normal in one undo step (`charStyle.delete {names}`, `paraStyle.delete {names}`). The menu's Duplicate copies every highlighted style in one undo step and highlights the copies. A highlighted row dragged onto Create New Style or Delete carries every highlighted style: dropped on Create New Style it copies them all and highlights the copies, and dropped on Delete it deletes them all but Normal and clears the highlight; a row from outside the highlight carries only its own style. Public reference: [Character and paragraph styles](https://web.archive.org/web/20261015081534/https://helpx.adobe.com/illustrator/using/character-paragraph-styles.html).