Co-authored-by: AhmetV <344941595+ahmetv10@users.noreply.github.com>
This commit is contained in:
@@ -410,6 +410,17 @@ pub fn locked_value(app: &SolveApp, t: &Tool, label: &str) -> Option<f64> {
|
||||
locked(app, t, label)
|
||||
}
|
||||
|
||||
/// Give the keyboard back to the box it was in, after a click in another panel took it (#2927).
|
||||
/// The box that owned the keyboard is still the one that had it last frame; the active tool must
|
||||
/// still show its boxes, so a finished or restarted shape is left alone.
|
||||
pub fn restore_box_focus(app: &SolveApp, ctx: &egui::Context) {
|
||||
let Some(count) = app.tool.as_ref().map(|t| t.dims.len()) else { return };
|
||||
let holder = ctx.memory(|memory| (0..count).map(|i| egui::Id::new(("sc_dim", i))).find(|id| memory.had_focus_last_frame(*id)));
|
||||
if let Some(id) = holder {
|
||||
ctx.memory_mut(|memory| memory.request_focus(id));
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the boxes of the active tool next to what they measure. Enter places the point.
|
||||
pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, proj: &Proj) {
|
||||
// Esc in a box ends the shape (the box had the keyboard, so the shortcut didn't see it).
|
||||
|
||||
@@ -412,6 +412,27 @@ fn a_midpoint_line_takes_a_typed_length_and_angle() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A click on a line type in the palette switches the drawing mode; it must not take the keyboard
|
||||
/// away from the dimension box of the shape being drawn (#2927).
|
||||
#[test]
|
||||
fn a_palette_linetype_click_leaves_the_dimension_box_focused() {
|
||||
let mut h = drawing("sketch.rectangle.two_point");
|
||||
type_value(&mut h, "30");
|
||||
assert_focus(&h, 0);
|
||||
let at = h.widget("construction").expect("the palette's construction button");
|
||||
h.call("ui.click", json!({"x": at[0], "y": at[1]}));
|
||||
h.settle();
|
||||
assert_focus(&h, 0);
|
||||
// The keyboard still reaches the box: typing keeps editing the dimension (a locked box keeps
|
||||
// its caret, so the text is appended), and Tab still moves to the next box.
|
||||
h.step(&json!({"text": "4"})).unwrap();
|
||||
assert_focus(&h, 0);
|
||||
assert_eq!(h.app.tool.as_ref().unwrap().dims[0].value, "304");
|
||||
tab(&mut h, false);
|
||||
assert_focus(&h, 1);
|
||||
assert_eq!(crate::sketch_palette::mode(&h.app), 1, "the click still switched the drawing line type");
|
||||
}
|
||||
|
||||
/// A value box set off the cursor stays in the drawing area (#2201): past an edge it goes to the
|
||||
/// cursor's other side, still clear of it; with no room either side it is pushed inside.
|
||||
#[test]
|
||||
|
||||
@@ -512,6 +512,8 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
} else {
|
||||
set_mode(app, kind);
|
||||
}
|
||||
// The button click would otherwise leave the shape's dimension box without the keyboard.
|
||||
crate::sketch_dims::restore_box_focus(app, ctx);
|
||||
}
|
||||
if construction {
|
||||
toggle_construction(app);
|
||||
|
||||
Reference in New Issue
Block a user