Made the TextButton a pygame.sprite.Sprite.
This commit is contained in:
parent
67424f067f
commit
9121342bff
1 changed files with 5 additions and 3 deletions
8
pg.py
8
pg.py
|
@ -74,11 +74,13 @@ class Button:
|
|||
return False
|
||||
|
||||
|
||||
class TextButton:
|
||||
class TextButton(pygame.sprite.Sprite):
|
||||
"""
|
||||
Creates a button from just some string and a position.
|
||||
"""
|
||||
def __init__(self, text: str, position: tuple, function=None, args: tuple=None, key: int=0, text_color: tuple=white, bg_color: tuple=gray, font: pygame.font.Font=default_font, padding: tuple=(8, 8), border_radius: int=0, line_thickness: int = 0):
|
||||
pygame.sprite.Sprite.__init__(self)
|
||||
|
||||
self.text = text
|
||||
self.position = position
|
||||
self.text_color = text_color
|
||||
|
@ -91,7 +93,7 @@ class TextButton:
|
|||
self.border_radius = border_radius
|
||||
self.line_thickness = line_thickness
|
||||
|
||||
self.surface, self.size = self.generate_surface()
|
||||
self.image, self.size = self.generate_surface()
|
||||
self.rect = self.make_rect()
|
||||
|
||||
self.button = Button(self.rect, self.function, args, self.key)
|
||||
|
@ -113,7 +115,7 @@ class TextButton:
|
|||
return pygame.Rect(self.position, self.size)
|
||||
|
||||
def draw(self, surface: pygame.Surface):
|
||||
surface.blit(self.surface, self.position)
|
||||
surface.blit(self.image, self.position)
|
||||
|
||||
def check(self, mouse_pos, pressed):
|
||||
return self.button.check(mouse_pos, pressed)
|
||||
|
|
Loading…
Reference in a new issue