Skip to content

Commit

Permalink
The library was hardcoded to global constants, made it rely on the ar…
Browse files Browse the repository at this point in the history
…guments
  • Loading branch information
RickMMA committed Feb 8, 2024
1 parent 440d50d commit 531ba56
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions menu_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# from pygame.locals import * # not using it right now

class Button():
def __init__(self, surface, pos, size = (200, 60), color = BLUE, text = ""):
def __init__(self, surface, pos, size = (200, 60), color = (0, 0, 255), text = "", font = ""):
"""
surface -> pygame.Surface
Surface where to put the button.
Expand All @@ -20,7 +20,8 @@ def __init__(self, surface, pos, size = (200, 60), color = BLUE, text = ""):
self.surface = surface
self.text = text
# self.text_size = text_size
self.font = pygame.font.SysFont(None, 40)
# self.font = pygame.font.SysFont(None, 40)
self.font = font
# self.padding = (15, self.font.get_height()-5)
self.padding = (0, 0)
# font.get_height() is not equal to font.size()
Expand All @@ -35,7 +36,7 @@ def render(self):
self.button.fill( (self.color[0], self.color[1], self.color[2]) )
self.surface.blit(self.button, (self.x - self.padding[0], self.y - self.padding[1]))

f = self.font.render(self.text, True, WHITE)
f = self.font.render(self.text, True, (255, 255, 255))
f_size = f.get_size()
btn_width = self.button.get_width()
btn_height = self.button.get_height()
Expand All @@ -44,4 +45,4 @@ def render(self):
# TODO: make conditional to choose pos of text
x = ((btn_width//2) - (f_size[0]//2)) + self.x
y = ((btn_height//2) - (f_size[1]//2)) + self.y
DISPLAYSURFACE.blit(f, (x, y))
self.surface.blit(f, (x, y))

0 comments on commit 531ba56

Please sign in to comment.