mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 10:48:15 +01:00
Merge pull request #4375
This commit is contained in:
commit
fc56018cb6
2 files changed
+35
-1
No files matched your search
@@ -886,7 +886,7 @@ impl<V: NumberValue + 'static> 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,
|
||||
|
||||
@@ -860,6 +860,40 @@ 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_behavior::{NumberCodec, Reader};
|
||||
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)
|
||||
.number_codec(NumberCodec::new(Reader::new(), 2))
|
||||
.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]
|
||||
|
||||
Reference in new issue
Block a user