Skip to content

Commit

Permalink
Fix #610 by not hiding if not visible
Browse files Browse the repository at this point in the history
This fixes issue #610, where calling the hide() method on an already hidden element called the full hide() functionality again, including generating any events, such as unhovering. This bug is present in all hide()  method implementation in the codebase (except UIPanel.hide) and is fixed with this commit for all widgets by exiting the hide() method early if self.visible is False.
  • Loading branch information
rbaltrusch committed Aug 25, 2024
1 parent c25d04e commit d302e11
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pygame_gui/elements/ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ def hide(self):
"""
In addition to the base UIElement.hide() - Change the hovered state to a normal state.
"""
super().hide()

self.on_unhovered()
if self.visible:
super().hide()
self.on_unhovered()

def on_locale_changed(self):
font = self.ui_theme.get_font(self.combined_element_ids)
Expand Down
6 changes: 6 additions & 0 deletions pygame_gui/elements/ui_drop_down_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ def hide(self):
"""
Hide selected_option_button and open_button.
"""
if not self.visible:
return

self.visible = False

if self.open_button is not None:
Expand Down Expand Up @@ -1013,6 +1016,9 @@ def hide(self):
hide() method, which begins a transition of the UIDropDownMenu to the 'closed' state, and
call the hide() method of the 'closed' state which hides all it's children widgets.
"""
if not self.visible:
return

super().hide()
if self.current_state is not None and self.menu_states is not None:
if self.current_state == self.menu_states['expanded']:
Expand Down
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_horizontal_scroll_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ def hide(self):
In addition to the base UIElement.hide() - hide the self.button_container which
will propagate and hide all the buttons.
"""
if not self.visible:
return

super().hide()
if self.button_container is not None:
self.button_container.hide()
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_horizontal_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@ def hide(self):
In addition to the base UIElement.hide() - hide the sliding button and hide
the button_container which will propagate and hide the left and right buttons.
"""
if not self.visible:
return

super().hide()

if self.sliding_button is not None:
Expand Down
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ def hide(self):
"""
In addition to the base UIElement.hide() - call hide() of owned container - panel_container.
"""
if not self.visible:
return

if self.panel_container is not None:
self.panel_container.hide()
super().hide()
Expand Down
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_scrolling_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ def hide(self):
it's visibility will propagate to them - there is no need to call their hide() methods
separately.
"""
if not self.visible:
return

if self._root_container is not None:
self._root_container.hide()
super().hide()
Expand Down
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_selection_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,9 @@ def hide(self):
children of list_and_scroll_bar_container, so it's visibility will propagate to them -
there is no need to call their hide() methods separately.
"""
if not self.visible:
return

super().hide()
if self.list_and_scroll_bar_container is not None:
self.list_and_scroll_bar_container.hide()
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_tab_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def hide(self):
In addition to the base UIElement.hide() - hide the _window_root_container which will
propagate and hide all the children.
"""
if not self.visible:
return

super().hide()
if self._root_container is not None:
self._root_container.hide()
Expand Down
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_text_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,9 @@ def hide(self):
"""
In addition to the base UIElement.hide() - call hide() of scroll_bar if it exists.
"""
if not self.visible:
return

super().hide()

if self.scroll_bar is not None:
Expand Down
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_vertical_scroll_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ def hide(self):
In addition to the base UIElement.hide() - hide the self.button_container which will
propagate and hide all the buttons.
"""
if not self.visible:
return

super().hide()
if self.button_container is not None:
self.button_container.hide()
3 changes: 3 additions & 0 deletions pygame_gui/elements/ui_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ def hide(self):
In addition to the base UIElement.hide() - hide the _window_root_container which will
propagate and hide all the children.
"""
if not self.visible:
return

super().hide()
if self._window_root_container is not None:
self._window_root_container.hide()
Expand Down
3 changes: 3 additions & 0 deletions pygame_gui/windows/ui_colour_picker_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ def hide(self):
In addition to the base UIElement.hide() - call hide() of the element_container
- which will propagate to the sub-elements - label, entry and slider.
"""
if not self.visible:
return

super().hide()
if self.element_container is not None:
self.element_container.hide()
Expand Down

0 comments on commit d302e11

Please sign in to comment.