Place the selection widgets over the canvas, so a frame runs its UI once

SelectionWidgets was laid out in the canvas body's flow, which the layout
check found changed in every frame the canvas drew: the frame was discarded
and its whole UI ran a second time. It is placed over the canvas's rect, as
the other canvas controls are.
This commit is contained in:
bflatastic
2026-11-24 21:08:43 +07:00
parent 34173f4e5b
commit ad9e45e7d3
2 changed files with 22 additions and 1 deletions
@@ -550,7 +550,7 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp
let id = super::canvas_id(win).with("selection_widget_drag");
let mut held: Option<Held> = ui.data(|d| d.get_temp::<Option<Held>>(id)).flatten();
end_hidden(app, &mut held, &layout);
let out = SelectionWidgets::new(layout).show(ui);
let out = SelectionWidgets::new(layout).show_at(ui, space.view.rect);
for (widget, press) in out.presses {
if !press.phase.start().is_some_and(|s| s.button == PointerButton::Primary) {
continue;
+21
View File
@@ -86,6 +86,27 @@ fn a_discarded_rerun_runs_a_duplicate_once() {
assert_eq!(undo(&app), before_undo + 1, "one undo step");
}
/// While the selection moves every frame, as in a drag, each frame runs its UI once: the canvas's overlays are placed
/// over the canvas and keep the layout its measuring run recorded, so no frame is discarded and run again.
#[test]
fn a_moving_selection_runs_each_frame_once() {
let mut app = app();
let ctx = crate::testing::ui_context();
for _ in 0..3 {
run_frame(&mut app, &ctx, vec![], |_| {}, false);
}
let frames = 8;
let passes: usize = (0..frames)
.map(|_| {
let step = |app: &mut VectorcraftApp| {
app.session.execute("object.move", &json!({"dx": 2, "dy": 1})).unwrap();
};
run_frame(&mut app, &ctx, vec![], step, false).0
})
.sum();
assert_eq!(passes, frames, "{passes} passes for {frames} frames");
}
/// One frame with an optional command applied between the tick and the draw (as a control request drained by `tick`
/// does); returns the IME descriptor of the last pass.
fn ime_frame(