@@ -256,37 +256,33 @@ where
256
256
| mouse:: ScrollDelta :: Pixels { y, .. } => y,
257
257
} ;
258
258
259
- if y. is_sign_negative ( ) {
260
- let mut options_iter = self . options . iter ( ) ;
259
+ fn find_next < ' a , T : PartialEq > (
260
+ selected : & ' a T ,
261
+ mut options : impl Iterator < Item = & ' a T > ,
262
+ ) -> Option < & ' a T > {
263
+ let _ = options. find ( |& option| option == selected) ;
264
+
265
+ options. next ( )
266
+ }
267
+
268
+ let next_option = if y < 0.0 {
261
269
if let Some ( selected) = self . selected . as_ref ( ) {
262
- if let Some ( _) =
263
- options_iter. position ( |o| o == selected)
264
- {
265
- if let Some ( prev_val) = options_iter. next ( ) {
266
- messages
267
- . push ( ( self . on_selected ) ( prev_val. clone ( ) ) ) ;
268
- }
269
- }
270
+ find_next ( selected, self . options . iter ( ) )
270
271
} else {
271
- messages
272
- . push ( ( self . on_selected ) ( self . options [ 0 ] . clone ( ) ) ) ;
272
+ self . options . first ( )
273
273
}
274
- } else {
275
- let mut options_iter = self . options . iter ( ) . rev ( ) ;
274
+ } else if y > 0.0 {
276
275
if let Some ( selected) = self . selected . as_ref ( ) {
277
- if let Some ( _) =
278
- options_iter. position ( |o| o == selected)
279
- {
280
- if let Some ( next_val) = options_iter. next ( ) {
281
- messages
282
- . push ( ( self . on_selected ) ( next_val. clone ( ) ) ) ;
283
- }
284
- }
276
+ find_next ( selected, self . options . iter ( ) . rev ( ) )
285
277
} else {
286
- messages. push ( ( self . on_selected ) (
287
- self . options [ self . options . len ( ) - 1 ] . clone ( ) ,
288
- ) ) ;
278
+ self . options . last ( )
289
279
}
280
+ } else {
281
+ None
282
+ } ;
283
+
284
+ if let Some ( next_option) = next_option {
285
+ messages. push ( ( self . on_selected ) ( next_option. clone ( ) ) ) ;
290
286
}
291
287
292
288
return event:: Status :: Captured ;
0 commit comments