Graphic Styles: a style with no fill and no stroke shows an outlined shape with a red slash

A style whose rows paint nothing showed as a blank white tile. Its
thumbnail now shows the preview square or type outlined in black and
filled with white, with the style's effects, under a red slash. The
panel's views, the Control bar's Style picker and chip, the dragged
chip, graphic style library panels and the large preview on the
selected object all show it. A row that paints None does not count as a
fill or stroke; a hidden row or one with zero opacity does.
This commit is contained in:
dotCooCoo
2026-11-16 04:59:07 -08:00
parent 7452b6f383
commit 101e4625e9
2 changed files with 169 additions and 11 deletions
+168 -11
View File
@@ -1,5 +1,6 @@
//! Graphic Styles panel: the document's styles as rendered thumbnails (Thumbnail View) or rows
//! (Small and Large List View), shown on a square or on type. Clicking a style applies it to the
//! (Small and Large List View), shown on a square or on type; a style with no fill and no stroke
//! shows the shape outlined in black and filled with white, under a red slash. Clicking a style applies it to the
//! selection (Alt-click adds it on top); Shift-click adds to the panel's selection every style from
//! the last one clicked without Shift through this one; Cmd/Ctrl-click adds or removes one;
//! double-click opens Graphic Style Options. Dragging a style moves it in the list, or applies it
@@ -15,10 +16,10 @@ use std::sync::Arc;
use egui::{Color32, Rect, Response, Sense, Stroke, StrokeKind, TextureHandle, Ui, pos2, vec2};
use serde_json::{Value, json};
use vectorcraft_color::{BlendMode, Paint};
use vectorcraft_color::{BlendMode, Color, Paint};
use vectorcraft_doc::style_libs::STYLE_LIBRARIES;
use vectorcraft_doc::text::{CharStyle, TextObject};
use vectorcraft_doc::{Appearance, AppearanceItem, Document, GraphicStyle, Node, NodeId, NodeKind, PatternDef, StyleLibrary};
use vectorcraft_doc::{Appearance, AppearanceItem, Document, FillLayer, GraphicStyle, Node, NodeId, NodeKind, PatternDef, StrokeLayer, StyleLibrary};
use vectorcraft_engine::cmd::stylelib;
use vectorcraft_engine::cmd::swatchlib::LibraryInfo;
use vectorcraft_geom::{Affine, Point, shapes};
@@ -80,6 +81,48 @@ fn uses_brush(g: &GraphicStyle) -> bool {
g.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(s) if s.brush.is_some()))
}
/// Does `g` have no fill and no stroke? A fill or stroke row whose paint is None does not count; a
/// hidden row or one with zero opacity does. The thumbnails of such a style show the preview shape
/// with a black outline, a white fill and a red slash ([`backing`], [`slash`]).
fn paints_nothing(g: &GraphicStyle) -> bool {
g.appearance.items.iter().all(|i| i.paint().is_none())
}
/// `g` with a white fill below its rows and a black stroke `width` wide above them: the shape a
/// style with no fill and no stroke is shown on, with the style's effects and transparency.
fn backing(g: &GraphicStyle, width: f64) -> GraphicStyle {
let mut g = g.clone();
g.appearance.items.insert(0, AppearanceItem::Fill(FillLayer::new(Paint::solid(Color::WHITE))));
g.appearance.items.push(AppearanceItem::Stroke(StrokeLayer::new(Paint::solid(Color::BLACK), width)));
g
}
/// The red of the slash on the thumbnail of a style with no fill and no stroke.
const SLASH: [f32; 3] = [230.0, 0.0, 0.0];
/// Draw a red slash (`/`) across the middle of `img`, a third of its side long, over what is there.
fn slash(img: &mut egui::ColorImage) {
let [w, h] = img.size;
let side = w.min(h) as f32;
let (cx, cy, half) = (w as f32 / 2.0, h as f32 / 2.0, side / 6.0);
let (a, b) = (pos2(cx - half, cy + half), pos2(cx + half, cy - half));
let radius = (side * 0.035).max(0.9);
let ab = b - a;
for y in 0..h {
for x in 0..w {
let p = pos2(x as f32 + 0.5, y as f32 + 0.5);
let t = ((p - a).dot(ab) / ab.length_sq()).clamp(0.0, 1.0);
let cover = (radius + 0.5 - (p - (a + ab * t)).length()).clamp(0.0, 1.0);
if cover > 0.0
&& let Some(px) = img.pixels.get_mut(y * w + x)
{
let mix = |old: u8, new: f32| (old as f32 + (new - old as f32) * cover).round() as u8;
*px = Color32::from_rgb(mix(px.r(), SLASH[0]), mix(px.g(), SLASH[1]), mix(px.b(), SLASH[2]));
}
}
}
}
/// What a style's thumbnail paints with besides the style: the patterns and brushes of a document,
/// or the patterns of a library.
#[derive(Clone, Copy)]
@@ -147,9 +190,20 @@ fn look_hashes(ctx: &egui::Context, app: &VectorcraftApp) -> Arc<Vec<u64>> {
}
/// Style `g` applied (as `graphicStyle.apply` applies it) to the preview shape, rendered `px`
/// pixels square on white, with `paints`.
/// pixels square on white, with `paints`. A style with no fill and no stroke ([`paints_nothing`])
/// is shown on the shape outlined in black and filled with white, under a red slash.
fn render(app: &VectorcraftApp, paints: Paints, g: &GraphicStyle, preview: Preview, px: u32) -> Option<egui::ColorImage> {
const SIDE: f64 = 100.0;
let empty = paints_nothing(g);
let backed;
let g = if empty {
// An outline 1.5 pixels wide on images up to 150 pixels across, and one hundredth of the
// image width on larger ones.
backed = backing(g, (1.5 * SIDE / px.max(1) as f64).max(1.0));
&backed
} else {
g
};
let mut doc = Document::new(SIDE, SIDE);
doc.patterns = paints.patterns.to_vec();
if uses_brush(g)
@@ -172,7 +226,11 @@ fn render(app: &VectorcraftApp, paints: Paints, g: &GraphicStyle, preview: Previ
let layer = doc.layers[0].id;
doc.insert(Some(layer), 0, app.session.styled(&shape, g)).ok()?;
let img = RENDERER.with(|r| r.borrow_mut().render_region(&doc, vectorcraft_geom::Rect::new(0.0, 0.0, SIDE, SIDE), px as f64 / SIDE, true));
Some(crate::canvas::color_image(&img))
let mut img = crate::canvas::color_image(&img);
if empty {
slash(&mut img);
}
Some(img)
}
/// The thumbnail of style `g` (`look`: its [`look_hash`]) at `size` points.
@@ -226,8 +284,10 @@ pub(super) fn outline(ui: &Ui, r: Rect, on: bool, hovered: bool) {
ui.painter().rect_stroke(r, 0.0, Stroke::new(if on { 2.0 } else { 1.0 }, color), StrokeKind::Inside);
}
/// Style `g` on a copy of the first selected object, `px` pixels square on white. One texture,
/// re-rendered only when the document, the style's look or the size changes.
/// Style `g` on a copy of the first selected object, `px` pixels square on white; a style with no
/// fill and no stroke shows the object outlined in black and filled with white, under a red slash,
/// as [`render`] shows it. One texture, re-rendered only when the document, the style's look or the
/// size changes.
fn object_preview(app: &VectorcraftApp, ctx: &egui::Context, g: &GraphicStyle, look: u64, px: u32) -> Option<TextureHandle> {
let st = app.session.active()?;
let n = st.doc.node(*st.selection.objects.first()?)?;
@@ -238,14 +298,30 @@ fn object_preview(app: &VectorcraftApp, ctx: &egui::Context, g: &GraphicStyle, l
{
return Some(tex);
}
let styled = app.session.styled(n, g);
let img = RENDERER.with(|r| r.borrow_mut().render_node_thumbnail(&st.doc, &styled, px, Some([255; 4])))?;
let color = crate::canvas::color_image(&img);
let tex = ctx.load_texture("gs-large-object", color, egui::TextureOptions::LINEAR);
let tex = ctx.load_texture("gs-large-object", render_object(app, &st.doc, n, g, px)?, egui::TextureOptions::LINEAR);
ctx.data_mut(|d| d.insert_temp(slot, (key, tex.clone())));
Some(tex)
}
/// Style `g` on a copy of `n` (an object of `doc`), rendered `px` pixels square on white: the image
/// of [`object_preview`].
fn render_object(app: &VectorcraftApp, doc: &Document, n: &Node, g: &GraphicStyle, px: u32) -> Option<egui::ColorImage> {
let empty = paints_nothing(g);
let styled = if empty {
// An outline about 1.5 pixels wide on the object scaled to the preview.
let side = n.geometric_bounds().map_or(1.0, |b| b.width().max(b.height()));
app.session.styled(n, &backing(g, (1.5 * side / px.max(1) as f64).max(1e-3)))
} else {
app.session.styled(n, g)
};
let img = RENDERER.with(|r| r.borrow_mut().render_node_thumbnail(doc, &styled, px, Some([255; 4])))?;
let mut img = crate::canvas::color_image(&img);
if empty {
slash(&mut img);
}
Some(img)
}
/// The large preview of style `i` next to the pointer while the right button is held on it: on
/// the selected object when there is one, else on the preview shape.
fn large_preview(app: &VectorcraftApp, ctx: &egui::Context, s: &Shown, i: usize) {
@@ -954,6 +1030,87 @@ mod tests {
assert_eq!(px(2, 2), Color32::WHITE);
}
/// Is `c` the slash's red?
fn red(c: Color32) -> bool {
c.r() > 180 && c.g() < 70 && c.b() < 70
}
/// Is `c` near black?
fn dark(c: Color32) -> bool {
c.r() < 90 && c.g() < 90 && c.b() < 90
}
/// A style with no fill and no stroke shows its thumbnail on the preview square or on type,
/// outlined in black and filled with white, under a red slash; so does a style whose rows paint
/// None, and one with only effects, whose effects still show. The large preview on the selected
/// object shows the same.
#[test]
fn a_style_with_no_fill_and_no_stroke_shows_an_outlined_shape_and_a_red_slash() {
let app = app();
let d = app.session.active().unwrap().doc.clone();
let image = |app: &VectorcraftApp, g: &GraphicStyle, preview: Preview| render(app, Paints::of(&d), g, preview, 40).unwrap();
let px = |img: &egui::ColorImage, x: usize, y: usize| img.pixels[y * img.size[0] + x];
let empty = GraphicStyle::new("Empty", Appearance::default());
let nones = GraphicStyle::new("Nones", Appearance::basic(Paint::None, Paint::None, 1.0));
for g in [&empty, &nones] {
let img = image(&app, g, Preview::Square);
// The square spans 8.8 to 31.2 pixels: a black edge, white inside, red in the middle.
assert!(red(px(&img, 20, 20)), "{}: {:?}", g.name, px(&img, 20, 20));
assert!((7..=10).any(|x| dark(px(&img, x, 20))), "{}: the left edge is black", g.name);
assert_eq!(px(&img, 13, 13), Color32::WHITE, "{}", g.name);
assert_eq!(px(&img, 2, 2), Color32::WHITE, "{}", g.name);
assert!(!red(px(&img, 13, 13)) && !red(px(&img, 27, 27)));
}
// On type: the slash over the outlined characters.
let img = image(&app, &empty, Preview::Text);
assert!(red(px(&img, 20, 20)));
assert!(img.pixels.iter().any(|c| dark(*c)), "the characters are outlined in black");
// Effects still show: a drop shadow 10 points down and right of the square.
let shadow = vectorcraft_doc::Effect { id: "stylize.dropShadow".into(), params: json!({"x": 10, "y": 10, "blur": 0}), visible: true };
let effects = GraphicStyle::new("Shadow", Appearance { effects: vec![shadow], ..Appearance::default() });
let img = image(&app, &effects, Preview::Square);
assert!(red(px(&img, 20, 20)));
assert_ne!(px(&img, 33, 33), Color32::WHITE, "the shadow shows below the square");
// The large preview on the selected rectangle.
let st = app.session.active().unwrap();
let n = st.doc.node(st.selection.objects[0]).unwrap();
let img = render_object(&app, &st.doc, n, &empty, 60).unwrap();
assert!(red(px(&img, 30, 30)));
assert!(dark(px(&img, 1, 30)), "{:?}", px(&img, 1, 30));
assert_eq!(px(&img, 10, 10), Color32::WHITE);
// A style that paints keeps its own look there, without the slash.
let blue = GraphicStyle::new("Blue", Appearance::basic(Paint::solid(Color::rgb(0.0, 0.0, 1.0)), Paint::None, 1.0));
let img = render_object(&app, &st.doc, n, &blue, 60).unwrap();
assert_eq!(px(&img, 30, 30), Color32::from_rgb(0, 0, 255));
}
/// A style with only a fill, or only a stroke, shows its own paint; a hidden fill or one with
/// zero opacity still counts as a fill, so its thumbnail shows no slash.
#[test]
fn a_fill_or_a_stroke_alone_or_a_hidden_fill_shows_no_slash() {
let app = app();
let d = app.session.active().unwrap().doc.clone();
let image = |g: &GraphicStyle| render(&app, Paints::of(&d), g, Preview::Square, 40).unwrap();
let blue = Paint::solid(Color::rgb(0.0, 0.0, 1.0));
let fill = GraphicStyle::new("Fill", Appearance::basic(blue.clone(), Paint::None, 1.0));
let stroke = GraphicStyle::new("Stroke", Appearance::basic(Paint::None, Paint::solid(Color::rgb(0.0, 0.6, 0.0)), 4.0));
let mut hidden = GraphicStyle::new("Hidden", Appearance::basic(blue.clone(), Paint::None, 1.0));
if let Some(f) = hidden.appearance.fill_mut() {
f.visible = false;
}
let mut clear = GraphicStyle::new("Clear", Appearance::basic(blue, Paint::None, 1.0));
if let Some(f) = clear.appearance.fill_mut() {
f.opacity = 0.0;
}
for g in [&fill, &stroke, &hidden, &clear] {
assert!(!paints_nothing(g), "{}", g.name);
assert!(!image(g).pixels.iter().any(|c| red(*c)), "{} shows no slash", g.name);
}
assert_eq!(image(&fill).pixels[20 * 40 + 20], Color32::from_rgb(0, 0, 255));
assert_eq!(image(&hidden).pixels[20 * 40 + 20], Color32::WHITE);
assert!(image(&stroke).pixels.iter().any(|c| c.g() > 100 && c.r() < 60 && c.b() < 60), "the stroke shows");
}
#[test]
fn merge_asks_for_a_name_and_drops_move_styles_or_make_new_ones() {
let mut app = app();
+1
View File
@@ -1759,6 +1759,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Graphic styles:** styles keep opacity and blend mode, capture groups and type, apply on top with Alt, and link to the objects using them; Redefine, Break Link, Graphic Style Options, Select All Unused, Sort by Name, and Select > Same Graphic Style / Appearance Attribute. The panel has list and thumbnail views with rendered previews, merge, reorder and drag and drop, plus a Control bar Style picker; eleven generated style libraries (including Game HUD, Status Effects, Neon & Glow, Painted and Sketched, whose seven styles each repaint a solid fill with one watercolor, dry brush, pastel, charcoal or ink effect, and Textures) save and load as `.vcstyles`.
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.
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).
- **Load text styles from another document:** the Character Styles and Paragraph Styles panel menus have Load Character Styles… or Load Paragraph Styles… and Load All Styles…, which copy the styles of a document picked in an open dialog, with the swatches and patterns they paint with, in one undo step (`charStyle.load`, `paraStyle.load`, `textStyle.loadAll`); a style the document already has, under its name or a numbered one, is not added again, any other whose name is taken gets a number, and the file's Normal styles are not loaded. Public reference: [Character and paragraph styles](https://web.archive.org/web/20261015081534/https://helpx.adobe.com/illustrator/using/character-paragraph-styles.html).