This commit is contained in:
bflatastic
2026-11-19 01:12:33 +07:00
4 changed files with 353 additions and 1 deletions
+44
View File
@@ -78,6 +78,48 @@ pub fn anchor_buttons(app: &mut VectorcraftApp, ui: &mut Ui, controls: AnchorCon
}
}
/// The selected paths' eligible corners, as document lengths, beside the anchor controls.
/// Explicit partial selections with no corners contribute no target (unlike `picked`'s fallback).
fn corner_radius(app: &mut VectorcraftApp, ui: &mut Ui, t: &Tokens, reserve: f32) {
let Some(st) = app.session.active() else { return };
let mut items = Vec::new();
let mut radius: Option<f64> = None;
let mut mixed = false;
for &id in &st.selection.objects {
let Some(lc) = st.doc.node(id).and_then(vectorcraft_doc::LiveCorners::of) else { continue };
let corners = st.selection.partial(id).map_or_else(|| lc.all(), |anchors| lc.corners_of(anchors));
if corners.is_empty() {
continue;
}
for &k in &corners {
// Keep absolute requested radii, even when their drawing is fitted smaller. Relative
// storage is a fraction, but the field and setLiveShape both consume document lengths.
let value = if lc.radii_relative() { lc.radius(k) * lc.corner(k).map_or(0.0, |c| c.max_radius()) } else { lc.radius(k) };
if let Some(first) = radius {
mixed |= (first - value).abs() >= 1e-9;
} else {
radius = Some(value);
}
}
items.push(json!({"id": id, "corners": corners}));
}
if items.is_empty() {
return;
}
let label = tl!("Corner Radius:");
let text = egui::RichText::new(label).size(12.0).color(t.text);
if ui.available_width() < row_width(ui, &[widgets::text_width(ui, text.clone()), INLINE_FIELD_WIDTH]) + reserve {
return;
}
widgets::field_label(ui, text);
let shown = if mixed { None } else { radius };
let unit = app.session.general_unit();
if let Some(radius) = widgets::num_field_named(ui, "cb-corner-radius", Some(label), shown, unit, INLINE_FIELD_WIDTH) {
// App::run reports any command failure in the status bar, as the other inline fields do.
app.run("object.setLiveShape", json!({"items": items, "radius": radius.max(0.0)})).ok();
}
}
/// The id of the Control bar's isolation button.
pub(super) const ISOLATION_BUTTON: &str = "cb-isolation";
@@ -1035,6 +1077,8 @@ fn contents(app: &mut VectorcraftApp, ui: &mut Ui, t: &Tokens, bar: egui::Rect,
}
if anchors != AnchorControls::None && group_on(app, "anchors") {
anchor_buttons(app, ui, anchors);
let reserve = transform_reserve(app, ui, !sel.is_empty());
corner_radius(app, ui, t, reserve);
}
let object_options = group_on(app, "objectOptions");
if object_options {
+307
View File
@@ -0,0 +1,307 @@
//! Numeric selected-corner radii in the actual Control bar.
// Tests may unwrap/panic (AGENTS.md, Robustness).
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use std::sync::{Mutex, MutexGuard};
use egui::{Event, Rect, vec2};
use serde_json::json;
use vectorcraft_doc::NodeId;
use vectorcraft_engine::Session;
use vectorcraft_ui_egui::{VectorcraftApp, chrome, i18n, panels, theme};
static CASE: Mutex<()> = Mutex::new(());
struct Language {
_lock: MutexGuard<'static, ()>,
previous: i18n::Lang,
}
impl Language {
fn english() -> Self {
let lock = CASE.lock().unwrap_or_else(|e| e.into_inner());
let previous = i18n::current();
i18n::set_current(i18n::Lang::EN);
Self { _lock: lock, previous }
}
}
impl Drop for Language {
fn drop(&mut self) {
i18n::set_current(self.previous);
}
}
fn ordinary_corner() -> (VectorcraftApp, NodeId) {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 500, "height": 400, "profile": null})).unwrap();
// A plain, original Pen-like path, not a live rectangle.
let result = app
.run(
"path.create",
json!({"anchors": [
{"x": 100, "y": 100}, {"x": 220, "y": 100},
{"x": 220, "y": 180}, {"x": 100, "y": 180}
], "closed": true}),
)
.unwrap();
let id = NodeId(result["id"].as_u64().unwrap());
app.select_tool("directSelection");
app.run("select.anchors", json!({"id": id.0, "anchors": [[0, 1]], "mode": "set"})).unwrap();
(app, id)
}
struct Painted {
nodes: Vec<egui::accesskit::Node>,
texts: Vec<(String, Rect)>,
}
impl Painted {
fn radius_field(&self) -> Option<&egui::accesskit::Node> {
self.nodes.iter().find(|node| {
node.role() == egui::accesskit::Role::TextInput && node.label().is_some_and(|name| name.trim_end_matches(':') == "Corner Radius")
})
}
fn has_text(&self, name: &str) -> bool {
self.texts.iter().any(|(text, _)| text == name)
}
}
struct Frames {
ctx: egui::Context,
time: f64,
width: f32,
properties: bool,
}
impl Frames {
fn new(width: f32, properties: bool) -> Self {
let ctx = egui::Context::default();
ctx.enable_accesskit();
theme::install_fonts(&ctx);
theme::apply(&ctx, theme::Brightness::MediumDark);
Self { ctx, time: 0.0, width, properties }
}
fn frame(&mut self, app: &mut VectorcraftApp, events: Vec<Event>) -> Painted {
self.time += 0.05;
let mut output = self.ctx.run_ui(
egui::RawInput {
screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(self.width, 1100.0))),
time: Some(self.time),
focused: true,
events,
..Default::default()
},
|ui| {
if self.properties {
panels::properties::show(app, ui);
} else {
chrome::control_bar(app, ui);
}
},
);
let texts = output
.shapes
.iter()
.filter_map(|clipped| match &clipped.shape {
egui::Shape::Text(text) => Some((text.galley.text().to_owned(), Rect::from_min_size(text.pos, text.galley.size()))),
_ => None,
})
.collect();
let nodes =
output.platform_output.accesskit_update.take().map(|update| update.nodes.into_iter().map(|(_, node)| node).collect()).unwrap_or_default();
output.textures_delta.clear();
Painted { nodes, texts }
}
fn settled(&mut self, app: &mut VectorcraftApp) -> Painted {
self.frame(app, vec![]);
self.frame(app, vec![]);
self.frame(app, vec![])
}
}
#[test]
fn corner_radius_existing_anchor_controls_and_properties_remain_available() {
let _language = Language::english();
let (mut app, _) = ordinary_corner();
let bar = Frames::new(1800.0, false).settled(&mut app);
assert!(bar.has_text("Convert:") && bar.has_text("Anchors:"), "{:?}", bar.texts);
assert!(bar.nodes.iter().any(|node| node.label() == Some("Remove Anchor Points")));
let properties = Frames::new(360.0, true).settled(&mut app);
assert!(properties.has_text("Corner Radius:"), "{:?}", properties.texts);
assert!(properties.texts.iter().any(|(text, _)| text == "0 pt"));
}
#[test]
fn corner_radius_selected_ordinary_corner_has_a_named_control_bar_field() {
let _language = Language::english();
let (mut app, _) = ordinary_corner();
let bar = Frames::new(1800.0, false).settled(&mut app);
assert!(bar.radius_field().is_some(), "no named Corner Radius input in actual Control bar: {:?}", bar.texts);
}
fn node_path(app: &VectorcraftApp, id: NodeId) -> vectorcraft_geom::PathData {
app.session.doc().unwrap().doc.node(id).unwrap().path_data().unwrap().clone()
}
fn corner_state(app: &VectorcraftApp, id: NodeId) -> (vectorcraft_geom::PathData, serde_json::Value, vectorcraft_doc::Selection, usize) {
let state = app.session.doc().unwrap();
let node = state.doc.node(id).unwrap();
(node.path_data().unwrap().clone(), serde_json::to_value(node.live_shape()).unwrap(), state.selection.clone(), state.history.undo.len())
}
fn picked_corner(app: &mut VectorcraftApp, id: NodeId, corner: usize, mode: &str) {
let anchors = {
let node = app.session.doc().unwrap().doc.node(id).unwrap();
vectorcraft_doc::LiveCorners::of(node).unwrap().anchors_of(&std::collections::BTreeSet::from([corner]))
};
app.run("select.anchors", json!({"id": id.0, "anchors": anchors, "mode": mode})).unwrap();
}
fn radius(app: &VectorcraftApp, id: NodeId, corner: usize) -> f64 {
let node = app.session.doc().unwrap().doc.node(id).unwrap();
vectorcraft_doc::LiveCorners::of(node).unwrap().radius(corner)
}
fn field_text(painted: &Painted) -> &str {
painted.radius_field().unwrap().value().unwrap_or_default()
}
fn close(a: f64, b: f64) -> bool {
(a - b).abs() < 1e-8
}
impl Frames {
fn edit_radius(&mut self, app: &mut VectorcraftApp, text: &str) -> Painted {
let painted = self.settled(app);
let bounds = painted.radius_field().unwrap().bounds().unwrap();
let at = egui::pos2(((bounds.x0 + bounds.x1) / 2.0) as f32, ((bounds.y0 + bounds.y1) / 2.0) as f32);
let button = |pressed| Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
self.frame(app, vec![Event::PointerMoved(at), button(true)]);
self.frame(app, vec![button(false)]);
let command =
egui::Modifiers { command: true, ctrl: !cfg!(target_os = "macos"), mac_cmd: cfg!(target_os = "macos"), ..egui::Modifiers::NONE };
let key = |key, pressed, modifiers| Event::Key { key, physical_key: Some(key), pressed, repeat: false, modifiers };
self.frame(app, vec![Event::ModifiersChanged(command), key(egui::Key::A, true, command)]);
self.frame(app, vec![key(egui::Key::A, false, command), Event::ModifiersChanged(egui::Modifiers::NONE), Event::Text(text.into())]);
self.frame(app, vec![key(egui::Key::Enter, true, egui::Modifiers::NONE)]);
self.frame(app, vec![key(egui::Key::Enter, false, egui::Modifiers::NONE)]);
self.settled(app)
}
}
#[test]
fn corner_radius_typing_edits_only_the_selected_corner_and_undo_restores_it() {
let _language = Language::english();
let (mut app, id) = ordinary_corner();
app.run("object.setLiveShape", json!({"id": id.0, "corners": [1], "radius": 160, "kind": "chamfer"})).unwrap();
picked_corner(&mut app, id, 1, "set");
let before = corner_state(&app, id);
let base = {
let node = app.session.doc().unwrap().doc.node(id).unwrap();
let corners = vectorcraft_doc::LiveCorners::of(node).unwrap();
assert!(corners.drawn_radius(1) < corners.radius(1), "the stored request exceeds the fitted radius");
corners.base.clone().into_owned()
};
let mut frames = Frames::new(1800.0, false);
assert_eq!(field_text(&frames.settled(&mut app)), "160 pt", "show requested absolute radius, not fitted size");
frames.edit_radius(&mut app, "6 pt");
let state = app.session.doc().unwrap();
let node = state.doc.node(id).unwrap();
let corners = vectorcraft_doc::LiveCorners::of(node).unwrap();
assert_eq!(&*corners.base, &base, "the uncut outline does not move");
assert!(close(corners.radius(1), 6.0));
assert_eq!(corners.kind(1), vectorcraft_geom::shapes::CornerKind::Chamfer);
for corner in [0, 2, 3] {
assert_eq!(corners.radius(corner), 0.0);
assert_eq!(corners.kind(corner), vectorcraft_geom::shapes::CornerKind::Round);
}
let logical = std::collections::BTreeSet::from([1]);
assert_eq!(state.selection.objects, vec![id]);
assert_eq!(corners.corners_of(state.selection.partial(id).unwrap()), logical);
assert_eq!(state.selection.partial(id).unwrap(), &corners.anchors_of(&logical));
assert_eq!(state.history.undo.len(), before.3 + 1);
app.run("edit.undo", json!({})).unwrap();
assert_eq!(corner_state(&app, id), before);
}
#[test]
fn corner_radius_mixed_targets_resolve_relative_units_and_skip_noncorner_partials() {
let _language = Language::english();
let (mut app, ordinary) = ordinary_corner();
app.run("object.setLiveShape", json!({"id": ordinary.0, "corners": [1], "radius": 6})).unwrap();
let result = app.run("shape.rectangle", json!({"x": 300, "y": 100, "width": 100, "height": 100})).unwrap();
let live = NodeId(result["id"].as_u64().unwrap());
app.run("object.setLiveShape", json!({"id": live.0, "relativeRadii": true, "radius": 10})).unwrap();
let result = app
.run(
"path.create",
json!({"anchors": [
{"x": 300, "y": 250}, {"x": 400, "y": 250},
{"x": 400, "y": 350, "in": [400, 330], "out": [400, 370]},
{"x": 450, "y": 400}
]}),
)
.unwrap();
let excluded = NodeId(result["id"].as_u64().unwrap());
let excluded_before = node_path(&app, excluded);
let noncorners = std::collections::BTreeSet::from([(0, 0), (0, 2)]);
{
let node = app.session.doc().unwrap().doc.node(excluded).unwrap();
let corners = vectorcraft_doc::LiveCorners::of(node).unwrap();
assert!(!corners.all().is_empty(), "this path has another corner that fallback must not edit");
assert!(corners.corners_of(&noncorners).is_empty(), "an endpoint and a smooth anchor are selected");
}
picked_corner(&mut app, ordinary, 1, "set");
picked_corner(&mut app, live, 1, "add");
app.run("select.anchors", json!({"id": excluded.0, "anchors": noncorners, "mode": "add"})).unwrap();
app.run("document.setUnits", json!({"units": "Millimeters"})).unwrap();
let mut frames = Frames::new(1800.0, false);
assert!(field_text(&frames.settled(&mut app)).is_empty(), "6 pt and 10 pt are mixed");
let depth = app.session.doc().unwrap().history.undo.len();
let shown = frames.edit_radius(&mut app, "2 mm");
let expected = 2.0 * 72.0 / 25.4;
assert!(close(radius(&app, ordinary, 1), expected));
assert_eq!(field_text(&shown), app.session.general_unit().format(expected));
let node = app.session.doc().unwrap().doc.node(live).unwrap();
let corners = vectorcraft_doc::LiveCorners::of(node).unwrap();
assert!(corners.radii_relative());
let maximum = corners.corner(1).unwrap().max_radius();
assert!(close(corners.radius(1), expected / maximum));
for corner in [0, 2, 3] {
assert!(close(corners.radius(corner), 0.2));
assert_eq!(radius(&app, ordinary, corner), 0.0);
}
assert_eq!(node_path(&app, excluded), excluded_before);
assert!(app.session.doc().unwrap().doc.node(excluded).unwrap().live_shape().is_none());
assert_eq!(app.session.doc().unwrap().history.undo.len(), depth + 1, "all targets in one edit");
// With only the non-corner partial left, there is no eligible field.
app.run("select.anchors", json!({"id": excluded.0, "anchors": noncorners, "mode": "set"})).unwrap();
assert!(frames.settled(&mut app).radius_field().is_none());
}
#[test]
fn corner_radius_respects_anchor_group_and_narrow_control_bar_space() {
let _language = Language::english();
let (mut app, id) = ordinary_corner();
let mut wide = Frames::new(1800.0, false);
assert!(wide.settled(&mut app).radius_field().is_some());
app.run("window.control.options", json!({"group": "anchors", "visible": false})).unwrap();
let hidden = wide.settled(&mut app);
assert!(hidden.radius_field().is_none());
assert!(!hidden.has_text("Corner Radius:"));
app.run("window.control.options", json!({"group": "anchors", "visible": true})).unwrap();
let narrow = Frames::new(400.0, false).settled(&mut app);
assert!(narrow.radius_field().is_none());
assert!(!narrow.has_text("Corner Radius:"), "the complete label and field are omitted together");
let menu = narrow.nodes.iter().find(|node| node.label() == Some("Panel menu")).unwrap().bounds().unwrap();
for node in narrow.nodes.iter().filter(|node| node.role() == egui::accesskit::Role::TextInput) {
if let Some(bounds) = node.bounds() {
assert!(bounds.x0 >= -0.5 && bounds.x1 <= menu.x0 + 0.5, "numeric control reaches past the panel menu: {bounds:?}");
}
}
app.run("select.set", json!({"ids": [id.0]})).unwrap();
app.select_tool("selection");
assert!(wide.settled(&mut app).radius_field().is_none(), "ordinary whole-path Selection has no anchor controls");
app.select_tool("pen");
assert!(wide.settled(&mut app).radius_field().is_some(), "whole-path anchor-editing tools use all eligible corners");
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -459,6 +459,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
| Select › Start Global Edit / Stop Global Edit; Properties › Quick Actions with the Global Edit Options popover (Match: Appearance, Size; On Artboards: All Artboards or a range, Include Objects On Canvas; Result(s)); Escape stops it; the matched objects are highlighted in their layer colour while it runs; a Shift-click on a highlighted match leaves it out | partial | #3521, `select.globalEdit` / `select.globalEditOptions` / `select.globalEditExclude`, `crates/engine/src/tests/globaledit.rs`; paths, compound paths, symbol instances and groups of them (similar groups, #4939: edits inside one group reach the same object in the others; [public source](https://helpx.adobe.com/illustrator/desktop/manage-objects/edit-objects/edit-groups-with-similar-objects.html)); a group holding type or an image is not taken, as Global Edit does not take images or text; Shift-click to leave a match out ([public source](https://helpx.adobe.com/ph_fil/illustrator/how-to/global-editing-sensei.html)); the Control bar's Global Edit Options dropdown opens the same options; the matches are highlighted before the start (`selecting_one_object_highlights_the_similar_objects_before_global_edit_starts`); rotated copies are matched and take an edit turned by their angle ([public source](https://helpx.adobe.com/vn_vi/illustrator/how-to/modern-logo-design.html); `start_global_edit_takes_rotated_copies_and_an_edit_reaches_each_turned_by_its_angle`); reflected copies are not matched (VectorCraft's own rule) |
| Contextual task bar | done | |
| Control bar with Transform and Stroke popovers | done | |
| Control bar: numeric Corner Radius for eligible selected ordinary and live corners (part of #7238, request 3 only) | done | Anchor Points visibility group; common/mixed values, general document units and multi-object edits through `object.setLiveShape`, one Undo. A partial selection containing no eligible corners contributes no target. Corner kind and relative mode are retained; existing corner-widget selection, widget visibility and maximum-radius behavior are unchanged. Requests 1/2 remain open. |
| Stroke panel: custom arrowheads after the built-in ones in both arrowhead menus, from the arrowheads file that the panel menu's Edit Arrowheads… opens; saving the file reloads the menus, and a stroke keeps a copy of its custom head's art | done | [Apply stroke on an object](https://helpx.adobe.com/illustrator/using/stroke-object.html) (Customize arrowheads); the file's layout (one symbol per head, pointing right, tip at the registration point, height drawn as wide as the built-in heads) is VectorCraft's own; `stroke.arrowheads.edit`, `stroke.arrowheads.list`, `stroke.arrowheads.reload`, `stroke.set` `{custom: name}`; engine `tests::arrowheads`, `stroke::tests_arrows::custom_heads_draw_their_own_art_at_the_tip` |
| Control bar: Paragraph: link and Align left/center/right while type is selected (#5372) | done | After the Character controls, as the public documentation has the Control panel format paragraphs ([Paragraph panel overview](https://helpx.adobe.com/illustrator/using/formatting-paragraphs.html), [Align text](https://helpx.adobe.com/illustrator/using/align-text.html)); the link opens the Paragraph panel in a popover, as Character: does with the Character panel. The bar trims from its right end: X/Y/W/H, Distribute, Align, area type vertical alignment, then these buttons, then the link. The three-button set is our choice for room; all seven alignments are in the popover. `panels/paragraph/tests.rs` headless tests (`the_control_bar_shows_the_paragraph_alignment_of_the_selected_type`, `the_control_bar_trims_its_paragraph_section_after_the_controls_to_its_right`) |
| Pathfinder shape results keep their source names and SVG IDs | done | #1293; Minus Front keeps the back name, Minus Back the front name; Unite/Intersect/Exclude use the backmost named input; compound output carries it once; geometry and paint unchanged |