@@ -266,12 +266,12 @@ pub enum WindowEvent {
266266 /// [`transform`]: https://developer.mozilla.org/en-US/docs/Web/CSS/transform
267267 CursorLeft { device_id : DeviceId } ,
268268
269+ /// A cursor button press has been received.
270+ CursorInput { device_id : DeviceId , state : ElementState , button : CursorButton } ,
271+
269272 /// A mouse wheel movement or touchpad scroll occurred.
270273 MouseWheel { device_id : DeviceId , delta : MouseScrollDelta , phase : TouchPhase } ,
271274
272- /// An mouse button press has been received.
273- MouseInput { device_id : DeviceId , state : ElementState , button : MouseButton } ,
274-
275275 /// Two-finger pinch gesture, often used for magnification.
276276 ///
277277 /// ## Platform-specific
@@ -1130,6 +1130,21 @@ impl ToolAngle {
11301130 }
11311131}
11321132
1133+ /// Input type for vaiour cursor types.
1134+ #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
1135+ #[ cfg_attr( feature = "serde" , derive( Deserialize , Serialize ) ) ]
1136+ pub enum CursorButton {
1137+ Mouse ( MouseButton ) ,
1138+ Pen ( ToolButton ) ,
1139+ Eraser ( ToolButton ) ,
1140+ }
1141+
1142+ impl From < MouseButton > for CursorButton {
1143+ fn from ( mouse : MouseButton ) -> Self {
1144+ Self :: Mouse ( mouse)
1145+ }
1146+ }
1147+
11331148/// Describes the input state of a key.
11341149#[ derive( Debug , Hash , PartialEq , Eq , Clone , Copy ) ]
11351150#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -1162,6 +1177,28 @@ pub enum MouseButton {
11621177 Other ( u16 ) ,
11631178}
11641179
1180+ /// Describes a button of a tool, e.g. a pen.
1181+ #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
1182+ #[ cfg_attr( feature = "serde" , derive( Deserialize , Serialize ) ) ]
1183+ pub enum ToolButton {
1184+ Contact ,
1185+ Barrel ,
1186+ Other ( u16 ) ,
1187+ }
1188+
1189+ impl From < ToolButton > for MouseButton {
1190+ fn from ( tool : ToolButton ) -> Self {
1191+ match tool {
1192+ ToolButton :: Contact => MouseButton :: Left ,
1193+ ToolButton :: Barrel => MouseButton :: Right ,
1194+ ToolButton :: Other ( 1 ) => MouseButton :: Middle ,
1195+ ToolButton :: Other ( 3 ) => MouseButton :: Back ,
1196+ ToolButton :: Other ( 4 ) => MouseButton :: Forward ,
1197+ ToolButton :: Other ( other) => MouseButton :: Other ( other) ,
1198+ }
1199+ }
1200+ }
1201+
11651202/// Describes a difference in the mouse scroll wheel state.
11661203#[ derive( Debug , Clone , Copy , PartialEq ) ]
11671204#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -1275,10 +1312,10 @@ mod tests {
12751312 delta: event:: MouseScrollDelta :: LineDelta ( 0.0 , 0.0 ) ,
12761313 phase: event:: TouchPhase :: Started ,
12771314 } ) ;
1278- with_window_event( MouseInput {
1315+ with_window_event( CursorInput {
12791316 device_id: did,
12801317 state: event:: ElementState :: Pressed ,
1281- button: event:: MouseButton :: Other ( 0 ) ,
1318+ button: event:: MouseButton :: Other ( 0 ) . into ( ) ,
12821319 } ) ;
12831320 with_window_event( PinchGesture {
12841321 device_id: did,
0 commit comments