Task bar: the basic shape tools show Edit Path, Fill, Stroke and Shape Properties

While the Rectangle, Rounded Rectangle, Ellipse, Polygon or Star tool has
one closed path selected whole, as right after it draws one, the
contextual task bar shows Edit Path, the Fill and Stroke chips, and
Shape Properties for a live rectangle, rounded rectangle, ellipse or
polygon. The help page lists these items for the five tools:
https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/contextual-task-bar-overview.html

With nothing selected, several objects, a group, an open path, type or
picked-out anchors, those tools show no bar. The selection tools'
Duplicate, Offset Path, Simplify, Recolor Artwork and Lock are left out.
A star, drawn as a plain path, gets no Shape Properties. Gen Shape Fill
and Generate Vectors are not added.
This commit is contained in:
dotCooCoo
2026-11-14 17:24:43 -08:00
parent 895e9493d2
commit dfcdff91df
3 changed files with 201 additions and 15 deletions
+48 -13
View File
@@ -55,6 +55,26 @@ fn selection_tool_with_selection(app: &VectorcraftApp) -> bool {
&& app.session.active().is_some_and(|st| !st.selection.is_empty())
}
/// The basic shape tools whose Contextual Task Bar shows Edit Path, Fill, Stroke and the selected
/// shape's properties. The Line Segment tool is not one of them.
const SHAPE_TOOLS: [&str; 5] = ["rectangle", "roundedRectangle", "ellipse", "polygon", "star"];
/// Whether a basic shape tool is in use with one closed path selected whole, as each of those tools
/// leaves the shape it draws.
fn shape_tool_on_shape(app: &VectorcraftApp) -> bool {
SHAPE_TOOLS.contains(&app.session.tool_id())
&& app.session.active().is_some_and(|st| {
st.selection.objects.len() == 1
&& st.selection.anchors.is_empty()
&& st
.selection
.objects
.first()
.and_then(|id| st.doc.node(*id))
.is_some_and(|n| matches!(&n.kind, NodeKind::Path { path, .. } if path.is_closed()))
})
}
/// Whether the bar shows its blank canvas actions, Draw (Pencil) and Place Image: a selection tool is
/// in use and the active document has no artwork, only layers and guides.
fn blank_canvas(app: &VectorcraftApp) -> bool {
@@ -107,7 +127,11 @@ pub(crate) fn task_bar_shows_type(app: &VectorcraftApp) -> bool {
/// With the Artboard tool it sits under the selected artboards and offers Resize (Artboard
/// Options), Duplicate, Rearrange All (with two or more artboards) and Export (Export for Screens).
/// A basic shape selected with the Selection tool shows a Shape Properties button in place of Lock.
/// Selected type also shows the font family, font style and Font Size controls before its Fill.
/// While a basic shape tool (Rectangle, Rounded Rectangle, Ellipse, Polygon or Star) has one closed
/// path selected, as after it draws one, the bar offers Edit Path, Fill and Stroke, and Shape
/// Properties for a live rectangle, rounded rectangle, ellipse or polygon; with nothing selected, or
/// any other selection, those tools show no bar. Selected type also shows the font family, font
/// style and Font Size controls before its Fill.
/// While a Type tool edits type, or has type selected, the bar shows only those controls and the
/// Fill. When one row would be wider than the canvas, the font controls take a row of their own,
/// narrowed to fit it, and the actions wrap onto rows under the handle's ([`bar_layout`]).
@@ -123,7 +147,10 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
let typing = type_tool_on_type(app);
// A blank canvas offers Draw (Pencil) and Place Image, as the same help page describes.
let blank = !on_artboards && blank_canvas(app);
if !(on_artboards || typing || blank || selection_tool_with_selection(app)) {
// A basic shape tool with its shape selected offers Edit Path, Fill, Stroke and the shape's
// properties, as the same help page describes.
let shaping = shape_tool_on_shape(app);
if !(on_artboards || typing || blank || shaping || selection_tool_with_selection(app)) {
return;
}
// Selected type has the font controls too, as the help page describes
@@ -153,20 +180,22 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
f.name.as_deref() == Some("Image Trace") && f.children().is_some_and(|c| c.first().is_some_and(|i| matches!(i.kind, NodeKind::Image(_))))
});
// A basic shape (a live rectangle, rounded rectangle, ellipse or polygon) selected whole with the
// Selection tool: its properties take the place of Lock, as in the reference app
// (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/contextual-task-bar-overview.html>).
// Selection tool or a basic shape tool: its properties take the place of Lock, as the help page
// describes (<https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/contextual-task-bar-overview.html>).
use vectorcraft_doc::LiveShape;
let shape = first
.filter(|f| {
n == 1
&& st.selection.anchors.is_empty()
&& app.session.tool_id() == "selection"
&& (app.session.tool_id() == "selection" || shaping)
&& matches!(&f.kind, NodeKind::Path { live: Some(l), .. }
if matches!(**l, LiveShape::Rectangle { .. } | LiveShape::Ellipse { .. } | LiveShape::Polygon { .. }))
})
.cloned();
let mut items: Vec<(&str, &str, &str, serde_json::Value)> = vec![]; // (label, icon, command, params)
let none = || json!({});
// Edit Path: the Direct Selection tool, to edit the path's anchors.
let edit_path = || (tl!("Edit Path"), "dc-direct", "tool.select", json!({"tool": "directSelection"}));
if on_artboards {
// As in the reference app, the Artboard tool offers to resize, duplicate and export the
// artboards (<https://community.adobe.com/questions-652/contextual-task-bar-in-illustrator-2025-quick-actions-when-you-need-them-1546580>),
@@ -181,11 +210,12 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
// Draw (Pencil) switches to the Pencil tool; Place Image picks files for the Place dialog.
items.push((tl!("Draw (Pencil)"), "pencil", "tool.select", json!({"tool": "pencil"})));
items.push((tl!("Place Image"), "image", "file.place", none()));
} else if shaping {
// A basic shape tool's one action; its Fill, Stroke and Shape Properties follow as chips.
items.push(edit_path());
} else if !typing {
// The selection tools' object actions. A Type tool's bar leaves them out, Create Outlines
// and the type conversions included.
// Edit Path: the Direct Selection tool, to edit the path's anchors.
let edit_path = || (tl!("Edit Path"), "dc-direct", "tool.select", json!({"tool": "directSelection"}));
// As in the reference app, an image offers Image Trace, Crop Image and Remove Background, and
// traced art offers Expand (<https://community.adobe.com/announcements-651/contextual-task-bar-in-illustrator-2025-quick-actions-when-you-need-them-1546580>,
// <https://community.adobe.com/announcements-651/ai-powered-image-editing-features-in-illustrator-1624061>).
@@ -288,13 +318,18 @@ pub(super) fn task_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) {
let fonts = fonts && room >= crate::panels::character::task_bar_min_room();
// The selected objects' Fill, Stroke, Recolor Artwork (when they have colours to recolour) and
// Lock (a basic shape's properties instead), left out with the Artboard tool and on a blank
// canvas, which have no selected objects. A Type tool's bar has the Fill alone.
// canvas, which have no selected objects. A Type tool's bar has the Fill alone. A basic shape
// tool's bar has the Fill, the Stroke and a live shape's Shape Properties.
let objects = !on_artboards && !blank;
let chips: Vec<Chip> =
[(objects, Chip::Fill), (objects && !typing, Chip::Stroke), (objects && !typing && colored, Chip::Recolor), (objects && !typing, Chip::Lock)]
.into_iter()
.filter_map(|(shown, chip)| shown.then_some(chip))
.collect();
let chips: Vec<Chip> = [
(objects, Chip::Fill),
(objects && !typing, Chip::Stroke),
(objects && !typing && !shaping && colored, Chip::Recolor),
(objects && !typing && (!shaping || shape.is_some()), Chip::Lock),
]
.into_iter()
.filter_map(|(shown, chip)| shown.then_some(chip))
.collect();
let widths: Vec<f32> = items.iter().map(|(label, _, cmd, _)| if icon_only(cmd) { BAR_MORE } else { action_width(ui, label) }).collect();
let font_w = fonts.then(|| {
let w = crate::panels::character::TASK_BAR_WIDTHS;
+151 -1
View File
@@ -1,7 +1,8 @@
//! The Contextual Task Bar's actions for each kind of selection: open paths offer Join and Edit
//! Path, compound paths and clipping masks their Release, images selected with vector art Make
//! Clipping Mask, type converts between point and area type, type on a path opens its options, and
//! a basic shape shows its properties in place of Lock. Type, and the Type tools while they edit it,
//! a basic shape shows its properties in place of Lock. The basic shape tools show Edit Path, Fill,
//! Stroke and Shape Properties for the shape they draw. Type, and the Type tools while they edit it,
//! show the font family, font style and Font Size controls.
use egui::{Event, PointerButton, Pos2, Rect, vec2};
@@ -571,6 +572,155 @@ fn other_selections_keep_lock() {
}
}
/// The basic shape tools: the tool ids, and the Shape Properties heading each tool's shape shows
/// (none for the star, a plain path).
const SHAPE_TOOLS: [(&str, Option<&str>); 5] = [
("rectangle", Some("Rectangle Properties:")),
("roundedRectangle", Some("Rectangle Properties:")),
("ellipse", Some("Ellipse Properties:")),
("polygon", Some("Polygon Properties:")),
("star", None),
];
/// Draw with `tool` by dragging across the canvas from the document point `from` to `to`, and return
/// whether the task bar showed partway through the drag.
fn drag_with(app: &mut VectorcraftApp, tool: &str, from: (f64, f64), to: (f64, f64)) -> bool {
app.run("tool.select", json!({ "tool": tool })).unwrap();
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
frame(app, &ctx, vec![]);
frame(app, &ctx, vec![]);
let xf = canvas::Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
let (a, b) = (xf.to_screen(vectorcraft_geom::Point::new(from.0, from.1)), xf.to_screen(vectorcraft_geom::Point::new(to.0, to.1)));
let press = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Default::default() };
frame(app, &ctx, vec![Event::PointerMoved(a), press(a, true)]);
frame(app, &ctx, vec![Event::PointerMoved(a + (b - a) / 2.0)]);
frame(app, &ctx, vec![Event::PointerMoved(b)]);
let shown_mid_drag = canvas::task_bar_rect(&ctx).is_some();
frame(app, &ctx, vec![press(b, false)]);
frame(app, &ctx, vec![]);
shown_mid_drag
}
fn names(named: &[(String, Rect)]) -> Vec<&str> {
named.iter().map(|(n, _)| n.as_str()).collect()
}
/// Each basic shape tool, just after it draws a shape, shows Edit Path, Fill and Stroke for it, and
/// Shape Properties for a live rectangle, rounded rectangle, ellipse or polygon. The bar leaves out
/// the selection tools' Duplicate, Offset Path, Simplify, Recolor Artwork and Lock, and shows
/// nothing during the drag that draws the shape.
#[test]
fn shape_tools_show_edit_path_paint_and_properties_after_drawing() {
let mut app = app();
for (i, (tool, heading)) in SHAPE_TOOLS.into_iter().enumerate() {
let x = 30.0 + 70.0 * i as f64;
let shown_mid_drag = drag_with(&mut app, tool, (x, 60.0), (x + 50.0, 120.0));
assert!(!shown_mid_drag, "{tool}: no bar while the shape is dragged out");
assert_eq!(app.session.tool_id(), tool);
let st = app.session.active().unwrap();
assert_eq!(st.selection.objects.len(), 1, "{tool} drew and selected a shape");
let shape = st.selection.objects[0].0;
let (_, named) = buttons(&mut app);
let names = names(&named);
for name in ["Edit Path", "Fill", "Stroke", "More Options"] {
assert!(names.contains(&name), "{tool}: {name} in {names:?}");
}
assert_eq!(names.contains(&"Shape Properties"), heading.is_some(), "{tool}: {names:?}");
for name in ["Duplicate", "Offset Path", "Simplify", "Recolor Artwork", "Lock (⌘2)"] {
assert!(!names.contains(&name), "{tool}: {name} is left out of {names:?}");
}
if let Some(heading) = heading {
let (_, texts) = click_lock_slot(&mut app);
assert!(has(&texts, heading), "{tool}: {heading} in {texts:?}");
assert!(!locked(&app, shape), "{tool}: the button doesn't lock the shape");
}
}
}
/// With a basic shape tool in use, the bar shows only for one closed path selected whole: not with
/// nothing selected, several objects, a group, an open path, type or picked-out anchors. The Line
/// Segment tool shows no bar for a selected rectangle.
#[test]
fn shape_tools_have_no_shape_bar_without_a_single_shape() {
let mut app = app();
let a = id(app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 30, "height": 30})).unwrap());
let b = id(app.run("shape.ellipse", json!({"x": 60, "y": 20, "width": 30, "height": 30})).unwrap());
let c = id(app.run("shape.rectangle", json!({"x": 20, "y": 250, "width": 30, "height": 30})).unwrap());
let d = id(app.run("shape.rectangle", json!({"x": 60, "y": 250, "width": 30, "height": 30})).unwrap());
select(&mut app, &[c, d]);
let group = id(app.run("object.group", json!({})).unwrap());
let line = id(app.run("shape.line", json!({"x1": 150, "y1": 50, "x2": 300, "y2": 120})).unwrap());
let text = id(app.run("text.create", json!({"x": 150, "y": 200, "text": "Type"})).unwrap());
let cases: [(&str, Vec<u64>); 5] =
[("nothing", vec![]), ("several", vec![a, b]), ("a group", vec![group]), ("an open path", vec![line]), ("type", vec![text])];
for (tool, _) in SHAPE_TOOLS {
app.run("tool.select", json!({ "tool": tool })).unwrap();
for (what, ids) in &cases {
select(&mut app, ids);
let (ctx, _) = bar(&mut app);
assert!(canvas::task_bar_rect(&ctx).is_none(), "{tool} with {what}: no bar");
}
app.run("select.anchors", json!({"id": a, "anchors": [[0, 1]]})).unwrap();
let (ctx, _) = bar(&mut app);
assert!(canvas::task_bar_rect(&ctx).is_none(), "{tool} with anchors: no bar");
select(&mut app, &[a]);
let (ctx, _) = bar(&mut app);
assert!(canvas::task_bar_rect(&ctx).is_some(), "{tool} with the rectangle: the bar");
}
app.run("tool.select", json!({"tool": "lineSegment"})).unwrap();
select(&mut app, &[a]);
let (ctx, _) = bar(&mut app);
assert!(canvas::task_bar_rect(&ctx).is_none(), "the Line Segment tool: no bar");
}
/// A basic shape tool's bar follows the selection: Shape Properties shows the shape drawn last,
/// edits it with Undo restoring it, and after an Undo of the drawing shows the shape selected
/// then. Fill makes the Fill active, Stroke the Stroke, and Edit Path switches to the Direct
/// Selection tool.
#[test]
fn shape_tool_bar_retargets_after_another_shape_and_undo() {
let mut app = app();
app.run("tool.select", json!({"tool": "ellipse"})).unwrap();
let rect = id(app.run("shape.rectangle", json!({"x": 40, "y": 40, "width": 80, "height": 60, "radius": 10})).unwrap());
let (ctx, texts) = click_lock_slot(&mut app);
assert!(has(&texts, "Rectangle Properties:"), "{texts:?}");
type_into(&mut app, &ctx, &texts, "10 pt", "20");
let corners = |app: &VectorcraftApp| match live(app, rect) {
vectorcraft_doc::LiveShape::Rectangle { radii, .. } => radii,
l => panic!("{l:?}"),
};
assert_eq!(corners(&app), [20.0; 4]);
app.run("edit.undo", json!({})).unwrap();
assert_eq!(corners(&app), [10.0; 4]);
let ellipse = id(app.run("shape.ellipse", json!({"x": 200, "y": 40, "width": 80, "height": 60})).unwrap());
let (_, texts) = click_lock_slot(&mut app);
assert!(has(&texts, "Ellipse Properties:") && !has(&texts, "Rectangle Properties:"), "{texts:?}");
app.run("edit.undo", json!({})).unwrap();
assert!(app.session.active().unwrap().doc.node(NodeId(ellipse)).is_none(), "the ellipse is undone");
let selected: Vec<u64> = app.session.active().unwrap().selection.objects.iter().map(|i| i.0).collect();
let (ctx, texts) = bar(&mut app);
assert!(!has(&texts, "Ellipse Properties:"), "{texts:?}");
if selected == [rect] {
assert!(canvas::task_bar_rect(&ctx).is_some(), "the rectangle selected again: the bar");
} else {
assert!(canvas::task_bar_rect(&ctx).is_none(), "{selected:?}: no bar");
select(&mut app, &[rect]);
}
let (_, texts) = click_lock_slot(&mut app);
assert!(has(&texts, "Rectangle Properties:"), "{texts:?}");
app.session.fill_active = false;
click_button(&mut app, "Fill");
assert!(app.session.fill_active, "Fill makes the Fill active");
click_button(&mut app, "Stroke");
assert!(!app.session.fill_active, "Stroke makes the Stroke active");
assert_eq!(app.session.tool_id(), "ellipse");
click_button(&mut app, "Edit Path");
assert_eq!(app.session.tool_id(), "directSelection");
}
/// A compound path under the Direct Selection tool isn't offered Edit Path, which would only switch
/// to the tool already in use; the Selection tool still offers it.
#[test]