diff options
author | 2020-04-30 07:38:46 +0200 | |
---|---|---|
committer | 2020-04-30 07:38:46 +0200 | |
commit | d4c4198f7242f168de65146e0ca339e0c1cbfe9b (patch) | |
tree | 89ba3fb312c65264593720586df7e55726550e21 /wgpu/src/widget/canvas/cursor.rs | |
parent | 1501a93915b3704a1d57da4c390a8ebca4e35c8b (diff) | |
download | iced-d4c4198f7242f168de65146e0ca339e0c1cbfe9b.tar.gz iced-d4c4198f7242f168de65146e0ca339e0c1cbfe9b.tar.bz2 iced-d4c4198f7242f168de65146e0ca339e0c1cbfe9b.zip |
Write documentation for the new `canvas` API
Diffstat (limited to 'wgpu/src/widget/canvas/cursor.rs')
-rw-r--r-- | wgpu/src/widget/canvas/cursor.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/wgpu/src/widget/canvas/cursor.rs b/wgpu/src/widget/canvas/cursor.rs index 7ab58b87..456760ea 100644 --- a/wgpu/src/widget/canvas/cursor.rs +++ b/wgpu/src/widget/canvas/cursor.rs @@ -1,8 +1,12 @@ use iced_native::{Point, Rectangle}; +/// The mouse cursor state. #[derive(Debug, Clone, Copy, PartialEq)] pub enum Cursor { + /// The cursor has a defined position. Available(Point), + + /// The cursor is currently unavailable (i.e. out of bounds or busy). Unavailable, } @@ -17,6 +21,9 @@ impl Cursor { } } + /// Returns the absolute position of the [`Cursor`], if available. + /// + /// [`Cursor`]: enum.Cursor.html pub fn position(&self) -> Option<Point> { match self { Cursor::Available(position) => Some(*position), @@ -24,6 +31,13 @@ impl Cursor { } } + /// Returns the relative position of the [`Cursor`] inside the given bounds, + /// if available. + /// + /// If the [`Cursor`] is not over the provided bounds, this method will + /// return `None`. + /// + /// [`Cursor`]: enum.Cursor.html pub fn position_in(&self, bounds: &Rectangle) -> Option<Point> { if self.is_over(bounds) { self.position_from(bounds.position()) @@ -32,6 +46,10 @@ impl Cursor { } } + /// Returns the relative position of the [`Cursor`] from the given origin, + /// if available. + /// + /// [`Cursor`]: enum.Cursor.html pub fn position_from(&self, origin: Point) -> Option<Point> { match self { Cursor::Available(position) => { @@ -41,6 +59,10 @@ impl Cursor { } } + /// Returns whether the [`Cursor`] is currently over the provided bounds + /// or not. + /// + /// [`Cursor`]: enum.Cursor.html pub fn is_over(&self, bounds: &Rectangle) -> bool { match self { Cursor::Available(position) => bounds.contains(*position), |