Skip to content

Commit

Permalink
improve handling of showing/hiding for more elements
Browse files Browse the repository at this point in the history
  • Loading branch information
MyreMylar committed Apr 22, 2023
1 parent 9eb3cb4 commit bfc3748
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
17 changes: 10 additions & 7 deletions pygame_gui/elements/ui_drop_down_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,10 @@ def __init__(self,
*,
expand_on_option_click: bool = True
):

# Need to move some declarations early as they are indirectly referenced via the ui element
# constructor
self.menu_states = None
self.current_state = None
super().__init__(relative_rect, manager, container=container,
starting_height=0,
anchors=anchors,
Expand Down Expand Up @@ -971,8 +974,8 @@ def show(self):
showing it's buttons.
"""
super().show()

self.menu_states['closed'].show()
if self.current_state is not None and self.menu_states is not None:
self.menu_states['closed'].show()

def hide(self):
"""
Expand All @@ -981,7 +984,7 @@ def hide(self):
call the hide() method of the 'closed' state which hides all it's children widgets.
"""
super().hide()

if self.current_state == self.menu_states['expanded']:
self.menu_states['expanded'].hide()
self.menu_states['closed'].hide()
if self.current_state is not None and self.menu_states is not None:
if self.current_state == self.menu_states['expanded']:
self.menu_states['expanded'].hide()
self.menu_states['closed'].hide()
4 changes: 2 additions & 2 deletions pygame_gui/elements/ui_horizontal_scroll_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ def show(self):
will propagate and show all the buttons.
"""
super().show()

self.button_container.show()
if self.button_container is not None:
self.button_container.show()

def hide(self):
"""
Expand Down
7 changes: 4 additions & 3 deletions pygame_gui/elements/ui_horizontal_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def __init__(self,
visible: int = 1,
click_increment: Union[float, int] = 1
):

# Need to move some declarations early as they are indirectly referenced via the ui element
# constructor
self.sliding_button = None
self.button_container = None
super().__init__(relative_rect, manager, container,
Expand Down Expand Up @@ -560,8 +561,8 @@ def show(self):
the button_container which will propagate and show the left and right buttons.
"""
super().show()

self.sliding_button.show()
if self.sliding_button is not None:
self.sliding_button.show()
if self.button_container is not None:
self.button_container.show()

Expand Down
11 changes: 7 additions & 4 deletions pygame_gui/elements/ui_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def __init__(self,
anchors: Optional[Dict[str, Union[str, UIElement]]] = None,
visible: int = 1
):

# Need to move some declarations early as they are indirectly referenced via the ui element
# constructor
self.panel_container = None
super().__init__(relative_rect,
manager,
container,
Expand Down Expand Up @@ -300,12 +302,13 @@ def show(self):
In addition to the base UIElement.show() - call show() of owned container - panel_container.
"""
super().show()

self.panel_container.show()
if self.panel_container is not None:
self.panel_container.show()

def hide(self):
"""
In addition to the base UIElement.hide() - call hide() of owned container - panel_container.
"""
self.panel_container.hide()
if self.panel_container is not None:
self.panel_container.hide()
super().hide()
10 changes: 7 additions & 3 deletions pygame_gui/elements/ui_scrolling_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def __init__(self,
object_id: Optional[Union[ObjectID, str]] = None,
anchors: Optional[Dict[str, Union[str, UIElement]]] = None,
visible: int = 1):

# Need to move some declarations early as they are indirectly referenced via the ui element
# constructor
self._root_container = None
super().__init__(relative_rect,
manager,
container,
Expand Down Expand Up @@ -439,7 +441,8 @@ def show(self):
separately.
"""
super().show()
self._root_container.show()
if self._root_container is not None:
self._root_container.show()

def hide(self):
"""
Expand All @@ -448,5 +451,6 @@ def hide(self):
it's visibility will propagate to them - there is no need to call their hide() methods
separately.
"""
self._root_container.hide()
if self._root_container is not None:
self._root_container.hide()
super().hide()
4 changes: 2 additions & 2 deletions pygame_gui/elements/ui_selection_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ def show(self):
there is no need to call their show() methods separately.
"""
super().show()

self.list_and_scroll_bar_container.show()
if self.list_and_scroll_bar_container is not None:
self.list_and_scroll_bar_container.show()

def hide(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions pygame_gui/elements/ui_vertical_scroll_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ def show(self):
propagate and show all the buttons.
"""
super().show()

self.button_container.show()
if self.button_container is not None:
self.button_container.show()

def hide(self):
"""
Expand Down

0 comments on commit bfc3748

Please sign in to comment.