pub enum ScrollDelta {
PageDelta(f32, f32),
LineDelta(f32, f32),
PixelDelta(PhysicalPosition<f64>),
}Expand description
Scroll delta.
Deltas are in a Y-down coordinate system, and represent a ‘navigation’ direction; a positive Y value means that the viewport should move downward relative to the content.
For mouse wheel events, only LineDelta and PixelDelta are typical.
For scroll deltas generated by scrollbars or other elements, PageDelta
may be used (for example, when clicking in the well of the scrollbar).
Variants§
PageDelta(f32, f32)
Page delta.
Page deltas are almost always synthetic, typically generated by clicking in the well of a scrollbar.
LineDelta(f32, f32)
Line delta.
PixelDelta(PhysicalPosition<f64>)
Pixel delta.
Implementations§
Source§impl ScrollDelta
impl ScrollDelta
Sourcepub fn to_pixel_delta(
self,
line_px: PhysicalPosition<f64>,
page_px: PhysicalPosition<f64>,
) -> PhysicalPosition<f64>
pub fn to_pixel_delta( self, line_px: PhysicalPosition<f64>, page_px: PhysicalPosition<f64>, ) -> PhysicalPosition<f64>
Convert this scroll delta into a pixel delta using caller-provided scaling.
This is a policy hook: the caller chooses what a “line” or “page” means in pixels.
§Example (physical pixel policy)
Convert line deltas into a pixel delta by choosing a line size in physical pixels:
use dpi::PhysicalPosition;
use ui_events::ScrollDelta;
let delta = ScrollDelta::LineDelta(0.0, -3.0);
// Policy: 1 line = 40 physical px vertically.
let line_px = PhysicalPosition { x: 0.0, y: 40.0 };
// Policy: 1 page = 800 physical px vertically (e.g. viewport height).
let page_px = PhysicalPosition { x: 0.0, y: 800.0 };
let px = delta.to_pixel_delta(line_px, page_px);
assert_eq!(px, PhysicalPosition { x: 0.0, y: -120.0 });§Scale factor and logical units
If your policy is expressed in logical/CSS pixels, apply your scale factor
(device pixel ratio) before calling to_pixel_delta:
use dpi::PhysicalPosition;
use ui_events::ScrollDelta;
let delta = ScrollDelta::LineDelta(0.0, 1.0);
let dpr = 2.0; // from your platform/window
// Policy: 1 line = 16 CSS px vertically.
let line_px = PhysicalPosition { x: 0.0, y: 16.0 * dpr };
// Policy: 1 page = 800 physical px vertically.
let page_px = PhysicalPosition { x: 0.0, y: 800.0 };
let _px = delta.to_pixel_delta(line_px, page_px);ScrollDelta::PixelDeltais returned unchanged.ScrollDelta::LineDeltais multiplied byline_pxper axis.ScrollDelta::PageDeltais multiplied bypage_pxper axis.
Sourcepub fn into_pixel_delta(
self,
line_px: PhysicalPosition<f64>,
page_px: PhysicalPosition<f64>,
) -> Self
pub fn into_pixel_delta( self, line_px: PhysicalPosition<f64>, page_px: PhysicalPosition<f64>, ) -> Self
Convert this scroll delta into ScrollDelta::PixelDelta using caller-provided scaling.
Trait Implementations§
Source§impl Clone for ScrollDelta
impl Clone for ScrollDelta
Source§fn clone(&self) -> ScrollDelta
fn clone(&self) -> ScrollDelta
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more