Pygame: Made it possible to pass a function as position for an text button to automatically update the position.
This commit is contained in:
parent
57ded2ff83
commit
95c6346d26
1 changed files with 7 additions and 6 deletions
13
pg.py
13
pg.py
|
@ -98,23 +98,24 @@ class Button:
|
|||
|
||||
class TextButton:
|
||||
def __init__(self, text: str, position: Union[tuple, Callable], surface: pygame.Surface, function=None, key: int=0, text_color: tuple=white, bg_color: tuple=gray, font: pygame.font.Font=default_font, padding: int=8):
|
||||
self.text_object = self.generate_text(text)
|
||||
|
||||
self.text = text
|
||||
self.text_color = text_color
|
||||
self.font = font
|
||||
|
||||
self.text_object = self.generate_text(text)
|
||||
self.size = (self.text_object.get_width() + padding * 2, self.text_object.get_height() + padding * 2)
|
||||
|
||||
self.surface = surface
|
||||
self.function = function
|
||||
self.text_color = text_color
|
||||
self.bg_color = bg_color
|
||||
self.font = font
|
||||
self.padding = padding
|
||||
|
||||
self.callable_position = None
|
||||
|
||||
if position is int:
|
||||
self.position = position
|
||||
|
||||
else:
|
||||
self.position = position()
|
||||
self.position = position(size=self.size)
|
||||
self.callable_position = position
|
||||
|
||||
self.background = self.generate_background()
|
||||
|
|
Loading…
Reference in a new issue