diff --git a/pygame_gui/ui_manager.py b/pygame_gui/ui_manager.py index 08802af9..116d8326 100644 --- a/pygame_gui/ui_manager.py +++ b/pygame_gui/ui_manager.py @@ -222,6 +222,7 @@ def process_events(self, event: pygame.event.Event): sorted_layers = sorted(self.ui_group.layers(), reverse=True) for layer in sorted_layers: sprites_in_layer = self.ui_group.get_sprites_from_layer(layer) + sprites_in_layer.reverse() if not sorting_consumed_event: windows_in_layer = [window for window in sprites_in_layer if 'window' in window.element_ids[-1]] @@ -336,7 +337,9 @@ def _handle_hovering(self, time_delta): hover_handled = False sorted_layers = sorted(self.ui_group.layers(), reverse=True) for layer in sorted_layers: - for ui_element in self.ui_group.get_sprites_from_layer(layer): + layer_elements = self.ui_group.get_sprites_from_layer(layer) + layer_elements.reverse() + for ui_element in layer_elements: if ui_element.visible: # Only check hover for visible elements - ignore hidden elements # we need to check hover even after already found what we are hovering, diff --git a/tests/test_elements/test_ui_scrolling_container.py b/tests/test_elements/test_ui_scrolling_container.py index fd612c64..b882243f 100644 --- a/tests/test_elements/test_ui_scrolling_container.py +++ b/tests/test_elements/test_ui_scrolling_container.py @@ -438,13 +438,13 @@ def test_are_contents_hovered(self, _init_pygame, default_ui_manager: IUIManage assert container.are_contents_hovered() assert container.vert_scroll_bar is not None - container.vert_scroll_bar.process_event(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5})) + container.vert_scroll_bar.process_event(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5, 'x': 0.0})) assert container.vert_scroll_bar.scroll_wheel_moved assert container.horiz_scroll_bar is not None - container.horiz_scroll_bar.process_event(pygame.event.Event(pygame.MOUSEWHEEL, {'x': -0.5})) + container.horiz_scroll_bar.process_event(pygame.event.Event(pygame.MOUSEWHEEL, {'x': -0.5, 'y': 0.0})) assert container.horiz_scroll_bar.scroll_wheel_moved @@ -465,7 +465,7 @@ def test_scrolls_while_hovering_non_scrolling_contents(self, _init_pygame, defa assert container.are_contents_hovered() assert container.vert_scroll_bar is not None - manager.process_events(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5})) + manager.process_events(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5, 'x': 0.0})) assert container.vert_scroll_bar.scroll_wheel_moved @@ -490,7 +490,7 @@ def test_does_not_scroll_while_hovering_scrolling_contents(self, _init_pygame, d assert container.are_contents_hovered() assert container.vert_scroll_bar is not None - manager.process_events(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5})) + manager.process_events(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5, 'x': 0.0})) assert not container.vert_scroll_bar.scroll_wheel_moved @@ -513,7 +513,7 @@ def test_scroll_while_hovering_nested_contents(self, _init_pygame, default_ui_ma assert container.are_contents_hovered() assert container.vert_scroll_bar is not None - manager.process_events(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5})) + manager.process_events(pygame.event.Event(pygame.MOUSEWHEEL, {'y': -0.5, 'x': 0.0})) assert container.vert_scroll_bar.scroll_wheel_moved