pygame_gui
pygame_gui copied to clipboard
Add tab containers
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
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
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
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.
Currently looks like this:
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!