Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #1064

bflatastic3ba3120637dd
diff --cc crates/ui-egui/src/widgets.rs
index d9bae36ec,cd86d5f38..b715b1c79
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@@ -635,53 -626,20 +636,58 @@@ mod tests
#[test]
fn wheel_steps_accumulate_small_movements_and_preserve_direction() {
+ // one mouse-wheel notch is one step, whatever a notch scrolls
+ let notch = crate::theme::WHEEL_LINE_POINTS;
let mut remainder = 0.0;
- assert_eq!(wheel_nudges(&mut remainder, 15.0), 0.0);
- assert_eq!(wheel_nudges(&mut remainder, 25.0), 1.0);
+ assert_eq!(wheel_nudges(&mut remainder, notch * 0.375), 0.0);
+ assert_eq!(wheel_nudges(&mut remainder, notch * 0.625), 1.0);
assert_eq!(remainder, 0.0);
- assert_eq!(wheel_nudges(&mut remainder, -100.0), -2.0);
- assert_eq!(wheel_nudges(&mut remainder, -20.0), -1.0);
+ assert_eq!(wheel_nudges(&mut remainder, -notch * 2.5), -2.0);
+ assert_eq!(wheel_nudges(&mut remainder, -notch * 0.5), -1.0);
assert_eq!(remainder, 0.0);
+ assert_eq!(wheel_nudges(&mut remainder, notch), 1.0, "a single notch is a single nudge");
+ assert_eq!(remainder, 0.0);
+ assert_eq!(wheel_nudges(&mut remainder, notch * 50.0), 10.0, "a single huge event is capped");
}
+ /// Shift-drag moves a tenth of the pointer's way along the track, also on the Kelvin track (where a pixel of
+ /// fine drag near the centre is about 4 K): a pointer creeping a pixel a frame still adds up to steps.
+ #[test]
+ fn a_slow_shift_drag_adds_up() {
+ let ctx = egui::Context::default();
+ let temp = lightcraft_develop::controls::find("wb.temp").unwrap();
+ let mut value = 7000.0;
+ let frame = |time: f64, events: Vec<egui::Event>, value: f64| {
+ let input = egui::RawInput {
+ screen_rect: Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(320.0, 120.0))),
+ time: Some(time),
+ events,
+ ..Default::default()
+ };
+ let mut out = SliderOut::default();
+ ctx.run_ui(input, |ui| out = slider(ui, temp, value, true, None)).textures_delta.clear();
+ let track = take_registry(&ctx).into_iter().find(|(id, _)| id == "slider:wb.temp").unwrap().1;
+ (out, track)
+ };
+ // Shift is held from the start (the modifiers stay until they change)
+ let (_, track) = frame(0.0, vec![egui::Event::ModifiersChanged(egui::Modifiers::SHIFT)], value);
+ let mut at = pos2(track.left() + temp.position(value) as f32 * track.width(), track.center().y);
+ let press =
+ |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::SHIFT };
+ frame(0.1, vec![egui::Event::PointerMoved(at), press(at, true)], value);
+ let moves = 60;
+ for i in 0..moves {
+ at.x += 1.0;
+ let (out, _) = frame(0.2 + f64::from(i) * 0.02, vec![egui::Event::PointerMoved(at)], value);
+ value = out.value.unwrap_or(value);
+ }
+ frame(2.0, vec![press(at, false)], value);
+ // the drag starts once the pointer has moved a few pixels; every pixel after that counts
+ let lo = temp.value_at(temp.position(7000.0) + f64::from(moves - 10) / f64::from(track.width()) * 0.1);
+ let hi = temp.value_at(temp.position(7000.0) + f64::from(moves) / f64::from(track.width()) * 0.1);
+ assert!(value >= lo - 50.0 && value <= hi + 50.0 && value > 7000.0, "{value} K, expected {lo:.0}–{hi:.0} K");
+ }
+
/// Typed values (issue #322): signs, a decimal comma, units; on the control's steps, in range.
#[test]
fn typed_values_are_stepped_and_clamped() {