1
0
Fork 0

Add ability to configure font settings

This commit is contained in:
Michał Rudowicz 2024-09-10 18:27:31 +02:00
parent b002dfcf4f
commit 8fb38ee0fd
2 changed files with 7 additions and 3 deletions

View File

@ -41,6 +41,10 @@
"message_text_color": "#2e3440", "message_text_color": "#2e3440",
"btn_bg_color": "#d8dee9", "btn_bg_color": "#d8dee9",
"btn_hover_color": "#eceff4", "btn_hover_color": "#eceff4",
"btn_text_color": "#2e3440" "btn_text_color": "#2e3440",
"btn_font_face": "Sans",
"btn_font_size": "20",
"message_font_face": "Sans",
"message_font_size": "40"
} }
} }

View File

@ -45,7 +45,7 @@ class Button:
self.text = text self.text = text
self.theme = theme self.theme = theme
self.cbk = cbk self.cbk = cbk
self.font = pygame.freetype.SysFont(name="Sans", size=20) self.font = pygame.freetype.SysFont(name=theme["btn_font_face"], size=int(theme["btn_font_size"]))
text_rect = self.font.get_rect(self.text) text_rect = self.font.get_rect(self.text)
self.text_pos = pygame.Rect((self.position.left + (self.position.width - text_rect.width)/2), self.text_pos = pygame.Rect((self.position.left + (self.position.width - text_rect.width)/2),
(self.position.top + (self.position.height - text_rect.height)/2), (self.position.top + (self.position.height - text_rect.height)/2),
@ -104,7 +104,7 @@ class Button:
class MessageBoard(IBoard): class MessageBoard(IBoard):
def __init__(self, screen_rect: pygame.Rect, text: str, theme: Dict): def __init__(self, screen_rect: pygame.Rect, text: str, theme: Dict):
self.text = text self.text = text
self.font = pygame.freetype.SysFont(name="Sans", size=30) self.font = pygame.freetype.SysFont(name=theme["message_font_face"], size=int(theme["message_font_size"]))
text_rect = self.font.get_rect(self.text) text_rect = self.font.get_rect(self.text)
self.text_pos = pygame.Rect((screen_rect.left + (screen_rect.width - text_rect.width)/2), self.text_pos = pygame.Rect((screen_rect.left + (screen_rect.width - text_rect.width)/2),
(screen_rect.top + (screen_rect.height - text_rect.height)/2), (screen_rect.top + (screen_rect.height - text_rect.height)/2),