Restore hover wheel in Transform fields (#10472) [skip ci]

This commit is contained in:
Codex committed 2026-12-01 17:19:37 +01:00
1 parent 7b5b960f33
commit 7a05781061
2 files changed
+40 -3

No files matched your search

+16 -3
View File
@@ -23,6 +23,7 @@ use craft::ui::menu::PanelRow;
use craft::ui::pickers::{Anchor9, ReferencePointLook};
use craft::ui::popover::Popover;
use craft::ui::runtime::commands::{CommandState, CommandStates};
use craft::ui::runtime::env::{WheelScope, with_env};
use craft::ui::runtime::overlay::CloseReason;
use craft::ui::text::{NumberField, NumberOutput, NumberPick, StepArrows};
use egui::Ui;
@@ -400,7 +401,9 @@ pub(crate) fn object_fields(app: &mut VectorcraftApp, ui: &mut Ui, groups: Trans
let bx = app.selection_box();
let state = bx.as_ref().map(|b| box_state(app, b));
let start = bx.map_or(Rect::ZERO, |b| b.rect);
let out = fields(app, state, start, groups, false).show(ui);
// Match the Transform panel's earlier numeric fields: a wheel started over an unfocused
// field edits it, while the rest of the panel keeps its normal scrolling behavior.
let out = with_env(ui, |set| set.wheel = Some(WheelScope::Free), |ui| fields(app, state, start, groups, false).show(ui));
apply_fields(app, &out, EditPath::Preview, set_object_bounds);
}
@@ -487,7 +490,11 @@ fn artboard_form(app: &mut VectorcraftApp, ui: &mut Ui, index: usize, r: Rect, b
let refi = app.ui.transform_panel.reference_point;
let mut state = BoxState::from_rect(r);
state.pivot = vectorcraft_geom::reference_point(r, refi);
let out = fields(app, Some(state), r, panel_groups(), bar).show(ui);
let out = if bar {
fields(app, Some(state), r, panel_groups(), true).show(ui)
} else {
with_env(ui, |set| set.wheel = Some(WheelScope::Free), |ui| fields(app, Some(state), r, panel_groups(), false).show(ui))
};
apply_fields(app, &out, EditPath::Preview, |app, source, row, intent, live| {
let (w, h) = sides(row);
let p = row.state.pivot;
@@ -537,7 +544,13 @@ pub(crate) fn guide_fields(app: &mut VectorcraftApp, ui: &mut Ui, (x, y): (Optio
for (label, pos, zero, by, vertical) in [("X", x, origin.x, "dx", true), ("Y", y, origin.y, "dy", false)] {
let edit = Field::new(tl!(label))
.enabled(pos.is_some())
.show(ui, |ui, _| NumberField::length(tl!(label), Bind::given(pos.map(|p| p - zero)), lengths).show(ui).edit)
.show(ui, |ui, _| {
with_env(
ui,
|set| set.wheel = Some(WheelScope::Free),
|ui| NumberField::length(tl!(label), Bind::given(pos.map(|p| p - zero)), lengths).show(ui).edit,
)
})
.inner;
let Some(edit) = edit else { continue };
apply_edits(app, &edit, EditPath::Scope, |app, v, _| {
@@ -50,6 +50,30 @@ fn new_app() -> VectorcraftApp {
app
}
/// A wheel over an unfocused position field moves the selected object without a click. A wheel
/// outside the fields leaves its position alone, so the surrounding panel may scroll instead.
#[test]
fn unfocused_position_fields_take_the_wheel_without_owning_the_rest_of_the_panel() {
for (name, horizontal) in [("X position", true), ("Y position", false)] {
let mut app = new_app();
app.run("shape.rectangle", json!({"x": 80, "y": 90, "width": 100, "height": 50})).unwrap();
let mut p = panel(app);
let before = p.app().selection_box().unwrap().rect;
let at = p.rect(name).center();
p.scroll_at(at, 40.0);
let after = p.app().selection_box().unwrap().rect;
if horizontal {
assert_ne!(after.x0, before.x0, "wheel over X moves the object");
assert_eq!(after.y0, before.y0);
} else {
assert_ne!(after.y0, before.y0, "wheel over Y moves the object");
assert_eq!(after.x0, before.x0);
}
p.scroll_at(egui::pos2(290.0, 1000.0), -40.0);
assert_eq!(p.app().selection_box().unwrap().rect, after, "wheel outside the fields leaves the object");
}
}
#[test]
fn use_preview_bounds_shows_the_visual_size_and_checks_the_align_flyout() {
let mut app = new_app();