@@ -429,25 +429,25 @@ where
429429 // println!("cursor in bar_bounds: {:?}", cursor.is_over(bar_bounds));
430430
431431 match event {
432- Event :: Mouse ( mouse:: Event :: ButtonPressed ( mouse:: Button :: Left ) ) => {
433- if cursor. is_over ( bar_bounds) {
434- global_state. pressed = true ;
435- if global_state. open {
436- schedule_close_on_click (
437- global_state,
438- & self . global_parameters ,
439- slice,
440- & mut self . roots ,
441- slice_layout. children ( ) ,
442- cursor,
443- self . close_on_item_click ,
444- self . close_on_background_click ,
445- ) ;
446- } else {
447- global_state. schedule ( MenuBarTask :: OpenOnClick ) ;
448- }
449- shell. capture_event ( ) ;
432+ Event :: Mouse ( mouse:: Event :: ButtonPressed ( mouse:: Button :: Left ) )
433+ if cursor. is_over ( bar_bounds) =>
434+ {
435+ global_state. pressed = true ;
436+ if global_state. open {
437+ schedule_close_on_click (
438+ global_state,
439+ & self . global_parameters ,
440+ slice,
441+ & mut self . roots ,
442+ slice_layout. children ( ) ,
443+ cursor,
444+ self . close_on_item_click ,
445+ self . close_on_background_click ,
446+ ) ;
447+ } else {
448+ global_state. schedule ( MenuBarTask :: OpenOnClick ) ;
450449 }
450+ shell. capture_event ( ) ;
451451 }
452452 Event :: Mouse ( mouse:: Event :: ButtonReleased ( mouse:: Button :: Left ) ) => {
453453 global_state. pressed = false ;
@@ -469,42 +469,39 @@ where
469469 }
470470 }
471471 }
472- Event :: Mouse ( mouse:: Event :: CursorMoved { .. } ) => {
473- if global_state. open {
474- if cursor. is_over ( bar_bounds) {
475- try_open_menu (
476- & mut self . roots ,
477- bar_menu_state,
478- item_trees,
479- slice_layout. children ( ) ,
480- cursor,
481- shell,
482- ) ;
483- shell. capture_event ( ) ;
484- } else {
485- bar. close ( item_trees, shell) ;
486- }
487- }
488- }
489- Event :: Mouse ( mouse:: Event :: WheelScrolled { delta } ) => {
490- if cursor. is_over ( bar_bounds) && slice_layout. bounds ( ) . width > layout. bounds ( ) . width
491- // check if scrolling is on
492- {
493- let scroll_speed = self . global_parameters . scroll_speed ;
494- let delta_x = match delta {
495- mouse:: ScrollDelta :: Lines { x, .. } => x * scroll_speed. line ,
496- mouse:: ScrollDelta :: Pixels { x, .. } => x * scroll_speed. pixel ,
497- } ;
498-
499- let min_offset = -( slice_layout. bounds ( ) . width - layout. bounds ( ) . width ) ;
500-
501- bar_menu_state. scroll_offset =
502- ( bar_menu_state. scroll_offset + delta_x) . clamp ( min_offset, 0.0 ) ;
503- shell. invalidate_layout ( ) ;
504- shell. request_redraw ( ) ;
472+ Event :: Mouse ( mouse:: Event :: CursorMoved { .. } ) if global_state. open => {
473+ if cursor. is_over ( bar_bounds) {
474+ try_open_menu (
475+ & mut self . roots ,
476+ bar_menu_state,
477+ item_trees,
478+ slice_layout. children ( ) ,
479+ cursor,
480+ shell,
481+ ) ;
505482 shell. capture_event ( ) ;
483+ } else {
484+ bar. close ( item_trees, shell) ;
506485 }
507486 }
487+ Event :: Mouse ( mouse:: Event :: WheelScrolled { delta } )
488+ if cursor. is_over ( bar_bounds)
489+ && slice_layout. bounds ( ) . width > layout. bounds ( ) . width =>
490+ {
491+ let scroll_speed = self . global_parameters . scroll_speed ;
492+ let delta_x = match delta {
493+ mouse:: ScrollDelta :: Lines { x, .. } => x * scroll_speed. line ,
494+ mouse:: ScrollDelta :: Pixels { x, .. } => x * scroll_speed. pixel ,
495+ } ;
496+
497+ let min_offset = -( slice_layout. bounds ( ) . width - layout. bounds ( ) . width ) ;
498+
499+ bar_menu_state. scroll_offset =
500+ ( bar_menu_state. scroll_offset + delta_x) . clamp ( min_offset, 0.0 ) ;
501+ shell. invalidate_layout ( ) ;
502+ shell. request_redraw ( ) ;
503+ shell. capture_event ( ) ;
504+ }
508505 Event :: Window ( window:: Event :: Resized { .. } ) => {
509506 if slice_layout. bounds ( ) . width > layout. bounds ( ) . width {
510507 let min_offset = -( slice_layout. bounds ( ) . width - layout. bounds ( ) . width ) ;
0 commit comments