@@ -151,7 +151,7 @@ impl InputState {
151
151
152
152
fn mouse_input ( & mut self , button : & MouseButton , state : & ElementState ) -> ClickCount {
153
153
self . mouse_state . update ( button, state) ;
154
- self . mouse_click_tracker . input ( button, state, & self . mouse_position )
154
+ self . mouse_click_tracker . input ( button, state, self . mouse_position )
155
155
}
156
156
157
157
fn cef_modifiers ( & self , location : & winit:: keyboard:: KeyLocation , is_repeat : bool ) -> CefModifiers {
@@ -187,7 +187,7 @@ impl From<&mut InputState> for MouseEvent {
187
187
}
188
188
}
189
189
190
- #[ derive( Default , Clone ) ]
190
+ #[ derive( Default , Clone , Copy ) ]
191
191
pub ( crate ) struct MousePosition {
192
192
x : usize ,
193
193
y : usize ,
@@ -233,42 +233,35 @@ struct ClickTracker {
233
233
right : Option < ClickRecord > ,
234
234
}
235
235
impl ClickTracker {
236
- fn input ( & mut self , button : & MouseButton , state : & ElementState , position : & MousePosition ) -> ClickCount {
236
+ fn input ( & mut self , button : & MouseButton , state : & ElementState , position : MousePosition ) -> ClickCount {
237
237
let record = match button {
238
238
MouseButton :: Left => & mut self . left ,
239
239
MouseButton :: Right => & mut self . right ,
240
240
MouseButton :: Middle => & mut self . middle ,
241
241
_ => return ClickCount :: Single ,
242
242
} ;
243
243
244
- let now = Instant :: now ( ) ;
245
-
246
244
let Some ( record) = record else {
247
- * record = Some ( ClickRecord {
248
- time : now,
249
- position : position. clone ( ) ,
250
- down_count : ClickCount :: Single ,
251
- up_count : ClickCount :: Single ,
252
- } ) ;
245
+ * record = Some ( ClickRecord { position, ..Default :: default ( ) } ) ;
253
246
return ClickCount :: Single ;
254
247
} ;
255
248
249
+ let now = Instant :: now ( ) ;
250
+ record. time = now;
251
+ record. position = position;
252
+
256
253
match state {
257
254
ElementState :: Pressed if record. down_count == ClickCount :: Double => {
258
255
* record = ClickRecord {
259
- time : now,
260
- position : position. clone ( ) ,
261
256
down_count : ClickCount :: Single ,
262
- up_count : record . up_count ,
257
+ .. * record
263
258
} ;
264
259
return ClickCount :: Single ;
265
260
}
266
261
ElementState :: Released if record. up_count == ClickCount :: Double => {
267
262
* record = ClickRecord {
268
- time : now,
269
- position : position. clone ( ) ,
270
- down_count : record. down_count ,
271
263
up_count : ClickCount :: Single ,
264
+ ..* record
272
265
} ;
273
266
return ClickCount :: Single ;
274
267
}
@@ -283,33 +276,19 @@ impl ClickTracker {
283
276
let count = if within_time && within_dist { ClickCount :: Double } else { ClickCount :: Single } ;
284
277
285
278
* record = match state {
286
- ElementState :: Pressed => ClickRecord {
287
- time : now,
288
- position : position. clone ( ) ,
289
- down_count : count,
290
- up_count : record. up_count ,
291
- } ,
292
- ElementState :: Released => ClickRecord {
293
- time : now,
294
- position : position. clone ( ) ,
295
- down_count : record. down_count ,
296
- up_count : count,
297
- } ,
279
+ ElementState :: Pressed => ClickRecord { down_count : count, ..* record } ,
280
+ ElementState :: Released => ClickRecord { up_count : count, ..* record } ,
298
281
} ;
299
282
count
300
283
}
301
284
}
302
285
303
- #[ derive( Clone , Copy , PartialEq ) ]
286
+ #[ derive( Clone , Copy , PartialEq , Default ) ]
304
287
enum ClickCount {
288
+ #[ default]
305
289
Single ,
306
290
Double ,
307
291
}
308
- impl Default for ClickCount {
309
- fn default ( ) -> Self {
310
- Self :: Single
311
- }
312
- }
313
292
impl From < ClickCount > for i32 {
314
293
fn from ( count : ClickCount ) -> i32 {
315
294
match count {
@@ -319,13 +298,25 @@ impl From<ClickCount> for i32 {
319
298
}
320
299
}
321
300
301
+ #[ derive( Clone , Copy ) ]
322
302
struct ClickRecord {
323
303
time : Instant ,
324
304
position : MousePosition ,
325
305
down_count : ClickCount ,
326
306
up_count : ClickCount ,
327
307
}
328
308
309
+ impl Default for ClickRecord {
310
+ fn default ( ) -> Self {
311
+ Self {
312
+ time : Instant :: now ( ) ,
313
+ position : Default :: default ( ) ,
314
+ down_count : Default :: default ( ) ,
315
+ up_count : Default :: default ( ) ,
316
+ }
317
+ }
318
+ }
319
+
329
320
struct CefModifiers ( u32 ) ;
330
321
impl CefModifiers {
331
322
fn new ( input_state : & InputState , location : & winit:: keyboard:: KeyLocation , is_repeat : bool ) -> Self {
0 commit comments