From 71f6cf47ae44c76ad55a135c48c38663ac43c0f5 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 30 Nov 2026 00:32:55 +0100 Subject: [PATCH 1/3] Cover numeric scrub with a nondecimal point rate --- crates/ui-widgets/tests/it/text/number.rs | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/ui-widgets/tests/it/text/number.rs b/crates/ui-widgets/tests/it/text/number.rs index 32f1ce0f45..668a35d193 100644 --- a/crates/ui-widgets/tests/it/text/number.rs +++ b/crates/ui-widgets/tests/it/text/number.rs @@ -860,6 +860,38 @@ fn a_slider_fields_scrub_keeps_the_steps_decimals_where_the_field_shows_fewer() assert_ne!(dragged, dragged.round(), "the value keeps the step's hundredth, not a whole number"); } +/// A per-point drag rate changes the distance, not the written precision of the field's value. +#[trial] +fn a_slider_fields_scrub_rate_does_not_set_its_value_precision() { + use craft_ui::form::SliderField; + use craft_ui::testing::Fixture; + use craft_ui::value_drag::{DragModifier, DragModifiers}; + use std::rc::Rc; + + let drag = |modifiers: Modifiers, distance: f32| { + let value = Rc::new(Cell::new(0.0_f64)); + let held = Rc::clone(&value); + let mut fixture = Fixture::new(move |ui| { + let mut now = held.get(); + SliderField::new("Exposure", Bind::bound(&mut now), -5.0..=5.0) + .step(0.01) + .scrub_step(10.0 / 257.0) + .pointer_modifiers(DragModifiers::new(Some(DragModifier::Shift), None)) + .show(ui); + held.set(now); + }); + fixture.settle(); + let (_, field, _) = slider_number(&fixture); + fixture.hold(modifiers).drag_at(field.center(), Vec2::new(distance, 0.0)).settle(); + value.get() + }; + let plain = drag(Modifiers::NONE, 40.0); + let fine = drag(Modifiers::SHIFT, 40.0); + assert!((plain - 1.56).abs() < 1e-9, "the per-point rate moves the plain drag to 1.56: {plain}"); + assert!((fine - 0.16).abs() < 1e-9, "Shift uses a tenth of the rate, rounded to the field's hundredths: {fine}"); + assert_eq!(drag(Modifiers::NONE, -250.0), -5.0, "the drag still clamps at the range end"); +} + /// A percent field whose committed values carry no decimals (`commit_decimals(0)`, a paint bar's Opacity) shows none, /// "10%"; one that sets no decimals of its own keeps the one-decimal look, "10.0%". #[trial] From 81836e654456e07593ee2b5f2334abaf54188b76 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 30 Nov 2026 01:32:19 +0100 Subject: [PATCH 2/3] Round number scrubs to the field step, not drag speed --- crates/ui-widgets/src/text/number.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-widgets/src/text/number.rs b/crates/ui-widgets/src/text/number.rs index f0c4a7b811..01e9c740c6 100644 --- a/crates/ui-widgets/src/text/number.rs +++ b/crates/ui-widgets/src/text/number.rs @@ -886,7 +886,7 @@ impl Component for NumberField<'_, V> { // float noise and keeps the step's precision even where the field shows fewer decimals: a field of hundredths // that shows no decimals still moves by a hundredth, not by nothing. The step is not a grid here: an Alt drag // moves by a share of it. - let decimals = self.decimals().max(decimals_for_step(step)); + let decimals = self.decimals().max(decimals_for_step(rule.step)); let scale = self.scale; // The rounded value is kept in the range after the rounding: a drag that runs into a range end finer than the // decimals it rounds to carries the value past it (0.005 to 0.01), and the range holds the write at its end, From 60a7e651c773670bf1ba710d58325ec6a88ce172 Mon Sep 17 00:00:00 2001 From: skylartaylor Date: Mon, 30 Nov 2026 01:35:57 +0100 Subject: [PATCH 3/3] Use the two-decimal codec in the scrub regression --- crates/ui-widgets/tests/it/text/number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ui-widgets/tests/it/text/number.rs b/crates/ui-widgets/tests/it/text/number.rs index 668a35d193..aa1b1363d2 100644 --- a/crates/ui-widgets/tests/it/text/number.rs +++ b/crates/ui-widgets/tests/it/text/number.rs @@ -863,6 +863,7 @@ fn a_slider_fields_scrub_keeps_the_steps_decimals_where_the_field_shows_fewer() /// A per-point drag rate changes the distance, not the written precision of the field's value. #[trial] fn a_slider_fields_scrub_rate_does_not_set_its_value_precision() { + use craft_behavior::{NumberCodec, Reader}; use craft_ui::form::SliderField; use craft_ui::testing::Fixture; use craft_ui::value_drag::{DragModifier, DragModifiers}; @@ -875,6 +876,7 @@ fn a_slider_fields_scrub_rate_does_not_set_its_value_precision() { let mut now = held.get(); SliderField::new("Exposure", Bind::bound(&mut now), -5.0..=5.0) .step(0.01) + .number_codec(NumberCodec::new(Reader::new(), 2)) .scrub_step(10.0 / 257.0) .pointer_modifiers(DragModifiers::new(Some(DragModifier::Shift), None)) .show(ui);