MyreMylar/pygame_gui

Using set_anchors() on a UIPanel to change it's anchor target, moves the UIPanel but not it's content

Closed this issue · 0 comments

Describe the bug
Using set_anchors() on a UIPanel to change it's anchor target, moves the UIPanel but not it's content (the panel's internal UIContainer).

To Reproduce
Steps to reproduce the behaviour:

  1. Create a UIPanel and at another UIElement to this panel
  2. Define new anchor targets for the UIPanel using .set_anchors()
  3. The UIPanel moves (after rebuilding it's parent), but it's contents (the panel's internal UIContainer) do not.
  4. A workaround is also defining the same anchors targets to the UIPanel's internal UIContainer.
  5. (see attached code below)

Expected behaviour
Using .set_anchors() on a UIPanel should define the same anchors to it's internal UIContainer

Screenshots
.set_anchors not called
image

.set_anchors({'top_target': button}) on UIPanel only
image

.set_anchors({'top_target': button}) on UIPanel and it's internal UIContainer
image

Platform and software (please complete the following information):

  • OS: Windows 10
  • Pygame GUI version 0.6.10
  • Pygame-ce version 2.4.1

Additional context
example code:

`

import pygame
import pygame_gui as gui

class Window(gui.elements.UIWindow):
    def __init__(self,
                 manager,
                 window_display_title,
                 object_id,
                 rect = pygame.Rect(50, 50, 200, 400)):
        
        super().__init__(rect = rect,
                        manager = manager,
                        window_display_title = window_display_title,
                        object_id = object_id,
                        resizable = False)
    
        self.manager = manager
    
        self.recreate_ui()
    
    def recreate_ui(self):
        panel = gui.elements.UIPanel(relative_rect = pygame.Rect(5, 5, 30, 30),
                                     manager = self.manager,
                                     container = self)
    
        label = gui.elements.UILabel(relative_rect = pygame.Rect(5, 5, 20, 20),
                                    text = "X",
                                    manager = self.manager,
                                    container = panel)
    
        button = gui.elements.UIButton(relative_rect = pygame.Rect(50, 50, 30, 30),
                                       manager = self.manager,
                                       text = "B",
                                       container = self)
    
        panel.set_anchors({'top_target': button})
        panel.get_container().set_anchors({'top_target': button}) #commenting this line will move the Panel but not it's contents
    
        self.rebuild()

    def update(self, time_delta):
        super().update(time_delta)

    def process_event(self, event):
        handled = super().process_event(event)
        
        return handled

`