Merge pull request #10237 from dotCooCoo/fix/number-field-wheel-under-pointer

Fields: the wheel steps a focused number field only while the pointer is over it
This commit is contained in:
FredApps authored and GitHub committed 2026-11-30 15:32:50 +01:00
commit af3c5abece
2 files changed
+43

No files matched your search

+3
View File
@@ -830,6 +830,9 @@ pub(crate) fn root_env(prefs: &vectorcraft_engine::Prefs, native_ppp: f32, print
root.escape_leaves_fields = true;
// A held key repeats its command (Cmd+= keeps zooming in).
root.shortcuts_repeat = true;
// The wheel steps a focused number field only while the pointer is over it; elsewhere it scrolls what is under the
// pointer.
root.pointer_scoped_field_wheel = true;
root
}
@@ -309,4 +309,44 @@ mod tests {
assert_eq!(panel.value("Name").as_deref(), Some("Dots"));
assert!(panel.app().session.active().unwrap().doc.pattern("Dots").is_some());
}
/// The tile's width and height of the pattern "Dots".
fn tile_size(panel: &Panel) -> (f64, f64) {
let app = panel.app();
let tile = &app.session.active().unwrap().doc.pattern("Dots").unwrap().tile;
(tile.width(), tile.height())
}
/// With the Width field focused, a wheel notch steps it only while the pointer is over it: over another control,
/// or over the unfocused Height field, the wheel scrolls the panel and the tile keeps its size.
#[test]
fn the_wheel_steps_the_focused_number_field_only_under_the_pointer() {
use craft::ui::contract::Role;
let mut panel = editing_panel();
panel.room(egui::vec2(220.0, 320.0));
panel.frame();
assert_eq!(tile_size(&panel), (10.0, 10.0));
panel.click_role("Width", Role::SPIN_BUTTON);
assert!(panel.focused("Width"), "the click focuses Width");
// One notch at `at`, then the frame after the wheel gesture's gap, which ends the gesture.
let notch = |panel: &mut Panel, at: egui::Pos2| {
panel.scroll_at(at, -30.0);
panel.advance(1.0);
panel.frame();
};
let check = panel.rect("Size Tile to Art").center();
notch(&mut panel, check);
assert_eq!(tile_size(&panel), (10.0, 10.0), "a notch over Size Tile to Art leaves the focused Width alone");
assert!(panel.focused("Width"), "Width keeps the focus");
let height = panel.rect_role("Height", Role::SPIN_BUTTON).center();
notch(&mut panel, height);
assert_eq!(tile_size(&panel), (10.0, 10.0), "a notch over the unfocused Height steps neither field");
let width = panel.rect_role("Width", Role::SPIN_BUTTON).center();
notch(&mut panel, width);
assert_eq!(tile_size(&panel), (9.0, 10.0), "a notch over the focused Width steps it");
}
}