Merge pull request #10839 from dotCooCoo/fix/selection-tool-anchor-size

Selection: anchor points draw at 4 pt under the Selection tool again
This commit is contained in:
.CooCoo
2026-12-04 08:54:52 -08:00
committed by GitHub
3 changed files with 35 additions and 9 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ const BADGE_OFFSET: Vec2 = Vec2::new(14.0, 14.0);
/// on the canvas of `space`. The extras lie under the tool's own marks.
pub(super) fn show(app: &VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSpace, overlays: &[Overlay], extra: &[Overlay]) {
let rect = space.view.rect;
let options = super::selection::path_options(&app.session.prefs);
let options = super::selection::path_options(&app.session.prefs, app.session.tool_id());
let quiet = tool_adapter::in_gesture(app, ui.ctx()) || tool_adapter::view_tool_held(app);
let lists = [extra, overlays];
// Only the overlays that are controls get a child `Ui`: a list of 10,000 path marks makes none.
+11 -6
View File
@@ -30,8 +30,11 @@ use super::outline::{ViewHides, c32, linked_crosses, node_outline, selection_hit
use super::{BodyKind, VectorcraftApp, Win};
// PLAN: `anchors` takes `tool_points` because the Curvature tool's own points come from `session.overlays`, which only `show` may call (`&mut app`).
/// The anchor square's side at Selection & Anchor Display › Size 3, the default, in points.
/// The anchor square's side at Selection & Anchor Display › Size 3, the default, in points, under a tool that edits
/// anchors ([`vectorcraft_tools::catalog::edits_anchors`]).
const ANCHOR_AT_DEFAULT_SIZE: f32 = 5.0;
/// How many points smaller the anchor squares are under a tool that does not edit anchors, such as the Selection tool.
const SELECTING_ANCHOR_SHRINK: f32 = 1.0;
/// The default of Selection & Anchor Display › Size.
const DEFAULT_SIZE: u32 = 3;
/// How many points bigger than the other selected anchors the key anchor's square is drawn.
@@ -129,12 +132,14 @@ pub(super) fn outline_revision(paths: &[BezPath], key: Option<&BezPath>, extra:
hasher.finish()
}
/// The Path Options the anchors layer draws with: Selection & Anchor Display › Size (1–7, one point per step) and
/// Handles. One builder, so every overlay reads the preference the same way.
/// The Path Options the anchors layer draws with under `tool`: Selection & Anchor Display › Size (1–7, one point per
/// step) and Handles. Anchors are [`SELECTING_ANCHOR_SHRINK`] smaller under a tool that does not edit anchors. One
/// builder, so every overlay reads the preference the same way.
#[allow(clippy::field_reassign_with_default)] // `PathOptionsSettings` is non-exhaustive: no struct literal outside its crate
pub(super) fn path_options(prefs: &Prefs) -> PathOptionsSettings {
pub(super) fn path_options(prefs: &Prefs, tool: &str) -> PathOptionsSettings {
let mut options = PathOptionsSettings::default();
options.anchor_size = Some(ANCHOR_AT_DEFAULT_SIZE + grow(prefs));
let shrink = if vectorcraft_tools::catalog::edits_anchors(tool) { 0.0 } else { SELECTING_ANCHOR_SHRINK };
options.anchor_size = Some(ANCHOR_AT_DEFAULT_SIZE - shrink + grow(prefs));
options.handles = match prefs.handle_style.as_str() {
"hollow" => HandleStyle::Hollow,
"large" => HandleStyle::Large,
@@ -282,7 +287,7 @@ pub(super) fn anchors(app: &VectorcraftApp, st: &DocState, tool: &str, tool_poin
shown: if curvature { AnchorsShown::Curvature } else { AnchorsShown::All },
handles: if prefs.show_handles_multiple_anchors { HandlesShown::Selected } else { HandlesShown::OneAnchor },
segment_mark: SegmentMark::Line,
options: path_options(prefs),
options: path_options(prefs, tool),
};
if hidden(app) || too_big(app, st) || (curvature && tool_points) {
return out;
+23 -2
View File
@@ -119,10 +119,11 @@ fn no_stale_marks_after_a_change(tool: &str) {
// The display preferences.
app.session.active_mut().unwrap().selection.segments.clear();
let at_default = marks(&app).options.anchor_size.unwrap();
app.session.prefs.anchor_size = 6;
app.session.prefs.handle_style = "hollow".into();
let options = marks(&app).options;
assert_eq!((options.anchor_size, options.handles), (Some(8.0), HandleStyle::Hollow));
assert_eq!((options.anchor_size, options.handles), (Some(at_default + 3.0), HandleStyle::Hollow), "Size 6 is three points up");
app.session.prefs.show_handles_multiple_anchors = false;
assert_eq!(marks(&app).handles, HandlesShown::OneAnchor);
app.session.prefs.show_handles_multiple_anchors = true;
@@ -875,7 +876,8 @@ fn curvature_marks_existing_paths_as_circles_and_leaves_a_drafts_points_to_the_t
#[test]
fn anchor_size_scales_anchors_and_handles() {
let options = |size: u32, style: &str| path_options(&Prefs { anchor_size: size, handle_style: style.into(), ..Default::default() });
let options =
|size: u32, style: &str| path_options(&Prefs { anchor_size: size, handle_style: style.into(), ..Default::default() }, "directSelection");
assert_eq!(options(3, "solid").anchor_size, Some(ANCHOR_AT_DEFAULT_SIZE));
let large = options(7, "large");
assert_eq!((large.anchor_size, large.handles), (Some(ANCHOR_AT_DEFAULT_SIZE + 4.0), HandleStyle::Large));
@@ -883,6 +885,25 @@ fn anchor_size_scales_anchors_and_handles() {
assert_eq!(options(3, "solid").handles, HandleStyle::Solid);
}
/// Anchors are a point smaller under the selection tools that move objects than under the tools that edit anchors,
/// at every Size.
#[test]
fn anchors_are_smaller_under_the_selection_tool_than_under_the_tools_that_edit_them() {
let (mut app, _) = scene();
let mut size_under = |tool: &str| {
app.select_tool(tool);
assert!(!shown_paths(&marks(&app)).is_empty(), "{tool} shows the selection's anchors");
marks(&app).options.anchor_size.unwrap()
};
let (selection, group, direct, pen) = (size_under("selection"), size_under("groupSelection"), size_under("directSelection"), size_under("pen"));
assert_eq!(direct, ANCHOR_AT_DEFAULT_SIZE);
assert_eq!(pen, direct, "the Pen tool draws anchors as Direct Selection does");
assert_eq!(selection, direct - SELECTING_ANCHOR_SHRINK);
assert_eq!(group, selection, "Group Selection moves objects as the Selection tool does");
let largest = |tool: &str| path_options(&Prefs { anchor_size: 7, ..Default::default() }, tool).anchor_size.unwrap();
assert_eq!(largest("directSelection") - largest("selection"), SELECTING_ANCHOR_SHRINK, "Size grows both alike");
}
/// The revision is of the drawn outline: the same paths and colour give one value, other paths or another colour do not.
#[test]
fn the_outline_revision_follows_what_is_drawn() {