@@ -99,6 +99,59 @@ impl MouseState {
9999 pub fn just_released_any ( & self , mouse_buttons : & [ MouseButton ] ) -> bool {
100100 mouse_buttons. iter ( ) . any ( |k| self . just_released ( * k) )
101101 }
102+ // -------------------------
103+ /// Calls the closure if the mouse button was pressed
104+ #[ inline]
105+ pub fn pressed_do ( & self , mouse_button : MouseButton , mut f : impl FnMut ( ) ) -> & Self {
106+ if self . pressed ( mouse_button) {
107+ f ( ) ;
108+ }
109+ self
110+ }
111+ /// Calls the closure if any of the indicated mouse buttons were pressed
112+ #[ inline]
113+ pub fn pressed_any_do ( & self , mouse_buttons : & [ MouseButton ] , mut f : impl FnMut ( ) ) -> & Self {
114+ if self . pressed_any ( mouse_buttons) {
115+ f ( ) ;
116+ }
117+ self
118+ }
119+ /// Calls the closure if the mouse button started being pressed during the last frame
120+ #[ inline]
121+ pub fn just_pressed_do ( & self , mouse_button : MouseButton , mut f : impl FnMut ( ) ) -> & Self {
122+ if self . just_pressed ( mouse_button) {
123+ f ( ) ;
124+ }
125+ self
126+ }
127+ /// Calls the closure if any of the indicated mouse buttons were just pressed this frame
128+ #[ inline]
129+ pub fn just_pressed_any_do ( & self , mouse_buttons : & [ MouseButton ] , mut f : impl FnMut ( ) ) -> & Self {
130+ if self . just_pressed_any ( mouse_buttons) {
131+ f ( ) ;
132+ }
133+ self
134+ }
135+ /// Calls the closure if the mouse button started being released during the last frame
136+ #[ inline]
137+ pub fn just_released_do ( & self , mouse_button : MouseButton , mut f : impl FnMut ( ) ) -> & Self {
138+ if self . just_released ( mouse_button) {
139+ f ( ) ;
140+ }
141+ self
142+ }
143+ /// Calls the closure if any of the indicated mouse buttons were just released this frame
144+ #[ inline]
145+ pub fn just_released_any_do (
146+ & self ,
147+ mouse_buttons : & [ MouseButton ] ,
148+ mut f : impl FnMut ( ) ,
149+ ) -> & Self {
150+ if self . just_released_any ( mouse_buttons) {
151+ f ( ) ;
152+ }
153+ self
154+ }
102155}
103156
104157/// Gather the mouse events from bevy and store them for our own use
0 commit comments