Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic expansion of UIScrollingContainer in x & y dimensions simultaneously - breaks the scroll bars. #643

Open
Matteo-Barberis opened this issue Oct 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Matteo-Barberis
Copy link

Matteo-Barberis commented Oct 29, 2024

PLEASE HELP ME IT WILL TAKE YOU ONE SECOND. IT'S A YES OR NO ANSWER.

What I want is simple: a container that stores items and allows me to scroll through them without any issues. It seems like a straightforward requirement, so I’m puzzled as to why I can’t find a solution.

I am trying to add components inside a window or container, and I want a scrollbar to be generated when those components exceed the available vertical space. So far, everything seems to be set up correctly, but the scrollbar is not functioning as expected—it goes out of bounds when i reach the end of the container and appears quite buggy.

Can the library support something like this? I've tried everything.

import pygame
import pygame_gui

pygame.init()
window = pygame.display.set_mode((800, 600))
manager = pygame_gui.UIManager((800, 600))

container = pygame_gui.elements.UIScrollingContainer(
    relative_rect=pygame.Rect((50, 50), (300, 400)),
    manager=manager
)

for i in range(20):
    pygame_gui.elements.UILabel(
        relative_rect=pygame.Rect((0, i * 35), (280, 30)),
        text=f"Item {i+1}",
        manager=manager,
        container=container
    )

clock = pygame.time.Clock()
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        manager.process_events(event)

    manager.update(clock.tick(60)/1000.0)
    window.fill((128, 128, 128))
    manager.draw_ui(window)
    pygame.display.update()
@MyreMylar
Copy link
Owner

MyreMylar commented Nov 10, 2024

Hi there. I would try adding:

should_grow_automatically=True,
allow_scroll_x=False,

To the parameters of the UIScrollingContainer. It looks like the code to expand the container automatically - added in the last version - doesn't work when it expands in both x and y simultaneously.

I'll see if I can fix it, but I'm less familiar with this code as I didn't write it.

@MyreMylar MyreMylar added the bug Something isn't working label Nov 10, 2024
@MyreMylar MyreMylar changed the title For the love of God this should be really easy, is it impossible to achieve? Scrollbar Goes Out of Bounds in Pygame GUI Container Automatic expansion of UIScrollingContainer in x & y dimensions simultaneously - breaks the scroll bars. Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants