Repository: MyreMylar/pygame_gui (python)

Issue:
Content of all tabs of a UITabContainer become visible when showing the UIWindow that contains UITabContainer
**Describe the bug**
When you call "show" on a UIWindow containing a UITabContainer, the contents of all tabs become visible.

**To Reproduce**
Steps to reproduce the behaviour:
1. Run the reproducible example below
2. Close the UIWindow object
3. Click the UIButton object to show the window again

**Expected behaviour**
I expected that only the content of the last selected tab to become visible.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Platform and software (please complete the following information):**
 - OS: Ubuntu 24.04 LTS, Linux Kernel 6.8.0-40-generic x86_64
 - Pygame GUI version: pygame_gui        0.6.12
 - Pygame version: pygame-ce         2.5.0


Reproducible example:
```python
import pygame as pg
import pygame_gui as pgg

SHAPE = (800, 600)
pg.init()
pg.display.set_caption('Quick Start')
clock = pg.time.Clock()
manager = pgg.UIManager(SHAPE)
window_surface = pg.display.set_mode(SHAPE)
background = pg.Surface(SHAPE)
background.fill(pg.Color('#000000'))

class MyWindow(pgg.elements.UIWindow):
    def on_close_window_button_pressed(self):
        self.hide()

btn = pgg.elements.UIButton(pg.Rect(32, 32, 120, 24), 'Show window')
win = MyWindow(pg.Rect(32, 64, 320, 480), manager, 'Janela')
tabs = pgg.elements.UITabContainer(pg.Rect(0, 0, 320, 480), manager, win)
for i in range(4):
    tab = tabs.add_tab(f"Tab{i}", f"tab{i}")
    lab = pgg.elements.UILabel(
        pg.Rect(16, 16+24*i, 120, 32), f"Label for Tab {i}",
        manager, tabs.get_tab_container(tab))

is_running = True
while is_running:
    time_delta = clock.tick(60)/1000.0
    for event in pg.event.get():
        if event.type == pg.QUIT:
            is_running = False
            break
        if event.type == pgg.UI_BUTTON_PRESSED:
            win.show()
        manager.process_events(event)
    manager.update(time_delta)
    window_surface.blit(background, (0, 0))
    manager.draw_ui(window_surface)
    pg.display.flip()
pg.quit()
```

Pull request:
Add better option to disable hiding/showing contained elements of containers
hopefully also fixes #628 

Patch:
diff --git a/pygame_gui/core/ui_appearance_theme.py b/pygame_gui/core/ui_appearance_theme.py
index 2fe3d84..700e0bb 100644
--- a/pygame_gui/core/ui_appearance_theme.py
+++ b/pygame_gui/core/ui_appearance_theme.py
@@ -103,7 +103,7 @@ class UIAppearanceTheme(IUIAppearanceThemeInterface):
             self.need_to_rebuild_data_manually_changed = False
             return True
         return False
-
+    
     @staticmethod
     def _json_to_dict(json_data):
         if isinstance(json_data, dict):
@@ -574,19 +574,16 @@ class UIAppearanceTheme(IUIAppearanceThemeInterface):
 
         :return IGUIFontInterface: An interface to a pygame font object wrapper.
         """
-        font = None
-        
+        # set the default font as the final fall back
+        font = self.font_dict.get_default_font()
+
         for combined_element_id in combined_element_ids:
             if combined_element_id in self.ele_font_res:
                 if self._locale in self.ele_font_res[combined_element_id]:
-                    font = self.ele_font_res[combined_element_id][self._locale].loaded_font
+                    return self.ele_font_res[combined_element_id][self._locale].loaded_font
                 else:
-                    font = self.ele_font_res[combined_element_id]['en'].loaded_font
-                break
+                    return self.ele_font_res[combined_element_id]['en'].loaded_font
 
-        # set the default font as the final fall back
-        if font is None:
-            font = self.font_dict.get_default_font()
         return font
 
     def get_misc_data(self, misc_data_id: str, combined_element_ids: List[str]) -> Union[str, Dict]:
@@ -770,7 +767,7 @@ class UIAppearanceTheme(IUIAppearanceThemeInterface):
                     self._load_element_font_data_from_theme(file_dict,
                                                             element_name)
 
-            if data_type == 'colours' or data_type == 'colors':
+            if data_type == 'colours':
                 self._load_element_colour_data_from_theme(data_type,
                                                           element_name,
                                                           element_theming)
@@ -1048,7 +1045,7 @@ class UIAppearanceTheme(IUIAppearanceThemeInterface):
         :param theme_dict: The data dictionary from the theming file to load data from.
         """
         for data_type in theme_dict['defaults']:
