Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arcade/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
from arcade.gui.events import UITextEvent
from arcade.gui.events import UITextMotionEvent
from arcade.gui.events import UITextMotionSelectEvent
from arcade.gui.events import UIOnActionEvent
from arcade.gui.surface import Surface
from arcade.gui.ui_manager import UIManager
from arcade.gui.widgets.layout import (
UIBoxLayout,
UIAnchorLayout,
UIGridLayout,
UILayout,
UIButtonRow,
)
from arcade.gui.widgets import UIDummy, Rect
from arcade.gui.widgets import UIInteractiveWidget
Expand All @@ -42,6 +44,7 @@
__all__ = [
"UIAnchorLayout",
"UIBoxLayout",
"UIButtonRow",
"UIGridLayout",
"UIManager",
"UIMessageBox",
Expand All @@ -65,6 +68,7 @@
"UIMousePressEvent",
"UIMouseReleaseEvent",
"UIMouseScrollEvent",
"UIOnActionEvent",
"UIOnUpdateEvent",
"UIOnChangeEvent",
"UIOnClickEvent",
Expand Down
5 changes: 5 additions & 0 deletions arcade/gui/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ class UIOnChangeEvent(UIEvent):

old_value: Any
new_value: Any


@dataclass
class UIOnActionEvent(UIMouseEvent):
pass
53 changes: 52 additions & 1 deletion arcade/gui/widgets/layout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Iterable, TypeVar, Tuple
from typing import Iterable, TypeVar, Tuple, Any, Callable

from arcade.gui.property import bind
from arcade.gui.widgets import UIWidget, UILayout
from arcade.gui.widgets.buttons import UIFlatButton
from arcade.gui.events import UIOnActionEvent, UIOnClickEvent

W = TypeVar("W", bound="UIWidget")

Expand Down Expand Up @@ -545,3 +547,52 @@ def do_layout(self):
child.rect = new_rect

start_y -= max_height_row


class UIButtonRow(UIBoxLayout):
"""
Places buttons in a row.

:param bool vertical: Whether the button row is vertical or not.
:param str align: Where to align the button row.
:param Any size_hint: Tuple of floats (0.0 - 1.0) of how much space of the parent should be requested.
:param size_hint_min: Min width and height in pixel.
:param size_hint_max: Max width and height in pixel.
:param int space_between: The space between the children.
:param Any style: Not used.
"""
def __init__(
self,
vertical: bool = False,
align: str = "center",
size_hint: Any = (0, 0),
size_hint_min: Any = None,
size_hint_max: Any = None,
space_between: int = 10,
style: Any = None,
):
super().__init__(
vertical=vertical,
align=align,
size_hint=size_hint,
size_hint_min=size_hint_min,
size_hint_max=size_hint_max,
space_between=space_between,
style=style
)
self.register_event_type("on_action")

def add_button(self, label: str, *, on_click: Callable = None, style: Any = None) -> None:
button = UIFlatButton(text=label, style=style)
button.on_click = self._on_click # type: ignore
self.add(button)

if on_click:
# Add on_click callback as event handler
button.event("on_click")(on_click)

def on_action(self, event: UIOnActionEvent) -> None:
pass

def _on_click(self, event: UIOnClickEvent) -> None:
self.dispatch_event("on_action", UIOnActionEvent(self, event.source, event.source.text))