Skip to content

Big Anchor Refactor: Dynamic dimension elements with anchors appear to calculate position before dimensions #515

Open
@LondonClass

Description

@LondonClass

Describe the bug
Anchors have different behaviors for static and dynamic elements.

To Reproduce

from pygame import Rect
from pygame_gui import UIManager
from pygame_gui.elements import UIButton


pygame.init()

pygame.display.set_caption('Quick Start')
window_surface = pygame.display.set_mode((800, 600))
manager = UIManager((800, 600))

background = pygame.Surface((800, 600))
background.fill((50, 50, 50))

clock = pygame.time.Clock()
is_running = True

window = pygame_gui.elements.UIWindow(rect=pygame.Rect((50, 50), (600, 300)),
                                                        manager=manager, resizable=True,
                                                        window_display_title='Static Dimensions')
hello_button = UIButton(Rect(-300, -150, -1, -1), 'Hello', container=window,
                                  anchors={'top': 'bottom',
                                           'left': 'right',
                                           'bottom': 'bottom',
                                           'right': 'right'})  # button that starts with dynamic dimensions
hello_button_2 = UIButton(Rect(-300, -150, hello_button.rect.width, hello_button.rect.height), 'Hello', container=window,
                                  anchors={'top': 'bottom',
                                           'left': 'right',
                                           'bottom': 'bottom',
                                           'right': 'right'})  # button starts with static dimensions

while is_running:
    time_delta = clock.tick(60)/1000.0
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            is_running = False

        manager.process_events(event)

    manager.update(time_delta)

    window_surface.blit(background, (0, 0))
    manager.draw_ui(window_surface)

    pygame.display.update()

Expected behaviour
The two buttons overlap.
I prefer the syntax of dynamic rectangles, so we don't have to subtract their width and height when passing relative-rect. So I hope to modify the anchor position of the static rectangle to match the dynamic rectangle.

Screenshots
T3H51YJ_9ITNJ3ADAV3PQ J

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions