11use crate :: { Point , Rectangle , Transformation , Vector } ;
22
3- use std:: ops:: Mul ;
4-
53/// The mouse cursor state.
64#[ derive( Debug , Clone , Copy , PartialEq , Default ) ]
75pub enum Cursor {
86 /// The cursor has a defined position.
97 Available ( Point ) ,
108
9+ /// The cursor has a defined position, but it's levitating over a layer above.
10+ Levitating ( Point ) ,
11+
1112 /// The cursor is currently unavailable (i.e. out of bounds or busy).
1213 #[ default]
1314 Unavailable ,
@@ -18,7 +19,7 @@ impl Cursor {
1819 pub fn position ( self ) -> Option < Point > {
1920 match self {
2021 Cursor :: Available ( position) => Some ( position) ,
21- Cursor :: Unavailable => None ,
22+ Cursor :: Levitating ( _ ) | Cursor :: Unavailable => None ,
2223 }
2324 }
2425
@@ -51,17 +52,41 @@ impl Cursor {
5152 pub fn is_over ( self , bounds : Rectangle ) -> bool {
5253 self . position_over ( bounds) . is_some ( )
5354 }
55+
56+ /// Returns true if the [`Cursor`] is levitating over a layer above.
57+ pub fn is_levitating ( self ) -> bool {
58+ matches ! ( self , Self :: Levitating ( _) )
59+ }
60+
61+ /// Makes the [`Cursor`] levitate over a layer above.
62+ pub fn levitate ( self ) -> Self {
63+ match self {
64+ Self :: Available ( position) => Self :: Levitating ( position) ,
65+ _ => self ,
66+ }
67+ }
68+
69+ /// Brings the [`Cursor`] back to the current layer.
70+ pub fn land ( self ) -> Self {
71+ match self {
72+ Cursor :: Levitating ( position) => Cursor :: Available ( position) ,
73+ _ => self ,
74+ }
75+ }
5476}
5577
56- impl Mul < Transformation > for Cursor {
78+ impl std :: ops :: Mul < Transformation > for Cursor {
5779 type Output = Self ;
5880
5981 fn mul ( self , transformation : Transformation ) -> Self {
6082 match self {
61- Cursor :: Unavailable => Cursor :: Unavailable ,
62- Cursor :: Available ( point) => {
63- Cursor :: Available ( point * transformation)
83+ Self :: Available ( position) => {
84+ Self :: Available ( position * transformation)
85+ }
86+ Self :: Levitating ( position) => {
87+ Self :: Levitating ( position * transformation)
6488 }
89+ Self :: Unavailable => Self :: Unavailable ,
6590 }
6691 }
6792}
0 commit comments