-            if data_type == 'colours' or data_type == 'colors':
+            if data_type == 'colours':
                 colours_dict = theme_dict['defaults'][data_type]
                 for colour_key in colours_dict:
                     colour = self._load_colour_or_gradient_from_theme(colours_dict,
diff --git a/pygame_gui/elements/ui_image.py b/pygame_gui/elements/ui_image.py
index 22abbf4..232893e 100644
--- a/pygame_gui/elements/ui_image.py
+++ b/pygame_gui/elements/ui_image.py
@@ -37,8 +37,7 @@ class UIImage(UIElement):
                  anchors: Optional[Dict[str, Union[str, UIElement]]] = None,
                  visible: int = 1,
                  *,
-                 starting_height: int = 1,
-                 scale_func=pygame.transform.smoothscale):
+                 starting_height: int = 1,):
 
         super().__init__(relative_rect, manager, container,
                          starting_height=starting_height,
@@ -51,7 +50,7 @@ class UIImage(UIElement):
 
         self.original_image = None
 
-        self.set_image(image_surface, image_is_alpha_premultiplied, scale_func)
+        self.set_image(image_surface, image_is_alpha_premultiplied)
         self.rebuild_from_changed_theme_data()
 
     def rebuild_from_changed_theme_data(self):
@@ -80,8 +79,7 @@ class UIImage(UIElement):
 
     def set_image(self,
                   new_image: Union[pygame.surface.Surface, None],
-                  image_is_alpha_premultiplied: bool = False,
-                  scale_func = pygame.transform.smoothscale) -> None:
+                  image_is_alpha_premultiplied: bool = False) -> None:
         """
         Allows users to change the image displayed on a UIImage element during run time, without recreating
         the element.
@@ -99,6 +97,6 @@ class UIImage(UIElement):
         if (image_surface.get_width() != self.rect.width or
                 image_surface.get_height() != self.rect.height):
             self.original_image = image_surface
-            self._set_image(scale_func(self.original_image, self.rect.size))
+            self._set_image(pygame.transform.smoothscale(self.original_image, self.rect.size))
         else:
             self._set_image(image_surface)
diff --git a/pygame_gui/elements/ui_scrolling_container.py b/pygame_gui/elements/ui_scrolling_container.py
index 381242d..8df6761 100644
--- a/pygame_gui/elements/ui_scrolling_container.py
+++ b/pygame_gui/elements/ui_scrolling_container.py
@@ -523,8 +523,15 @@ class UIScrollingContainer(UIElement, IContainerLikeInterface):
         :param show_contents: whether to also show the contents of the container. Defaults to True.
         """
         super().show()
-        if self._root_container is not None:
-            self._root_container.show(show_contents)
+
+        self._root_container.show(show_contents=False)
+        if self.vert_scroll_bar is not None:
+            self.vert_scroll_bar.show()
+        if self.horiz_scroll_bar is not None:
+            self.horiz_scroll_bar.show()
+
+        if self._view_container is not None:
+            self._view_container.show(show_contents)
 
     def hide(self, hide_contents: bool = True):
         """
@@ -537,9 +544,14 @@ class UIScrollingContainer(UIElement, IContainerLikeInterface):
         """
         if not self.visible:
             return
+        self._root_container.hide(hide_contents=False)
+        if self.vert_scroll_bar is not None:
+            self.vert_scroll_bar.hide()
+        if self.horiz_scroll_bar is not None:
+            self.horiz_scroll_bar.hide()
 
-        if self._root_container is not None:
-            self._root_container.hide(hide_contents)
+        if self._view_container is not None:
+            self._view_container.hide(hide_contents)
         super().hide()
 
     def __iter__(self) -> Iterator[IUIElementInterface]:
diff --git a/pygame_gui/elements/ui_window.py b/pygame_gui/elements/ui_window.py
index 6da4711..e0a8e90 100644
--- a/pygame_gui/elements/ui_window.py
+++ b/pygame_gui/elements/ui_window.py
@@ -758,8 +758,13 @@ class UIWindow(UIElement, IContainerLikeInterface, IWindowInterface):
         :param show_contents: whether to also show the contents of the window. Defaults to True.
         """
         super().show()
-        if self._window_root_container is not None:
-            self._window_root_container.show()
+        self._window_root_container.show(show_contents=False)
+        if self.title_bar is not None:
+            self.title_bar.show()
+        if self.close_window_button is not None:
+            self.close_window_button.show()
+        if self.window_element_container is not None:
+            self.window_element_container.show(show_contents)
 
     def hide(self, hide_contents: bool = True):
         """
@@ -772,8 +777,13 @@ class UIWindow(UIElement, IContainerLikeInterface, IWindowInterface):
             return
 
         super().hide()
-        if self._window_root_container is not None:
-            self._window_root_container.hide(hide_contents)
+        self._window_root_container.hide(hide_contents=False)
+        if self.title_bar is not None:
+            self.title_bar.hide()
+        if self.close_window_button is not None:
+            self.close_window_button.hide()
+        if self.window_element_container is not None:
+            self.window_element_container.hide(hide_contents)
 
     def get_relative_mouse_pos(self):
         """


Test patch:
diff --git a/tests/test_core/test_ui_appearance_theme.py b/tests/test_core/test_ui_appearance_theme.py
index 3920cbe..2d2c206 100644
--- a/tests/test_core/test_ui_appearance_theme.py
+++ b/tests/test_core/test_ui_appearance_theme.py
@@ -192,11 +192,8 @@ class TestUIAppearanceTheme:
         assert shadow_width == '0'
 
     def test_get_font(self, _init_pygame, _display_surface_return_none: None):
-        resource_loader = BlockingThreadedResourceLoader()
-        theme = UIAppearanceTheme(resource_loader, locale='nonsense_locale')
+        theme = UIAppearanceTheme(BlockingThreadedResourceLoader(), locale='nonsense_locale')
         theme.load_theme(os.path.join("tests", "data", "themes", "ui_button_non_default.json"))
-        resource_loader.start()
-        resource_loader.update()
         assert theme.get_font_info(['button']) == theme.ui_element_fonts_info['button']['en']
         assert theme.get_font(['button']) == theme.ele_font_res['button']['en'].loaded_font