pygame_gui icon indicating copy to clipboard operation
pygame_gui copied to clipboard

Add tab containers

Open LondonClass opened this issue 11 months ago • 1 comments

Desired features A tab container that can switch between different windows by clicking on the tab.

Sample code

import pygame

from pygame_gui import UIManager, UI_BUTTON_PRESSED
from pygame_gui.elements import UIButton, UITabContainer

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(manager.ui_theme.get_colour('dark_bg'))

tab_container = UITabContainer(relative_rect=pygame.Rect(50, 50, 700, 500), manager=manager)

container_1 = tab_container.get_container(tab_container.add_tab("Tab1"))
container_2 = tab_container.get_container(tab_container.add_tab("Tab2"))

hello_button_1 = UIButton((250, 180), 'Hello1', container=container_1, command=lambda: print("Hello1!"))
hello_button_2 = UIButton((350, 280), 'Hello2', container=container_2, command=lambda: print("Hello2!"))

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

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()

Screenshot 7QDW1CH1SH4B@9WFWIYZ`XI

I still don't quite understand what features I want and what interfaces should be opened. So I send the PR and see what everyone thinks.

Fixes #102

LondonClass avatar Mar 04 '24 11:03 LondonClass

Codecov Report

Attention: Patch coverage is 22.00000% with 117 lines in your changes are missing coverage. Please review.

Project coverage is 95.34%. Comparing base (e7a9dd5) to head (fe0f020).

:exclamation: Current head fe0f020 differs from pull request most recent head 15cc2ba. Consider uploading reports for the commit 15cc2ba to get more accurate results

Files Patch % Lines
pygame_gui/elements/ui_tab_container.py 19.71% 114 Missing :warning:
pygame_gui/core/drawable_shapes/drawable_shape.py 50.00% 2 Missing :warning:
pygame_gui/elements/ui_button.py 66.66% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #529      +/-   ##
==========================================
- Coverage   96.33%   95.34%   -0.99%     
==========================================
  Files          88       89       +1     
  Lines       13013    13159     +146     
==========================================
+ Hits        12536    12547      +11     
- Misses        477      612     +135     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 04 '24 11:03 codecov[bot]

Currently looks like this:

image

I'm going to merge it - tagged in the API docs as experimental, we'll see how people get on with it and see if anythign needs tweaking.

Thanks for the PR!

MyreMylar avatar Apr 11 '24 19:04 MyreMylar