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

scrolling an image in container #17

Open
non-npc opened this issue Aug 22, 2024 · 0 comments
Open

scrolling an image in container #17

non-npc opened this issue Aug 22, 2024 · 0 comments

Comments

@non-npc
Copy link

non-npc commented Aug 22, 2024

i cant seem to get images to scroll in a container, any ideas or examples?
the scrollbars appear but when i click them nothing happens, i was expecting it work like like the scrolling text example.

   # Initialize Pygame and create the window
    pygame.init()
    window_surface = pygame.display.set_mode(WINDOW_SIZE)
    ui_manager = pygame_gui.UIManager(WINDOW_SIZE)

    # Create the UIScrollingContainer for the scrollable image area
    container_rect = pygame.Rect(COLUMN_1_WIDTH, 0, COLUMN_2_WIDTH, WINDOW_SIZE[1])
    scrolling_container = UIScrollingContainer(container_rect, manager=ui_manager)

    while running:
        dt = clock.tick(60) / 1000.0
        window_surface.fill(background_color)

        # Handle events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

            ui_manager.process_events(event)

        # Update the UI manager
        ui_manager.update(dt)

        # Draw the content within the scrolling container
        if current_image_surface:
            scrolling_container.get_container().clear()
            if is_animating and current_gif_frames:
                animation_timer += dt * 1000  # Convert dt to milliseconds
                if animation_timer >= animation_speed:
                    animation_timer = 0
                    current_gif_index = (current_gif_index + 1) % len(current_gif_frames)
                    current_image_surface = current_gif_frames[current_gif_index]
            zoomed_surface = pygame.transform.rotozoom(current_image_surface, 0, current_zoom)
            image_rect = zoomed_surface.get_rect()

            # Adjust the scrollable area size to match the image size
            scrolling_container.set_scrollable_area_dimensions((image_rect.width, image_rect.height))
            
            
            
            # Add the UIImage to the scrolling container (re-create each frame for simplicity)
            UIImage(relative_rect=pygame.Rect((0, 0), (image_rect.width, image_rect.height)),
                    image_surface=zoomed_surface,
                    manager=ui_manager,
                    container=scrolling_container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant