Sketch Dimension: click an existing dimension to edit it while the tool is on (#5451)
With Sketch Dimension on and nothing picked yet, a click on a dimension that is already in the sketch opens its value box, the same in-place editor a double-click opens without a tool. Enter applies, Esc cancels, and the tool stays on for the next dimension. The dimension's text always takes the click; its lines only away from sketch points and curves, which still start a new dimension (the rule plain selection uses). Once a new dimension is under way, clicks keep their meaning. Dimensions off in the selection filter are left alone. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
//! `solidcraft_sketch::dim_layout`.
|
||||
//!
|
||||
//! A click selects a dimension (Delete removes it), a drag moves its text (and so the offset of
|
||||
//! its dimension line), a double-click edits its value in place with parameter completion.
|
||||
//! its dimension line), a double-click (or one click with the Dimension tool) edits its value
|
||||
//! in place with parameter completion.
|
||||
//! Everything acts through commands: `sketch.dimension_text`, `sketch.delete`,
|
||||
//! `parameters.change`.
|
||||
|
||||
@@ -383,10 +384,19 @@ pub fn text_rects() -> Vec<(String, Rect)> {
|
||||
|
||||
/// A double-click on a dimension opens its value for editing (true: it was on one).
|
||||
pub fn double_click(app: &mut SolveApp, pos: Pos2) -> bool {
|
||||
let Some(d) = DRAWN.with(|d| {
|
||||
let id = hit(pos)?;
|
||||
d.borrow().iter().find(|x| x.id == id).cloned()
|
||||
}) else {
|
||||
open_editor(app, hit(pos))
|
||||
}
|
||||
|
||||
/// A click of the Dimension tool on an existing dimension opens its value for editing, as a
|
||||
/// double-click does without a tool (true: it was on one). Its text wins; its lines only off
|
||||
/// sketch geometry (`on_geometry`), which the click picks for a new dimension instead.
|
||||
pub fn tool_click(app: &mut SolveApp, pos: Pos2, on_geometry: bool) -> bool {
|
||||
open_editor(app, hit_text(pos).or_else(|| if on_geometry { None } else { hit(pos) }))
|
||||
}
|
||||
|
||||
/// Open the inline editor on the drawn dimension `id` (true: there was one to act on).
|
||||
fn open_editor(app: &mut SolveApp, id: Option<String>) -> bool {
|
||||
let Some(d) = id.and_then(|id| DRAWN.with(|d| d.borrow().iter().find(|x| x.id == id).cloned())) else {
|
||||
return false;
|
||||
};
|
||||
let Some(param) = d.param else {
|
||||
|
||||
@@ -151,6 +151,46 @@ fn double_clicking_another_dimension_inserts_its_name_once() {
|
||||
crate::dim_view::cancel();
|
||||
}
|
||||
|
||||
/// With the Dimension tool on, one click on an existing dimension edits its value, as a
|
||||
/// double-click does without a tool. The tool stays on, and geometry still starts a new one.
|
||||
#[test]
|
||||
fn dimension_tool_click_on_an_existing_dimension_edits_its_value() {
|
||||
let mut h = line([20., 0.]);
|
||||
h.app.run("sketch.dimension", json!({"entities":["l1"],"value":20,"text_at":[10,8]})).unwrap();
|
||||
let created = h.app.run("sketch.line", json!({"points":[[0,-10],[12,-10]],"infer":false})).unwrap();
|
||||
let second = created["created"]["curves"][0].as_str().unwrap().to_string();
|
||||
h.settle();
|
||||
h.step(&json!({"start":"sketch.dimension"})).unwrap();
|
||||
h.step(&json!({"click":{"dimension":"d1"}})).unwrap();
|
||||
assert!(crate::dim_view::editing(), "a click on the dimension opens its value");
|
||||
h.frames(5);
|
||||
assert_eq!(h.ctx.memory(|m| m.focused()), Some(egui::Id::new("sc_dim_edit")), "the value field takes the keyboard");
|
||||
type_value(&mut h, "25");
|
||||
h.step(&json!({"key":"Enter"})).unwrap();
|
||||
assert!(!crate::dim_view::editing(), "{}", h.call("ui.inspect", json!({})));
|
||||
assert!((h.app.session.doc.eval("d1", solidcraft_engine::doc::expr::Kind::Length).unwrap() - 25.).abs() < 1e-6);
|
||||
assert_eq!(h.app.session.doc.next_d_name(), "d2", "no new dimension was made");
|
||||
assert_eq!(h.app.tool.as_ref().map(|t| t.cmd), Some("sketch.dimension"), "the tool stays on");
|
||||
// A click on geometry still picks it for a new dimension.
|
||||
h.frames(40);
|
||||
h.step(&json!({"click":{"world":[6,-10,0]}})).unwrap();
|
||||
assert_eq!(h.app.tool.as_ref().map(|t| t.picks.clone()), Some(vec![second]));
|
||||
crate::dim_view::cancel();
|
||||
}
|
||||
|
||||
/// With dimensions off in the selection filter, the Dimension tool leaves them alone.
|
||||
#[test]
|
||||
fn dimension_tool_click_respects_the_selection_filter() {
|
||||
let mut h = line([20., 0.]);
|
||||
h.app.run("sketch.dimension", json!({"entities":["l1"],"value":20,"text_at":[10,8]})).unwrap();
|
||||
h.app.ui.pick_off.push("dimensions".into());
|
||||
h.settle();
|
||||
h.step(&json!({"start":"sketch.dimension"})).unwrap();
|
||||
h.step(&json!({"click":{"dimension":"d1"}})).unwrap();
|
||||
assert!(!crate::dim_view::editing(), "a filtered-out dimension opened for editing");
|
||||
crate::dim_view::cancel();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dimension_parameters_use_typing_and_ctrl_space_completion() {
|
||||
for (prefix, expected) in [("wid", "width"), ("", "width"), ("d", "d1")] {
|
||||
|
||||
@@ -147,7 +147,9 @@ pub fn hint(id: &str) -> String {
|
||||
"sketch.circle.center" => "Circle: click the centre, then a point on the circle".into(),
|
||||
"sketch.arc.three_point" => "Arc: click start, end, then a point on the arc".into(),
|
||||
"sketch.arc.center_point" => "Arc: click centre and start, then click end or type a signed sweep".into(),
|
||||
"sketch.dimension" => "Dimension: pick one or two entities and type the value (or click to place it first); Enter applies".into(),
|
||||
"sketch.dimension" => {
|
||||
"Dimension: pick one or two entities and type the value (or click to place it first); click a dimension to edit it; Enter applies".into()
|
||||
}
|
||||
"sketch.constraint.horizontal_vertical" => "Horizontal/Vertical: pick a line or two points; hold Shift to pick a line midpoint".into(),
|
||||
"sketch.slot.center_to_center" | "sketch.slot.overall" => "Slot: click both ends, then the width".into(),
|
||||
"sketch.constraint.midpoint" => "MidPoint: pick a point and a line, or two lines to centre the second on the first".into(),
|
||||
@@ -316,6 +318,16 @@ pub fn on_click(app: &mut SolveApp, proj: &Proj, pos: Pos2, shift: bool) {
|
||||
})
|
||||
});
|
||||
let fresh = |tool: &Tool, id: &String| !tool.picks.contains(id) && tool.picks.len() < 2;
|
||||
// Before a new dimension is under way, a click on an existing one edits its value;
|
||||
// the tool stays on for the next dimension.
|
||||
if crate::dim_view::live().is_none()
|
||||
&& tool.picks.is_empty()
|
||||
&& !app.ui.pick_off.iter().any(|k| k == "dimensions")
|
||||
&& crate::dim_view::tool_click(app, pos, hit.is_some())
|
||||
{
|
||||
app.tool = Some(tool);
|
||||
return;
|
||||
}
|
||||
if let Some(typed) = crate::dim_view::live() {
|
||||
match hit {
|
||||
// Before anything is typed, another entity joins the dimension, as in the
|
||||
|
||||
@@ -214,6 +214,11 @@ text there and keeps the value box focused; a click on another point or line mak
|
||||
dimension a distance or angle instead; Tab leaves the picks waiting for a click to place the
|
||||
text.
|
||||
|
||||
To change a dimension you already have, double-click it, or, with Sketch Dimension on and
|
||||
nothing picked yet, click it once: its value box opens with the value selected, Enter applies,
|
||||
and the tool stays on for the next dimension. The dimension's text always takes the click; its
|
||||
lines take it only away from sketch points and curves, which still start a new dimension.
|
||||
|
||||
Between two points, or on a line, that don't line up with an axis, where you place the
|
||||
dimension picks what it measures: across from them, the distance between them; above or below
|
||||
them, the horizontal distance; beside them, the vertical distance.
|
||||
|
||||
Reference in New Issue
Block a user