diff --git a/menu.py b/menu.py index 5a8d727..e9a1fac 100644 --- a/menu.py +++ b/menu.py @@ -11,6 +11,7 @@ import pygame.freetype class ButtonDef(TypedDict): text: str + cbk: Callable[[], None] class IBoard: @@ -68,7 +69,7 @@ class MenuBoard(IBoard): button_positions = self.generate_button_positions(screen_rect) self.buttons = list(map(lambda d: Button(next(button_positions), f"Button {d['text']}", - lambda: print(d['text'])), buttons)) + d['cbk']), buttons)) def generate_button_positions(self, screen_rect: pygame.Rect): current_button_row = 0 @@ -102,8 +103,9 @@ class App: self.screen = pygame.display.set_mode((info.current_w, info.current_h), flags=pygame.FULLSCREEN) self.clock = pygame.time.Clock() self.running = False - self.board: IBoard = MenuBoard(pygame.Rect(0, 0, info.current_w, info.current_h), - list(map(lambda t: ButtonDef(text=f"{t}"), list(range(btns))))) + buttons = list(map(lambda t: ButtonDef(text=f"{t}", cbk=lambda: print(t)), list(range(btns)))) + buttons.append(ButtonDef(text="Exit", cbk=self.quit)) + self.board: IBoard = MenuBoard(pygame.Rect(0, 0, info.current_w, info.current_h), buttons) def loop(self): self.running = True @@ -122,6 +124,9 @@ class App: self.clock.tick(30) pygame.quit() + def quit(self): + self.running = False + if __name__ == '__main__': app = App(int(sys.argv[1]))