Write docs for wheel events
This commit is contained in:
1 parent
1bb8b04d87
commit
addb0703b1
2 files changed
+12
No files matched your search
@@ -755,6 +755,7 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WheelData {
|
impl WheelData {
|
||||||
|
/// Construct a new WheelData with the specified wheel movement delta
|
||||||
pub fn new(delta: WheelDelta) -> Self {
|
pub fn new(delta: WheelDelta) -> Self {
|
||||||
let (delta_mode, vector) = match delta {
|
let (delta_mode, vector) = match delta {
|
||||||
WheelDelta::Pixels(v) => (0, v.cast_unit::<UnknownUnit>()),
|
WheelDelta::Pixels(v) => (0, v.cast_unit::<UnknownUnit>()),
|
||||||
@@ -771,6 +772,7 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Construct from the attributes of the web wheel event
|
||||||
pub fn from_web_attributes(
|
pub fn from_web_attributes(
|
||||||
delta_mode: u32,
|
delta_mode: u32,
|
||||||
delta_x: f64,
|
delta_x: f64,
|
||||||
@@ -786,6 +788,7 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The amount of wheel movement
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
pub fn delta(&self) -> WheelDelta {
|
pub fn delta(&self) -> WheelDelta {
|
||||||
let x = self.delta_x;
|
let x = self.delta_x;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ pub type PagesVector = Vector3D<f64, Pages>;
|
|||||||
///
|
///
|
||||||
/// This may be expressed in Pixels, Lines or Pages
|
/// This may be expressed in Pixels, Lines or Pages
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum WheelDelta {
|
pub enum WheelDelta {
|
||||||
/// Movement in Pixels
|
/// Movement in Pixels
|
||||||
Pixels(PixelsVector),
|
Pixels(PixelsVector),
|
||||||
@@ -73,10 +74,18 @@ impl WheelDelta {
|
|||||||
WheelDelta::Pages(PagesVector::new(x, y, z))
|
WheelDelta::Pages(PagesVector::new(x, y, z))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true iff there is no wheel movement
|
||||||
|
///
|
||||||
|
/// i.e. the x, y and z delta is zero (disregards units)
|
||||||
pub fn is_zero(&self) -> bool {
|
pub fn is_zero(&self) -> bool {
|
||||||
self.strip_units() == Vector3D::new(0., 0., 0.)
|
self.strip_units() == Vector3D::new(0., 0., 0.)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A Vector3D proportional to the amount scrolled
|
||||||
|
///
|
||||||
|
/// Note that this disregards the 3 possible units: this could be expressed in terms of pixels, lines, or pages.
|
||||||
|
///
|
||||||
|
/// In most cases, to properly handle scrolling, you should handle all 3 possible enum variants instead of stripping units. Otherwise, if you assume that the units will always be pixels, the user may experience some unexpectedly slow scrolling if their mouse/OS sends values expressed in lines or pages.
|
||||||
pub fn strip_units(&self) -> Vector3D<f64, UnknownUnit> {
|
pub fn strip_units(&self) -> Vector3D<f64, UnknownUnit> {
|
||||||
match self {
|
match self {
|
||||||
WheelDelta::Pixels(v) => v.cast_unit(),
|
WheelDelta::Pixels(v) => v.cast_unit(),
|
||||||
|
|||||||
Reference in new issue
Block a user