Arcade Game Development Library
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete user interface framework with widgets, layouts, event handling, styling, and theming for creating game menus, HUDs, and interactive interfaces.
class UIManager:
"""
Main UI manager for handling GUI elements, events, and rendering.
"""
def __init__(self, window: arcade.Window = None):
"""Create UI manager for window."""
def add(self, widget: arcade.gui.UIWidget) -> None:
"""Add widget to manager."""
def remove(self, widget: arcade.gui.UIWidget) -> None:
"""Remove widget from manager."""
def clear(self) -> None:
"""Remove all widgets."""
def on_draw(self) -> None:
"""Draw all widgets."""
def on_update(self, delta_time: float) -> None:
"""Update widgets."""
class UIView(arcade.View):
"""
View with built-in UI manager for easy GUI integration.
"""
def __init__(self):
super().__init__()
self.ui_manager = arcade.gui.UIManager()
class UIWidget:
"""
Base widget class for all GUI elements.
"""
def __init__(self, x: float = 0, y: float = 0, width: float = 100, height: float = 100):
"""Create base widget."""
x: float
y: float
width: float
height: float
visible: bool
def on_draw(self) -> None:
"""Draw the widget."""
def on_update(self, delta_time: float) -> None:
"""Update widget logic."""
class UIInteractiveWidget(UIWidget):
"""
Base class for interactive widgets that handle events.
"""
def on_click(self, event: arcade.gui.UIOnClickEvent) -> None:
"""Handle click events."""
def on_hover(self, event: arcade.gui.UIMouseEvent) -> None:
"""Handle hover events."""class UIFlatButton(UIInteractiveWidget):
"""
Flat-style button widget with text and click handling.
"""
def __init__(self, text: str = "Button", x: float = 0, y: float = 0,
width: float = 100, height: float = 50,
style: dict = None):
"""Create flat button."""
text: str
style: dict
def on_click(self, event: arcade.gui.UIOnClickEvent) -> None:
"""Handle button click."""
class UITextureButton(UIInteractiveWidget):
"""
Button widget using textures for different states.
"""
def __init__(self, x: float = 0, y: float = 0,
texture: arcade.Texture = None,
texture_hovered: arcade.Texture = None,
texture_pressed: arcade.Texture = None):
"""Create texture button."""
texture: arcade.Texture
texture_hovered: arcade.Texture
texture_pressed: arcade.Textureclass UILayout(UIWidget):
"""
Base layout widget for organizing child widgets.
"""
def add(self, widget: UIWidget) -> None:
"""Add child widget to layout."""
def remove(self, widget: UIWidget) -> None:
"""Remove child widget."""
class UIBoxLayout(UILayout):
"""
Linear layout (horizontal or vertical).
"""
def __init__(self, vertical: bool = True, align: str = "center", space_between: int = 0):
"""Create box layout."""
vertical: bool
align: str
space_between: int
class UIGridLayout(UILayout):
"""
Grid-based layout with rows and columns.
"""
def __init__(self, column_count: int = 1, row_count: int = 1):
"""Create grid layout."""
column_count: int
row_count: intclass UILabel(UIWidget):
"""
Text label widget for displaying static text.
"""
def __init__(self, text: str = "Label", x: float = 0, y: float = 0,
font_name: str = "Arial", font_size: int = 16,
text_color: tuple = (255, 255, 255, 255)):
"""Create text label."""
text: str
font_name: str
font_size: int
text_color: tuple
class UIInputText(UIInteractiveWidget):
"""
Text input field for user text entry.
"""
def __init__(self, x: float = 0, y: float = 0, width: float = 200,
text: str = "", placeholder: str = ""):
"""Create text input."""
text: str
placeholder: str
cursor_position: int
def on_text(self, text: str) -> None:
"""Handle text input."""class UIEvent:
"""Base UI event class."""
pass
class UIOnClickEvent(UIEvent):
"""Click event with position and button info."""
x: int
y: int
button: int
class UIOnChangeEvent(UIEvent):
"""Value change event for inputs."""
old_value: object
new_value: object
class UIMouseEvent(UIEvent):
"""Mouse event with position and movement."""
x: int
y: int
dx: int
dy: intimport arcade
import arcade.gui
class MenuView(arcade.gui.UIView):
def __init__(self):
super().__init__()
self.setup_ui()
def setup_ui(self):
# Create vertical layout
v_box = arcade.gui.UIBoxLayout(vertical=True, space_between=20)
# Title
title = arcade.gui.UILabel("Game Menu", font_size=32)
v_box.add(title)
# Buttons
start_button = arcade.gui.UIFlatButton("Start Game", width=200)
start_button.on_click = self.on_start_click
v_box.add(start_button)
options_button = arcade.gui.UIFlatButton("Options", width=200)
v_box.add(options_button)
quit_button = arcade.gui.UIFlatButton("Quit", width=200)
quit_button.on_click = self.on_quit_click
v_box.add(quit_button)
# Add layout to UI manager
self.ui_manager.add(v_box)
def on_start_click(self, event):
game_view = GameView()
self.window.show_view(game_view)
def on_quit_click(self, event):
arcade.exit()
def on_draw(self):
self.clear()
self.ui_manager.on_draw()
def main():
window = arcade.Window(800, 600, "GUI Example")
menu = MenuView()
window.show_view(menu)
arcade.run()
if __name__ == "__main__":
main()Install with Tessl CLI
npx tessl i tessl/pypi-arcade