-
Notifications
You must be signed in to change notification settings - Fork 86
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
set_dimensions now support dynamic sizes #514
set_dimensions now support dynamic sizes #514
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #514 +/- ##
==========================================
- Coverage 95.71% 95.62% -0.10%
==========================================
Files 84 84
Lines 11676 11788 +112
==========================================
+ Hits 11176 11272 +96
- Misses 500 516 +16 ☔ View full report in Codecov by Sentry. |
I have tested this with a small program and using Test program to compare: import pygame
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))
hello_button = UIButton(Rect(350, 280, 100, 30), 'Hello') # button starts with static dimensions
hello_button_2 = UIButton(Rect(350, 180, -1, -1), 'Hello') # button that starts with dynamic dimensions
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
if event.type == pygame.KEYDOWN and event.key == pygame.K_d:
hello_button.set_dimensions((-1, -1)) # press 'd' to convert to dynamic dimensions
if event.type == pygame.KEYDOWN and event.key == pygame.K_s:
hello_button.set_text("Long string of text") # press 's' and 'a' to toggle text in the buttons
hello_button_2.set_text("Long string of text")
if event.type == pygame.KEYDOWN and event.key == pygame.K_a:
hello_button.set_text("Hello")
hello_button_2.set_text("Hello")
manager.process_events(event)
manager.update(time_delta)
window_surface.blit(background, (0, 0))
manager.draw_ui(window_surface)
pygame.display.update() |
@MyreMylar This may disrupt the previous code, causing the element to become dynamic unexpectedly. (For example, when an error occurs and a negative value is passed in) |
I think that is a risk that we have to take given the API of passing in -1 to indicate a dynamic dimension. The alternative would be adding some keyword only parameters that override whatever is specified in the dimensions e.g:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, LGTM 👍
Works how I would expect now.
Fixes #498