diff --git a/wobbl_tools/_examples/__init__.py b/wobbl_tools/_examples/__init__.py new file mode 100644 index 0000000..a93a4bf --- /dev/null +++ b/wobbl_tools/_examples/__init__.py @@ -0,0 +1 @@ +#!/usr/bin/python3 diff --git a/wobbl_tools/_examples/pgui/__init__.py b/wobbl_tools/_examples/pgui/__init__.py new file mode 100644 index 0000000..a93a4bf --- /dev/null +++ b/wobbl_tools/_examples/pgui/__init__.py @@ -0,0 +1 @@ +#!/usr/bin/python3 diff --git a/wobbl_tools/_examples/pgui/pgui.py b/wobbl_tools/_examples/pgui/pgui.py new file mode 100644 index 0000000..413580b --- /dev/null +++ b/wobbl_tools/_examples/pgui/pgui.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 + +import pygame +from wobbl_tools.pygame_tools.pgui.widgets import Container +from wobbl_tools.pygame_tools.pgui.page_system import PageManager, Page + + +class MainMenu(Page): + def update(self): + pass + + +class PGUIExample: + def __init__(self): + pygame.init() + + self.screen = pygame.display.set_mode((800, 600), flags=pygame.RESIZABLE) + + self.clock = pygame.time.Clock() + + self.pages = PageManager(self) + self.pages += MainMenu(self, main_container=Container()) + + self.pages.current_page = "MainMenu" + + def tick(self): + self.handle_events() + + self.draw() + + pygame.display.flip() + + self.clock.tick(60) + + def draw(self): + self.screen.fill((40, 40, 40)) + self.pages.draw(self.screen) + + def handle_events(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + exit() + + elif event.type == pygame.VIDEORESIZE: # on window resize + self.pages.update() + + +if __name__ == "__main__": + app = PGUIExample() + + while True: + app.tick() diff --git a/wobbl_tools/pygame_tools/pgui/widgets/__init__.py b/wobbl_tools/pygame_tools/pgui/widgets/__init__.py index ecf7241..92760dd 100644 --- a/wobbl_tools/pygame_tools/pgui/widgets/__init__.py +++ b/wobbl_tools/pygame_tools/pgui/widgets/__init__.py @@ -1,2 +1,8 @@ #!/usr/bin/python3 +from .button import Button +from .container import Container +from .hover import Hover +from .multiline_text import MultilineText +from .text_button import TextButton +from .text_input import TextInput diff --git a/wobbl_tools/pygame_tools/pgui/widgets/_any_widget.py b/wobbl_tools/pygame_tools/pgui/widgets/_any_widget.py new file mode 100644 index 0000000..14e8eed --- /dev/null +++ b/wobbl_tools/pygame_tools/pgui/widgets/_any_widget.py @@ -0,0 +1,12 @@ +#!/usr/bin/python3 + +from typing import Union + +any_widget = Union[ + "Button", + "Container", + "Hover", + "MultilineText", + "TextButton", + "TextInput" +] diff --git a/wobbl_tools/pygame_tools/pgui/widgets/button.py b/wobbl_tools/pygame_tools/pgui/widgets/button.py index dbd071b..08ab406 100644 --- a/wobbl_tools/pygame_tools/pgui/widgets/button.py +++ b/wobbl_tools/pygame_tools/pgui/widgets/button.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 from wobbl_tools.pygame_tools.utils import * -from wobbl_tools.pygame_tools.pgui.widgets import Hover +from .hover import Hover class Button: diff --git a/wobbl_tools/pygame_tools/pgui/widgets/container.py b/wobbl_tools/pygame_tools/pgui/widgets/container.py new file mode 100644 index 0000000..0eeb0b6 --- /dev/null +++ b/wobbl_tools/pygame_tools/pgui/widgets/container.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 + +import pygame +from ._any_widget import any_widget + + +class Container: + """ + A Container is a widget similar to a