feat(properties): turn a selected line into a fill from Shape properties

The button at the top of a shape's properties runs modify.lines_to_fills.
A fill with no line leaves the button unavailable, so a click changes nothing.

Co-authored-by: Neel Patel <N-NeelPatel@users.noreply.github.com>
This commit is contained in:
Cursor AgentandNeel Patel committed 2026-11-21 20:13:15 +00:00
1 parent dde812c923
commit dd3daba35a
4 files changed
+116 -1

No files matched your search

+4
View File
@@ -3,3 +3,7 @@
Own-feature messages describe which symbol types support filters and blending without the comparative phrase “as in Animate”. Matching comments and explanatory prose use the same direct descriptions.
File-format interoperability references and required trademark/non-affiliation notices remain intact. Regression tests prevent the retired comparative phrase from returning to production display strings. No version, release workflow, release-stage setting or release hold is changed.
## Shape properties, lines to fills (2026-11-21)
Issue #530 asks for a properties button that turns a selected stroke into a fill. The reference app labels that button "Expand to Fill". That name is not used here. It is another product's name for this action, it is not in the shared names list, and it was not cleared: no register search is treated as a finding that the name is free (unclear means no). The button uses the label this command already has, **Convert Lines to Fills** (`modify.lines_to_fills`, Modify › Shape).
+3
View File
@@ -402,6 +402,9 @@ a few curves, not hundreds of points. In merged drawing the new fill joins the d
merges with a fill of the same colour that it touches and cuts into others, as any fill does.
A drawing object keeps its own fill and gets the outline as a second object above it.
The same action is a button at the top of a shape's properties. With no line selected
the button is unavailable, and a fill on its own stays as it is.
**Expand Fill…** moves the edge of each selected fill out or in by a **Distance** in pixels.
**Expand** grows the fill and rounds its corners, as if you had drawn round it with a round
brush; **Inset** shrinks it and keeps the corners sharp. Holes get smaller as the fill grows,
+1 -1
View File
@@ -147,7 +147,7 @@ not this table, says what matters most.
| Transform: rotate 90°, flip, remove transform, scale and rotate by numbers | **done** | |
| Envelope | **done** | [ADR 0080](adr/0080-drawing-parity-leftovers.md). Shapes and drawing objects only. |
| Distort | **missing** | P-020. |
| Modify › Shape: Convert Lines to Fills, Expand Fill, Soften Fill Edges | **done** | [ADR 0109](adr/0109-shape-commands-picker-eyedropper-and-transformation-origins.md). |
| Modify › Shape: Convert Lines to Fills, Expand Fill, Soften Fill Edges | **done** | [ADR 0109](adr/0109-shape-commands-picker-eyedropper-and-transformation-origins.md). Properties repeats Convert Lines to Fills at the top of a shape's rows; with only a fill selected the button is unavailable. |
| Modify › Shape: Smooth, Straighten, Advanced Smooth, Optimize | **missing** | P-020 ([#510](https://github.com/storytold/anicraft/issues/510)). |
| Stroke styles: solid, dashed, dotted; caps, joins, miter | **done** | [ADR 0046](adr/0046-stroke-caps-joins-and-dashes.md). |
| Stroke styles: ragged, stipple, hatched | **missing** in authoring | They import from Animate files as solid lines and the report says so† (P-032). |
+108
View File
@@ -1096,6 +1096,13 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E
ui.label(text(Type::Caption, tr!("Posed by its bone: drag it with the Selection tool. Colour effect, blending and filters apply on every pose of the armature.")));
return;
}
// At the top of a shape's properties (#530): the same command as Modify › Shape ›
// Convert Lines to Fills. A selection with no line leaves the button unavailable, so a
// click changes nothing and says nothing.
if matches!(e.kind, ElementKind::Shape(_)) {
lines_to_fills_button(app, ui);
ui.add_space(4.0);
}
if let ElementKind::Symbol { symbol, events, .. } = &e.kind
&& app.s.doc.symbol(*symbol).is_some_and(|x| x.kind != SymbolKind::Graphic)
{
@@ -1441,6 +1448,27 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E
}
}
/// Convert Lines to Fills, drawn at the top of a shape's properties (#530). It dispatches
/// `modify.lines_to_fills`. With no line selected the button is unavailable: a click does not
/// run the command, so a fill on its own stays as it is and no error is reported.
fn lines_to_fills_button(app: &mut App, ui: &mut egui::Ui) {
let has_line = app.s.selected_elements().iter().any(|(_, el)| matches!(&el.kind, ElementKind::Shape(sh) if sh.stroke.is_some()));
let label = anicraft_engine::find_command("modify.lines_to_fills").map(|c| crate::i18n::t_cmd(c.id, c.label)).unwrap_or_else(|| tr!("Convert Lines to Fills"));
let resp = ui.add_enabled(has_line, egui::Button::new(label));
let resp = if has_line {
resp.on_hover_text(tr!("Turns each selected line into a fill of its outline, in the line's colour, and keeps a fill the shape already has"))
} else {
resp.on_disabled_hover_text(tr!("Select a line to turn it into a fill. A fill on its own stays as it is"))
};
if has_line
&& resp.clicked()
&& let Some(v) = app.run("modify.lines_to_fills", json!({}))
{
let n = v["converted"].as_u64().unwrap_or(1);
app.status_ok(trn!("Turned {n} line into a fill. {undo} to undo.", "Turned {n} lines into fills. {undo} to undo.", n, undo = app.undo_key()));
}
}
/// The bitmap a placed bitmap or bitmap fill shows, with Swap Bitmap (ADR 0053): another
/// Library bitmap in its place, for every selected bitmap.
fn bitmap_row(app: &mut App, ui: &mut egui::Ui, current: anicraft_engine::doc::BitmapId, differs: bool) {
@@ -3957,4 +3985,84 @@ mod tests {
let t = transform(&app);
assert!((t.m[0] - 1.0).abs() < 1e-4 && (t.m[3] - m.m[3]).abs() < 1e-3, "still mirrored as dragged: {t:?}");
}
/// #530: the button at the top of a shape's properties turns a selected line into a fill
/// of that line, and leaves a fill that has no line as it is (no error, no undo step).
#[test]
fn the_shape_properties_button_turns_a_line_into_a_fill_and_leaves_a_fill_alone() {
use egui::accesskit::{Action, ActionRequest, Node, Role, TreeId};
use egui::{Event, Modifiers};
let ctx = egui::Context::default();
ctx.enable_accesskit();
let mut app = App::with_context(&ctx, Session::default(), Some(std::path::PathBuf::from("unused.png")));
let input = |events: Vec<Event>| egui::RawInput {
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1600.0, 1200.0))),
events,
..Default::default()
};
let frame = |ctx: &egui::Context, app: &mut App, extra: Vec<Event>| -> Vec<(egui::accesskit::NodeId, Node)> {
let mut events = vec![Event::ModifiersChanged(Modifiers::NONE)];
events.extend(extra);
let mut out = ctx.run_ui(input(events), |ui| app.frame(ui));
out.textures_delta.clear();
out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default()
};
let settle = |ctx: &egui::Context, app: &mut App| {
let mut nodes = Vec::new();
for _ in 0..4 {
nodes = frame(ctx, app, Vec::new());
}
nodes
};
let button = |nodes: &[(egui::accesskit::NodeId, Node)]| {
nodes.iter().find(|(_, n)| n.role() == Role::Button && n.label() == Some("Convert Lines to Fills")).map(|(id, n)| {
(*id, n.is_disabled(), n.supports_action(Action::Click) && n.supports_action(Action::Focus))
})
};
// The first shape's stroke, fill, and the size of its path on the stage.
let measured = |app: &App| {
let shown = app.s.visible_elements();
let e = shown.iter().find(|e| matches!(e.kind, ElementKind::Shape(_))).expect("a shape");
match &e.kind {
ElementKind::Shape(sh) => {
let b = sh.path.bounds().transformed(&e.transform);
(sh.stroke.is_some(), sh.fill.is_some(), b.width(), b.height())
}
_ => (false, false, 0.0, 0.0),
}
};
app.run("draw.line", json!({"x0": 40.0, "y0": 80.0, "x1": 240.0, "y1": 80.0, "stroke": "#112233", "stroke_width": 8, "cap": "none"})).expect("a line");
let nodes = settle(&ctx, &mut app);
let (id, disabled, pressable) = button(&nodes).expect("a shape's properties offer Convert Lines to Fills");
assert!(!disabled, "a selected line can be turned into a fill");
assert!(pressable, "reachable from the keyboard");
let (had_stroke, had_fill, w0, h0) = measured(&app);
assert!(had_stroke && !had_fill && h0 < w0, "a line, wider than it is tall: {w0} by {h0}");
let steps = app.s.history().undo_len();
let press = Event::AccessKitActionRequest(ActionRequest { action: Action::Click, target_tree: TreeId::ROOT, target_node: id, data: None });
frame(&ctx, &mut app, vec![press]);
settle(&ctx, &mut app);
let (stroke, fill, w1, h1) = measured(&app);
assert!(!stroke && fill, "the line is a fill");
assert!(h1 > h0 && w1 + 0.5 >= w0, "the fill covers a band around the line: {w0}×{h0} → {w1}×{h1}");
assert_eq!(app.s.history().undo_len(), steps + 1, "one undo step");
assert!(app.status.as_ref().is_some_and(|s| !s.error && s.text.contains("fill")), "the change is announced: {:?}", app.status.as_ref().map(|s| s.text.clone()));
// A fill on its own: the button stays, unavailable, and pressing it changes nothing.
app.run("edit.delete", json!({})).expect("removed");
app.run("draw.rect", json!({"x": 30.0, "y": 40.0, "w": 80.0, "h": 50.0, "fill": "#cc3333", "stroke": null})).expect("a fill");
let nodes = settle(&ctx, &mut app);
let (id, disabled, _) = button(&nodes).expect("a fill's properties still offer the button");
assert!(disabled, "a fill with no line cannot run it");
let doc = app.s.doc.clone();
let steps = app.s.history().undo_len();
let press = Event::AccessKitActionRequest(ActionRequest { action: Action::Click, target_tree: TreeId::ROOT, target_node: id, data: None });
frame(&ctx, &mut app, vec![press]);
settle(&ctx, &mut app);
assert_eq!(app.s.doc, doc, "the fill is unchanged");
assert_eq!(app.s.history().undo_len(), steps, "no undo step");
assert!(!app.status.as_ref().is_some_and(|s| s.error), "a fill is not reported as an error: {:?}", app.status.as_ref().map(|s| s.text.clone()));
}
}