pg: Padding in TextButton() is now a tuple to specify the padding for x and y.
This commit is contained in:
parent
6fb6280bad
commit
e106d87d6d
1 changed files with 5 additions and 5 deletions
10
pg.py
10
pg.py
|
@ -97,13 +97,13 @@ class Button:
|
||||||
|
|
||||||
|
|
||||||
class TextButton:
|
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 = text
|
||||||
self.text_color = text_color
|
self.text_color = text_color
|
||||||
self.font = font
|
self.font = font
|
||||||
|
|
||||||
self.text_object = self.generate_text(text)
|
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.surface = surface
|
||||||
self.function = function
|
self.function = function
|
||||||
|
@ -129,11 +129,11 @@ class TextButton:
|
||||||
|
|
||||||
def generate_background(self):
|
def generate_background(self):
|
||||||
w, h = self.text_object.get_size()
|
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))
|
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:
|
if new_text is None:
|
||||||
new_text = self.text
|
new_text = self.text
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ class TextButton:
|
||||||
|
|
||||||
self.text_object = self.generate_text(new_text)
|
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
|
new_callable_pos = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue