Skip to main content

egui_charts/config/
kinetic.rs

1//! Kinetic (inertial) scroll animation parameters.
2//!
3//! When enabled, releasing a scroll/drag gesture causes the chart to continue
4//! scrolling with decaying velocity, giving a "momentum" feel similar to
5//! mobile OS list scrolling.
6
7/// Kinetic scroll animation parameters.
8#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
9pub struct KineticScrollOptions {
10    /// Continue scrolling after a horizontal touch drag is released
11    /// Default: false (chart stops immediately on release)
12    pub enabled: bool,
13
14    /// Continue scrolling after a mouse drag is released, independently of `enabled`
15    /// Default: false
16    #[serde(default)]
17    pub mouse: bool,
18
19    /// Min scroll speed (pixels/frame)
20    /// Default: 0.2
21    pub min_scroll_speed: f32,
22
23    /// Max scroll speed (pixels/frame)
24    /// Default: 7.0
25    pub max_scroll_speed: f32,
26
27    /// Damping coefficient: the share of scroll velocity kept per frame.
28    /// Accepts finite values in `0.0..1.0` (zero stops immediately, one is excluded).
29    /// Invalid values are replaced by the default when chart options are applied.
30    /// Default: 0.997 (~99.7% of speed retained each frame)
31    pub damping_coeff: f32,
32
33    /// Min pixels moved to trigger kinetic scroll
34    /// Default: 15.0
35    pub scroll_min_move: f32,
36}
37
38impl Default for KineticScrollOptions {
39    fn default() -> Self {
40        Self {
41            enabled: false, // Disabled by default (no inertial scrolling)
42            mouse: false,
43            min_scroll_speed: 0.2,
44            max_scroll_speed: 7.0,
45            damping_coeff: 0.997,
46            scroll_min_move: 15.0,
47        }
48    }
49}