mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 13:33:51 +00:00
Graphic Styles: art or an appearance dropped on a style with Alt replaces that style
Art dragged off the canvas, or the Appearance panel's thumbnail, dropped on a style in the Graphic Styles panel with Alt held runs graphicStyle.redefine with that style's name and the object's id (the first object of the art), in one undo step. The style keeps its name, id and place in the list, and the art still linked to it takes the new look. The style is outlined while one is held over it with Alt. An object already linked to the style with its look changes nothing. Without Alt the drop still makes a new style, and a style dropped on a style still moves it.
This commit is contained in:
@@ -318,8 +318,14 @@ impl Session {
|
||||
/// it is still linked (still has that style's look). A graph series group that holds nothing of its own stands
|
||||
/// for the topmost path directly inside it, which a style applied to the group links.
|
||||
pub fn selection_graphic_style(&self) -> Option<(&GraphicStyle, bool)> {
|
||||
self.graphic_style_of(*self.active()?.selection.subjects().first()?)
|
||||
}
|
||||
|
||||
/// The graphic style of object `id` of the active document, as [`Self::selection_graphic_style`]
|
||||
/// gives it for the first selected object.
|
||||
pub fn graphic_style_of(&self, id: NodeId) -> Option<(&GraphicStyle, bool)> {
|
||||
let st = self.active()?;
|
||||
let n = super::appearance::look_holder(&st.doc, st.doc.node(*st.selection.subjects().first()?)?);
|
||||
let n = super::appearance::look_holder(&st.doc, st.doc.node(id)?);
|
||||
let g = st.doc.graphic_style_by_id(n.extras().graphic_style?)?;
|
||||
Some((g, in_sync(n, g)))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
//! double-click opens Graphic Style Options. Dragging a style moves it in the list, applies it
|
||||
//! to the art it is dropped on (`canvas::panel_drop`), or, dropped on New Graphic Style, adds a
|
||||
//! copy of it and of the styles highlighted with it at the end of the list; art dragged off the
|
||||
//! canvas or the Appearance panel's thumbnail dropped on the panel becomes a new style. Holding the right button on a style
|
||||
//! canvas or the Appearance panel's thumbnail dropped on the panel becomes a new style, and
|
||||
//! dropped on a style with Alt held replaces that style with its look (`graphicStyle.redefine`).
|
||||
//! Holding the right button on a style
|
||||
//! shows it large, on the selected object when there is one. The Control bar's Style picker lists
|
||||
//! the same tiles ([`picker`]). Graphic style libraries open in library panels
|
||||
//! ([`GraphicStyleLibraries`]).
|
||||
@@ -364,6 +366,8 @@ struct Events {
|
||||
moved: Option<(String, usize)>,
|
||||
/// Art or an appearance dropped on the panel: a new style from this object.
|
||||
new_from: Option<NodeId>,
|
||||
/// Art or an appearance dropped on a style with Alt held: the style takes this object's look.
|
||||
replaced: Option<(String, NodeId)>,
|
||||
/// The style the right button is held on.
|
||||
large: Option<usize>,
|
||||
/// A style is dragged over a tile or row.
|
||||
@@ -383,10 +387,26 @@ fn clicked(ui: &Ui, resp: &Response, name: &str) -> Option<Click> {
|
||||
|
||||
/// Clicks, drags and the right button on the tile or row `resp` of style `i` of `d` (`list`: rows
|
||||
/// stack downwards). A drag from it carries the style ([`PanelDrag::GraphicStyle`]); a style
|
||||
/// dragged over it lands before or after it by the pointer's half.
|
||||
/// dragged over it lands before or after it by the pointer's half. Art (its first object) or the
|
||||
/// Appearance panel's thumbnail held over it with Alt outlines it, and released there replaces the
|
||||
/// style with that object's look; without Alt it is left to the list ([`zone_input`]).
|
||||
fn cell_input(ui: &Ui, resp: &Response, d: &Document, i: usize, list: bool, ev: &mut Events) {
|
||||
let name = &d.graphic_styles[i].name;
|
||||
widgets::drag_source(ui, resp, || PanelDrag::GraphicStyle(name.clone()));
|
||||
let source = resp.dnd_hover_payload::<PanelDrag>().and_then(|drag| match &*drag {
|
||||
PanelDrag::Art(ids) => ids.first().copied(),
|
||||
PanelDrag::Appearance(id) => Some(*id),
|
||||
_ => None,
|
||||
});
|
||||
if let Some(id) = source
|
||||
&& alt_held(ui)
|
||||
{
|
||||
ev.over = true;
|
||||
widgets::drop_target_outline(ui, resp.rect);
|
||||
if resp.dnd_release_payload::<PanelDrag>().is_some() {
|
||||
ev.replaced = Some((name.clone(), id));
|
||||
}
|
||||
}
|
||||
if let Some(drag) = resp.dnd_hover_payload::<PanelDrag>()
|
||||
&& let PanelDrag::GraphicStyle(moving) = &*drag
|
||||
{
|
||||
@@ -505,6 +525,12 @@ fn act(app: &mut VectorcraftApp, ui: &Ui, s: &Shown, ev: Events, picker: bool) {
|
||||
if let Some(id) = ev.new_from {
|
||||
run(app, "graphicStyle.new", json!({ "id": id.0 }));
|
||||
}
|
||||
// An object that is linked to the style and still has its look leaves the style as it is.
|
||||
if let Some((name, id)) = ev.replaced
|
||||
&& !app.session.graphic_style_of(id).is_some_and(|(g, linked)| linked && g.name == name)
|
||||
{
|
||||
run(app, "graphicStyle.redefine", json!({ "name": name, "id": id.0 }));
|
||||
}
|
||||
match ev.click {
|
||||
Some(Click::Pick(name, _)) if picker => {
|
||||
app.run("graphicStyle.apply", json!({"name": name, "add": alt_held(ui)})).ok();
|
||||
@@ -1432,6 +1458,105 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Art or the Appearance panel's thumbnail dropped on a style with Alt held replaces that style
|
||||
/// with the object's look, in one undo step: the style keeps its name, its place and its id, the
|
||||
/// objects still linked to it take the new look, and the object becomes linked. The style is
|
||||
/// outlined while one is held over it with Alt. Without Alt the drop makes a new style; a style
|
||||
/// dragged with Alt still only moves; an object linked to the style with its look, an empty art
|
||||
/// drag and an object that is gone change nothing and record no undo step.
|
||||
#[test]
|
||||
fn art_or_an_appearance_dropped_on_a_style_with_alt_replaces_that_style() {
|
||||
let mut app = app();
|
||||
let rect = app.session.active().unwrap().doc.layers[0].children().unwrap()[0].id;
|
||||
app.run("paint.setFill", json!({"color": "#ff0000", "ids": [rect.0]})).unwrap();
|
||||
app.run("graphicStyle.new", json!({"name": "Red", "id": rect.0})).unwrap();
|
||||
app.run("graphicStyle.move", json!({"name": "Red", "to": 0})).unwrap();
|
||||
app.run("shape.ellipse", json!({"x": 60, "y": 60, "width": 20, "height": 20})).unwrap();
|
||||
let oval = app.session.active().unwrap().selection.objects[0];
|
||||
app.run("paint.setFill", json!({"color": "#00ff00", "ids": [oval.0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let screen = Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(260.0, 600.0)));
|
||||
// One frame of the panel with `events` and `modifiers` held: whether a drop-target outline
|
||||
// the size of one style's tile or row is drawn around `at`.
|
||||
let frame_at = |app: &mut VectorcraftApp, at: egui::Pos2, 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 accent = Tokens::get(&ctx).accent;
|
||||
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) && r.rect.height() < 45.0,
|
||||
_ => false,
|
||||
})
|
||||
};
|
||||
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, alt) = (egui::Modifiers::default(), egui::Modifiers::ALT);
|
||||
let doc = |app: &VectorcraftApp| app.session.active().unwrap().doc.clone();
|
||||
let steps = |app: &VectorcraftApp| app.session.doc().unwrap().history.undo.len();
|
||||
let red = doc(&app).graphic_style("Red").unwrap().clone();
|
||||
let green = doc(&app).node(oval).unwrap().appearance.fill_paint();
|
||||
assert_ne!(red.appearance.fill_paint(), green);
|
||||
// The first style: the top of the list's first row, or its first tile.
|
||||
for (view, at) in [(View::SmallList, pos2(60.0, 9.0)), (View::Thumbnail, pos2(20.0, 20.0))] {
|
||||
app.ui.graphic_styles_view = view;
|
||||
frame_at(&mut app, at, vec![], none);
|
||||
for payload in [PanelDrag::Art(vec![oval]), PanelDrag::Appearance(oval)] {
|
||||
let n = names(&app);
|
||||
let before = steps(&app);
|
||||
// Held over the style with Alt it is outlined; without Alt it is not.
|
||||
egui::DragAndDrop::set_payload(&ctx, payload.clone());
|
||||
assert!(!frame_at(&mut app, at, vec![egui::Event::PointerMoved(at)], none), "{view:?} {payload:?}: no outline without Alt");
|
||||
assert!(frame_at(&mut app, at, vec![egui::Event::PointerMoved(at)], alt), "{view:?} {payload:?}: outlined with Alt");
|
||||
assert_eq!(names(&app), n, "{view:?} {payload:?}: holding it there changes nothing");
|
||||
// Released there with Alt: Red takes the oval's look and keeps its name, place and id.
|
||||
frame_at(&mut app, at, release(at, alt), alt);
|
||||
let d = doc(&app);
|
||||
assert_eq!(names(&app), n, "{view:?} {payload:?}");
|
||||
let g = d.graphic_style("Red").unwrap();
|
||||
assert_eq!((g.id, g.appearance.fill_paint()), (red.id, green.clone()), "{view:?} {payload:?}");
|
||||
assert_eq!(d.node(rect).unwrap().appearance.fill_paint(), green, "{view:?} {payload:?}: the linked rectangle follows");
|
||||
assert_eq!(d.node(rect).unwrap().extras().graphic_style, Some(red.id));
|
||||
assert_eq!(d.node(oval).unwrap().extras().graphic_style, Some(red.id), "{view:?} {payload:?}: the oval is linked");
|
||||
assert_eq!(steps(&app), before + 1, "{view:?} {payload:?}: one undo step");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
let d = doc(&app);
|
||||
assert_eq!(d.graphic_style("Red").unwrap().appearance, red.appearance, "{view:?} {payload:?}: undo restores the style");
|
||||
assert_eq!(d.node(oval).unwrap().extras().graphic_style, None);
|
||||
assert_eq!(d.node(rect).unwrap().appearance.fill_paint(), red.appearance.fill_paint());
|
||||
}
|
||||
|
||||
// Without Alt the oval becomes a new style at the end, and Red stays as it was.
|
||||
let n = names(&app);
|
||||
egui::DragAndDrop::set_payload(&ctx, PanelDrag::Art(vec![oval]));
|
||||
frame_at(&mut app, at, release(at, none), none);
|
||||
assert_eq!(names(&app).len(), n.len() + 1, "{view:?}");
|
||||
assert_eq!(doc(&app).graphic_style("Red").unwrap().appearance, red.appearance, "{view:?}");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
|
||||
// A style dragged onto Red with Alt moves and replaces nothing.
|
||||
let last = n.last().unwrap().clone();
|
||||
egui::DragAndDrop::set_payload(&ctx, PanelDrag::GraphicStyle(last.clone()));
|
||||
frame_at(&mut app, at, release(at, alt), alt);
|
||||
assert_eq!(names(&app)[0], last, "{view:?}");
|
||||
assert_eq!(doc(&app).graphic_style("Red").unwrap().appearance, red.appearance, "{view:?}");
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(names(&app), n, "{view:?}");
|
||||
|
||||
// The rectangle that is linked to Red with its look, an empty drag of art and an object
|
||||
// that is gone change nothing and record nothing.
|
||||
let before = steps(&app);
|
||||
for payload in [PanelDrag::Art(vec![rect]), PanelDrag::Appearance(rect), PanelDrag::Art(vec![]), PanelDrag::Art(vec![NodeId(9999)])] {
|
||||
egui::DragAndDrop::set_payload(&ctx, payload.clone());
|
||||
frame_at(&mut app, at, release(at, alt), alt);
|
||||
assert_eq!(names(&app), n, "{view:?} {payload:?}");
|
||||
assert_eq!(doc(&app).graphic_style("Red").unwrap().appearance, red.appearance, "{view:?} {payload:?}");
|
||||
assert_eq!(steps(&app), before, "{view:?} {payload:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_click_selects_a_range_and_cmd_click_adds_or_removes_one_style() {
|
||||
let mut app = app();
|
||||
|
||||
@@ -13,13 +13,15 @@ pub enum PanelDrag {
|
||||
/// it is dropped.
|
||||
Paint { paint: Paint, params: serde_json::Value, rows: Option<SwatchRows>, library: Option<(String, String)> },
|
||||
/// The Appearance panel's thumbnail: art it is dropped on takes object `0`'s appearance
|
||||
/// (`appearance.copyFrom`); the Graphic Styles panel makes a style of it.
|
||||
/// (`appearance.copyFrom`); the Graphic Styles panel makes a style of it, or with Alt held
|
||||
/// replaces the style it is dropped on with it (`graphicStyle.redefine`).
|
||||
Appearance(vectorcraft_doc::NodeId),
|
||||
/// A Graphic Styles panel style: art it is dropped on takes it (`graphicStyle.apply` with its
|
||||
/// `ids`); the panel moves it to where it is dropped.
|
||||
GraphicStyle(String),
|
||||
/// The selected art, dragged off the canvas with the Selection tool: the Graphic Styles panel
|
||||
/// makes a style of the first object (`graphicStyle.new`), the Symbols panel a symbol of it all
|
||||
/// makes a style of the first object (`graphicStyle.new`), or with Alt held replaces the style
|
||||
/// it is dropped on with that object's look (`graphicStyle.redefine`), the Symbols panel a symbol of it all
|
||||
/// (`symbol.new`), the Swatches panel a pattern swatch of a copy (`object.pattern.make`) and the
|
||||
/// Brushes panel an Art brush (`brush.new`).
|
||||
Art(Vec<vectorcraft_doc::NodeId>),
|
||||
|
||||
+4
-1
@@ -4287,7 +4287,10 @@ A graphic style holds an appearance (fills, strokes, effects) plus opacity, blen
|
||||
object's, type its characters'). `graphicStyle.apply {name, ids?}` gives the objects the style and links them;
|
||||
`add: true` adds the style on top of the existing appearance instead. Linked objects stay linked while they keep the
|
||||
style's look: editing their appearance or transparency breaks the link, and `graphicStyle.redefine {name?, id?}`
|
||||
updates only the objects still linked. The art of a column or marker design in a graph series is never linked:
|
||||
updates only the objects still linked. Art dragged off the canvas, or the Appearance panel's thumbnail, dropped on a
|
||||
style in the Graphic Styles panel with Alt held runs `graphicStyle.redefine` with that style's `name` and the object's
|
||||
`id` (the first object of the art); an object already linked to the style with its look changes nothing. The art of a
|
||||
column or marker design in a graph series is never linked:
|
||||
`graphicStyle.new` can make a style from it, and `graphicStyle.redefine` leaves its look as it was and unlinks it,
|
||||
whether it is the source or a linked object. `graphicStyle.list` returns each style with the ids linked to it and the
|
||||
style of the first selected object; `select.same.graphicStyle` selects an object's fellow users.
|
||||
|
||||
@@ -1796,6 +1796,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
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`).
|
||||
The Appearance panel's thumbnail dropped on a graphic style with Alt held replaces that style with the look of the object the panel shows; the style keeps its name and the art that uses it takes the new look, as the help page describes ([the help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=568)). VectorCraft's own rules: art dragged off the canvas does the same with its first object; the style keeps its place in the list, is outlined while one is held over it with Alt, and the replacement is one undo step; an object already linked to the style with its look changes nothing; without Alt the drop makes a new style (`art_or_an_appearance_dropped_on_a_style_with_alt_replaces_that_style` 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).
|
||||
|
||||
Reference in New Issue
Block a user