use eframe::egui; pub fn drag_value_with_scroll( ui: &mut egui::Ui, value: &mut T, range: std::ops::RangeInclusive, speed_drag: f64, speed_scroll: f64, ) -> egui::Response where T: egui::emath::Numeric + std::ops::Add + std::fmt::Debug { let drag = egui::DragValue::new(value) .speed(speed_drag) .range(range.clone()); let response = ui.add(drag); if response.hovered() { let scroll_diff = ui.input(|i| i.smooth_scroll_delta.y); const THRESHOLD: f32 = 10.0; if scroll_diff > THRESHOLD { *value = clamp_partial(*value + T::from_f64(speed_scroll), *range.start(), *range.end()); } else if scroll_diff < -THRESHOLD { *value = clamp_partial(*value + T::from_f64(-speed_scroll), *range.start(), *range.end()); } } response } // literally why is this not given in the emath::Numeric definition fn clamp_partial(val: T, min: T, max: T) -> T { if val < min { min } else if val > max { max } else { val } }