From e106d87d6d46f9544daf37b1d8ec64613b1c5555 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sun, 12 Nov 2023 15:30:20 +0100 Subject: [PATCH] pg: Padding in TextButton() is now a tuple to specify the padding for x and y. --- pg.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pg.py b/pg.py index 711eae9..c978cc6 100644 --- a/pg.py +++ b/pg.py @@ -97,13 +97,13 @@ 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): + 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: tuple=(8, 8)): 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.size = (self.text_object.get_width() + padding[0] * 2, self.text_object.get_height() + padding[1] * 2) self.surface = surface self.function = function @@ -129,11 +129,11 @@ class TextButton: def generate_background(self): w, h = self.text_object.get_size() - w, h = w + self.padding * 2, h + self.padding * 2 + w, h = w + self.padding[0] * 2, h + self.padding[1] * 2 return pygame.Rect(self.position, (w, h)) - def update(self, new_text: str=None, new_pos: Union[tuple, Callable]=None, new_surface: pygame.Surface=None, new_func=None, new_key: int=None, new_text_color: tuple=None, new_bg_color: tuple=None, new_font: pygame.font.Font=None, new_padding: int=None): + def update(self, new_text: str=None, new_pos: Union[tuple, Callable]=None, new_surface: pygame.Surface=None, new_func=None, new_key: int=None, new_text_color: tuple=None, new_bg_color: tuple=None, new_font: pygame.font.Font=None, new_padding: tuple=None): if new_text is None: new_text = self.text @@ -157,7 +157,7 @@ class TextButton: self.text_object = self.generate_text(new_text) - self.size = (self.text_object.get_width() + self.padding * 2, self.text_object.get_height() + self.padding * 2) + self.size = (self.text_object.get_width() + self.padding[0] * 2, self.text_object.get_height() + self.padding[1] * 2) new_callable_pos = None