Skip to content

Commit 605f56f

Browse files
eruvanospushfoo
andauthored
docs(gui): convert to google doc and little cleanup (#2305)
* docs(gui): convert to google doc and little cleanup * docs(gui): next round, document all the things * docs(gui): fix format * docs(gui): fix more format * docs(gui): fix more format * docs(gui): fix more format * docs(gui): fix more format, clean up color refs * docs(gui): re-add attr in UITextEvents * Fix phrasing in UIEvent docstring * Update docstrings for base class events * Remove extra whitespace line * Add missing Args for property.bind * Add missing Args for unbind * Use code-block and make a phrasing tweak to module-level bind function * Spacing? * Use code-block: python in odule-level unbind * Spacing in DictProperty top-level docstring * Spacing in ListProperty top-level docstring * Fix whitespace in surface.activate docstring * Rephrase for Surface's top-level docstring * Clean up and annotate Surface.activate * Formatting fix --------- Co-authored-by: pushfoo <36696816+pushfoo@users.noreply.github.com>
1 parent 47b343e commit 605f56f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1101
-770
lines changed

arcade/gui/constructs.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Constructs, are prepared widget combinations, you can use for common use-cases
3-
"""
1+
"""Constructs, are prepared widget combinations, you can use for common use-cases"""
42

53
from __future__ import annotations
64

@@ -16,8 +14,7 @@
1614

1715

1816
class UIMessageBox(UIMouseFilterMixin, UIAnchorLayout):
19-
"""
20-
A simple dialog box that pops up a message with buttons to close.
17+
"""A simple dialog box that pops up a message with buttons to close.
2118
Subclass this class or overwrite the 'on_action' event handler with
2219
2320
.. code-block:: python
@@ -27,11 +24,12 @@ class UIMessageBox(UIMouseFilterMixin, UIAnchorLayout):
2724
def on_action(event: UIOnActionEvent):
2825
pass
2926
27+
Args:
28+
width: Width of the message box
29+
height: Height of the message box
30+
message_text: Text to show as message to the user
31+
buttons: List of strings, which are shown as buttons
3032
31-
:param width: Width of the message box
32-
:param height: Height of the message box
33-
:param message_text: Text to show as message to the user
34-
:param buttons: List of strings, which are shown as buttons
3533
"""
3634

3735
def __init__(
@@ -100,19 +98,20 @@ def on_action(self, event: UIOnActionEvent):
10098

10199

102100
class UIButtonRow(UIBoxLayout):
103-
"""
104-
Places buttons in a row.
105-
106-
:param vertical: Whether the button row is vertical or not.
107-
:param align: Where to align the button row.
108-
:param size_hint: Tuple of floats (0.0 - 1.0) of how much space of the parent
109-
should be requested.
110-
:param size_hint_min: Min width and height in pixel.
111-
:param size_hint_max: Max width and height in pixel.
112-
:param space_between: The space between the children.
113-
:param style: Not used.
114-
:param Tuple[str, ...] button_labels: The labels for the buttons.
115-
:param callback: The callback function which will receive the text of the clicked button.
101+
"""Places buttons in a row.
102+
103+
Args:
104+
vertical: Whether the button row is vertical or not.
105+
align: Where to align the button row.
106+
size_hint: Tuple of floats (0.0 - 1.0) of how much space of the
107+
parent should be requested.
108+
size_hint_min: Min width and height in pixel.
109+
size_hint_max: Max width and height in pixel.
110+
space_between: The space between the children.
111+
callback: The callback function which will receive the text of
112+
the clicked button.
113+
button_factory: The factory to create the buttons. Default is py:class:`UIFlatButton`.
114+
**kwargs: Passed to UIBoxLayout
116115
"""
117116

118117
def __init__(
@@ -124,8 +123,8 @@ def __init__(
124123
size_hint_min: Optional[Any] = None,
125124
size_hint_max: Optional[Any] = None,
126125
space_between: int = 10,
127-
style: Optional[Any] = None,
128126
button_factory: type = UIFlatButton,
127+
**kwargs,
129128
):
130129
super().__init__(
131130
vertical=vertical,
@@ -134,7 +133,7 @@ def __init__(
134133
size_hint_min=size_hint_min,
135134
size_hint_max=size_hint_max,
136135
space_between=space_between,
137-
style=style,
136+
**kwargs,
138137
)
139138
self.register_event_type("on_action") # type: ignore # https://github.com/pyglet/pyglet/pull/1173 # noqa
140139

@@ -147,12 +146,20 @@ def add_button(
147146
style=None,
148147
multiline=False,
149148
):
149+
"""Add a button to the row.
150+
151+
Args:
152+
label: The text of the button.
153+
style: The style of the button.
154+
multiline: Whether the button is multiline or not.
155+
"""
150156
button = self.button_factory(text=label, style=style, multiline=multiline)
151157
button.on_click = self._on_click # type: ignore
152158
self.add(button)
153159
return button
154160

155161
def on_action(self, event: UIOnActionEvent):
162+
"""Called when button was pressed, override this method to handle button presses."""
156163
pass
157164

158165
def _on_click(self, event: UIOnClickEvent):

arcade/gui/events.py

Lines changed: 93 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,84 @@
33
from dataclasses import dataclass
44
from typing import Any
55

6+
from pyglet.math import Vec2
7+
68

79
@dataclass
810
class UIEvent:
9-
"""
10-
An event created by the GUI system. Can be passed using widget.dispatch("on_event", event).
11-
An event always has a source, which is the UIManager for general input events,
12-
but will be the specific widget in case of events like on_click events.
11+
"""An event created by the GUI system.
12+
13+
Can be passed as follows:
14+
15+
.. code-block:: python
16+
17+
widget.dispatch("on_event", event)
18+
19+
An event always has a source. This is the UIManager for general input
20+
events, but will be the specific widget in case of events like click
21+
events.
22+
23+
Args:
24+
source: The source of the event.
1325
"""
1426

1527
source: Any
1628

1729

1830
@dataclass
1931
class UIMouseEvent(UIEvent):
20-
"""
21-
Covers all mouse event
32+
"""Base class for all UI mouse events.
33+
34+
Args:
35+
x: The x coordinate of the mouse.
36+
y: The y coordinate of the mouse.
2237
"""
2338

2439
x: int
2540
y: int
2641

2742
@property
28-
def pos(self):
29-
return self.x, self.y
43+
def pos(self) -> Vec2:
44+
"""Return the position as tuple (x, y)"""
45+
return Vec2(self.x, self.y)
3046

3147

3248
@dataclass
3349
class UIMouseMovementEvent(UIMouseEvent):
34-
"""Triggered when the mouse is moved."""
50+
"""Triggered when the mouse is moved.
51+
52+
Args:
53+
dx: The change in x coordinate.
54+
dy: The change in y coordinate.
55+
"""
3556

3657
dx: int
3758
dy: int
3859

3960

4061
@dataclass
4162
class UIMousePressEvent(UIMouseEvent):
42-
"""Triggered when a mouse button(left, right, middle) is pressed."""
63+
"""Triggered when a mouse button(left, right, middle) is pressed.
64+
65+
Args:
66+
button: The button pressed.
67+
modifiers: The modifiers pressed.
68+
"""
4369

4470
button: int
4571
modifiers: int
4672

4773

4874
@dataclass
4975
class UIMouseDragEvent(UIMouseEvent):
50-
"""Triggered when the mouse moves while one of its buttons being pressed."""
76+
"""Triggered when the mouse moves while one of its buttons being pressed.
77+
78+
Args:
79+
dx: The change in x coordinate.
80+
dy: The change in y coordinate.
81+
buttons: The buttons pressed.
82+
modifiers: The modifiers pressed.
83+
"""
5184

5285
dx: int
5386
dy: int
@@ -57,23 +90,38 @@ class UIMouseDragEvent(UIMouseEvent):
5790

5891
@dataclass
5992
class UIMouseReleaseEvent(UIMouseEvent):
60-
"""Triggered when a mouse button is released."""
93+
"""Triggered when a mouse button is released.
94+
95+
Args:
96+
button: The button released.
97+
modifiers: The modifiers pressed
98+
"""
6199

62100
button: int
63101
modifiers: int
64102

65103

66104
@dataclass
67105
class UIMouseScrollEvent(UIMouseEvent):
68-
"""Triggered by rotating the scroll wheel on the mouse."""
106+
"""Triggered by rotating the scroll wheel on the mouse.
107+
108+
Args:
109+
scroll_x: The horizontal scroll amount.
110+
scroll_y: The vertical scroll
111+
"""
69112

70113
scroll_x: int
71114
scroll_y: int
72115

73116

74117
@dataclass
75118
class UIKeyEvent(UIEvent):
76-
"""Covers all keyboard event."""
119+
"""Base class for all keyboard-centric UI events.
120+
121+
Args:
122+
symbol: The key pressed.
123+
modifiers: The modifiers pressed.
124+
"""
77125

78126
symbol: int
79127
modifiers: int
@@ -114,46 +162,67 @@ class UITextInputEvent(UITextEvent):
114162
* a platform-specific input method, such as pen input on a tablet PC
115163
116164
To learn more, see pyglet's `relevant documentation <https://pyglet.readthedocs.io/en/development/modules/window.html#pyglet.window.Window.on_text>`_.
165+
166+
Args:
167+
text: The text inputted. Often a single character.
117168
"""
118169

119170
text: str
120171

121172

122173
@dataclass
123174
class UITextMotionEvent(UITextEvent):
124-
"""Triggered when text cursor moves."""
175+
"""Triggered when text cursor moves.
176+
177+
Args:
178+
motion: The motion of the cursor
179+
"""
125180

126181
motion: Any
127182

128183

129184
@dataclass
130185
class UITextMotionSelectEvent(UITextEvent):
131-
"""Triggered when the text cursor moves selecting the text with it."""
186+
"""Triggered when the text cursor moves selecting the text with it.
187+
188+
Args:
189+
selection: The selection of the cursor
190+
"""
132191

133192
selection: Any
134193

135194

136195
@dataclass
137196
class UIOnClickEvent(UIMouseEvent):
138-
"""Triggered when a widget is clicked."""
197+
"""Triggered when a widget is clicked.
198+
199+
Args:
200+
button: The button clicked.
201+
modifiers: The modifiers pressed.
202+
"""
139203

140204
button: int
141205
modifiers: int
142206

143207

144208
@dataclass
145209
class UIOnUpdateEvent(UIEvent):
146-
"""
147-
Arcade on_update callback passed as :class:`UIEvent`
210+
"""Arcade on_update callback passed as :class:`UIEvent`.
211+
212+
Args:
213+
dt: Time since last update
148214
"""
149215

150216
dt: int
151217

152218

153219
@dataclass
154220
class UIOnChangeEvent(UIEvent):
155-
"""
156-
Value of a widget changed
221+
"""Value of a widget changed.
222+
223+
Args:
224+
old_value: The old value.
225+
new_value: The new value.
157226
"""
158227

159228
old_value: Any
@@ -162,10 +231,10 @@ class UIOnChangeEvent(UIEvent):
162231

163232
@dataclass
164233
class UIOnActionEvent(UIEvent):
165-
"""
166-
Notification about an action
234+
"""Notification about an action.
167235
168-
:param action: Value describing the action, mostly a string
236+
Args:
237+
action: Value describing the action, mostly a string
169238
"""
170239

171240
action: Any

arcade/gui/examples/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
This package contains GUI specific examples.
1+
"""This package contains GUI specific examples.
32
43
These show explicit GUI examples, and are not part of the main examples.
54

arcade/gui/examples/anchor_layout.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Positioning UI elements with UIAnchorLayout
1+
"""Positioning UI elements with UIAnchorLayout
32
43
UIAnchorLayout aligns widgets added to it to directional anchors, which
54
include "left", "center_x", or "top". Dummy widgets react to click events

arcade/gui/examples/box_layout.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Arrange widgets in vertical or horizontal lines with UIBoxLayout
1+
"""Arrange widgets in vertical or horizontal lines with UIBoxLayout
32
43
The direction UIBoxLayout follows is controlled by the `vertical` keyword
54
argument. It is True by default. Pass False to it to arrange elements in

arcade/gui/examples/button_with_text.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Customizing buttons with text & textures.
1+
"""Customizing buttons with text & textures.
32
43
This example showcases arcade's range of different built-in button types
54
and how they can be used to customize a UI. A UIGridLayout is used to

arcade/gui/examples/dropdown.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Creating a dropdown menu with UIDropDown
1+
"""Creating a dropdown menu with UIDropDown
32
43
When an option in the UIDropDown is chosen, this example will respond
54
by changing the text displayed on screen to reflect it.
@@ -30,7 +29,7 @@ def __init__(self):
3029
self.dropdown.center_on_screen()
3130
self.ui.add(self.dropdown)
3231

33-
self.label = self.ui.add(UILabel(text=" ", text_color=(0, 0, 0)))
32+
self.label = self.ui.add(UILabel(text=" ", text_color=arcade.color.BLACK))
3433

3534
@self.dropdown.event()
3635
def on_change(event: UIOnChangeEvent):

arcade/gui/examples/exp_hidden_password.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Creating a hidden password field
1+
"""Creating a hidden password field
32
43
This example demonstrates how to create a custom text input
54
which hides the contents behind a custom character, as often

arcade/gui/examples/exp_scroll_area.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
This example is a proof-of-concept for a UIScrollArea.
1+
"""This example is a proof-of-concept for a UIScrollArea.
32
43
You can currently scroll through the UIScrollArea in the following ways:
54

0 commit comments

Comments
 (0)