Skip to content

Commit 7eaaf44

Browse files
committed
Squashed commit of the following:
commit 0e8403a Author: A. J. Andrews <86714785+DragonMoffon@users.noreply.github.com> Date: Sun Sep 15 23:19:50 2024 +1200 fixed small issue with sprite size property commit 851821b Author: DigiDuncan <digiduncan@gmail.com> Date: Sun Sep 15 04:23:07 2024 -0400 add .tracking and px -> em conversion (#2365) * add .tracking and px -> em conversion * I hate Sphinx It's coarse, and rough, and irritating, and it gets everywhere. * fix docs commit 4ff2f0f Author: DigiDuncan <digiduncan@gmail.com> Date: Sun Sep 15 01:27:23 2024 -0400 add __all__ to InputManger (#2366) commit 895bf57 Author: bump_version <bump-version@version.com> Date: Sun Sep 8 01:01:14 2024 +0000 Version 3.0.0-dev.36 [skip ci] commit 5c4bc93 Author: Einar Forselv <eforselv@gmail.com> Date: Sun Sep 8 01:28:44 2024 +0200 Fix uilabel tests on windows (#2362) commit 798ae21 Author: Maic Siemering <maic@siemering.tech> Date: Mon Sep 2 23:54:23 2024 +0200 fix slider calculates wrong x value when min_value > 0 (#2359) commit d4947c9 Author: Maic Siemering <maic@siemering.tech> Date: Sun Sep 1 23:32:04 2024 +0200 feat(section): untie sections and arcade (#2345) * feat(section): untie sections and arcade commit e9dd36a Author: bump_version <bump-version@version.com> Date: Sun Sep 1 16:59:51 2024 +0000 Version 3.0.0-dev.35 [skip ci] commit a362ee1 Author: Maic Siemering <maic@siemering.tech> Date: Sat Aug 31 23:00:08 2024 +0200 Changes for arcade 3.0 RC2 (dev34) (#2357) - Add more gui examples - hidden password - camera - revamp UIGridLayout, use box algorithm, add documentation commit 1b8ca03 Author: bump_version <bump-version@version.com> Date: Mon Aug 26 12:50:54 2024 +0000 Version 3.0.0-dev.34 [skip ci] commit 19b53a1 Author: Maic Siemering <maic@siemering.tech> Date: Sat Aug 24 05:43:10 2024 +0200 Gui/colorpicker (#2354) * Add color picker example commit 10143b9 Author: Maic Siemering <maic@siemering.tech> Date: Sat Aug 24 05:05:14 2024 +0200 GUI push for 3.0 (#2351) - New FlatUI colors under arcade.uicolor - Combined gui examples and proper documentation - Rewrite box layout to address sizing issues, when a child provided size_hint_min - GUI assets are now consistent in style and properly structured - Apply feedback about UIGridLayout parameter names - UIView provides add_widget method and a background property, which will be used for clearing screen - UIFlatButton provides multiple default styles - Consistent UITextureSlider parameter names, better default for height - UIAnchorLayouts do not restrict a child size to its own size, to allow scrolling use cases - UITextArea provides the option for pyglet attributed or html text formatting - UIInputText emits a on_change event, when text changed - Buttons default to Kenny font, when loaded --------- Co-authored-by: Jaecktec <constantin@jaeck.eu.org> commit 3808448 Author: Aizen <32631344+feiyuhuahuo@users.noreply.github.com> Date: Fri Aug 23 11:54:16 2024 +0800 Update resource_handlers.rst (#2348) commit 072101f Author: A. J. Andrews <86714785+DragonMoffon@users.noreply.github.com> Date: Wed Aug 14 00:26:07 2024 +1200 updated ViewportProjector to use Rect, and created unit tests (#2343) * updated ViewportProjector to use Rect and created unit tests * linting ✨ * ⬛ * Correcting references to the viewport Thanks for pointing out the issue, @eruvanos! commit 83cb72d Author: Maic Siemering <maic@siemering.tech> Date: Thu Aug 8 21:24:06 2024 +0200 typing(gui):remove type ignores from gui (#2346) * remove type ignores from gui commit f44233c Merge: 8c17aed 2c4161f Author: A. J. Andrews <86714785+DragonMoffon@users.noreply.github.com> Date: Thu Aug 8 12:43:28 2024 +1200 Merge pull request #2344 from pythonarcade/sub-clock Add a SubClock class to `arcade.future` commit 2c4161f Author: DragonMoffon <happydog.aja@gmail.com> Date: Thu Aug 8 00:28:57 2024 +1200 :sparkles: linting and :black_large_square: :sparkles: commit be85a02 Author: DragonMoffon <happydog.aja@gmail.com> Date: Thu Aug 8 00:24:12 2024 +1200 Create SubClock Class commit b441fb9 Author: DragonMoffon <happydog.aja@gmail.com> Date: Thu Aug 8 00:23:59 2024 +1200 :boot:strapping! commit 734e333 Author: DragonMoffon <happydog.aja@gmail.com> Date: Thu Aug 8 00:11:52 2024 +1200 no more doc string typing
1 parent 8a58e7c commit 7eaaf44

File tree

152 files changed

+3638
-2496
lines changed

Some content is hidden

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

152 files changed

+3638
-2496
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ API in a way that is not compatible with how it was used in 2.6.
6767
* Removed `arcade.gui.widgets.UIPadding` this is now general available in `arcade.gui.widgets.UIWidget`
6868
* Removed `arcade.gui.widgets.UITexturePane` this is now general available in `arcade.gui.widgets.UIWidget`
6969
* Removed `arcade.gui.widgets.UIAnchorWidget` replaced by `arcade.gui.widgets.UIAnchorLayout`
70-
70+
* Resources
71+
* removed unsused resources from `resources/gui_basic_assets`
72+
* `items/shield_gold.png`
73+
* `items/sword_gold.png`
74+
* `slider_thumb.png`
75+
* `slider_track.png`
76+
* `toggle/switch_green.png`
77+
* `toggle/switch_red.png`
7178
### Featured Updates
7279

7380
* The texture atlas has been heavily reworked to be more efficient.
@@ -131,6 +138,10 @@ API in a way that is not compatible with how it was used in 2.6.
131138
* Update and add example code.
132139
* Iterable (providing direct children)
133140

141+
* Updated widgets
142+
* `arcade.gui.widgets.text.UIInputText` emits `on_change` event when new text input or set
143+
* `arcade.gui.widgets.slider.UITextureSlider` texture names changed to fit general naming pattern
144+
134145
* New widgets:
135146

136147
* `arcade.gui.widgets.dropdown.UIDropdown`
@@ -152,6 +163,8 @@ API in a way that is not compatible with how it was used in 2.6.
152163
* `arcade.gui.UIAnchorLayout`
153164
* `arcade.gui.UIGridLayout` [PR1478](https://github.com/pythonarcade/arcade/pull/1478)
154165

166+
* Added color consistent assets to `arcade.resources.gui_basic_assets`
167+
* Provide GUI friendly color constants in `arcade.uicolor`
155168
* Replace deprecated usage of `arcade.draw_text`
156169

157170
### Misc Changes

arcade/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0-dev.33
1+
3.0.0-dev.36

arcade/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def configure_logging(level: int | None = None):
228228
# Module imports
229229
from arcade import color as color
230230
from arcade import csscolor as csscolor
231+
from arcade import uicolor as uicolor
231232
from arcade import camera as camera
232233
from arcade import key as key
233234
from arcade import resources as resources
@@ -387,6 +388,7 @@ def configure_logging(level: int | None = None):
387388
"rect",
388389
"color",
389390
"csscolor",
391+
"uicolor",
390392
"key",
391393
"resources",
392394
"types",

arcade/application.py

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from arcade.clock import GLOBAL_CLOCK, GLOBAL_FIXED_CLOCK, _setup_clock, _setup_fixed_clock
2121
from arcade.color import TRANSPARENT_BLACK
2222
from arcade.context import ArcadeContext
23-
from arcade.sections import SectionManager
2423
from arcade.types import LBWH, Color, Rect, RGBANormalized, RGBOrA255
2524
from arcade.utils import is_raspberry_pi
2625
from arcade.window_commands import get_display_size, set_window
@@ -979,37 +978,21 @@ def show_view(self, new_view: View) -> None:
979978
# remove previously shown view's handlers
980979
if self._current_view is not None:
981980
self._current_view.on_hide_view()
982-
if self._current_view.has_sections:
983-
self.remove_handlers(self._current_view.section_manager)
984981
self.remove_handlers(self._current_view)
985982

986983
# push new view's handlers
987984
self._current_view = new_view
988-
if new_view.has_sections:
989-
section_manager_managed_events = new_view.section_manager.managed_events
990-
section_handlers = {
991-
event_type: getattr(new_view.section_manager, event_type, None)
992-
for event_type in section_manager_managed_events
993-
}
994-
if section_handlers:
995-
self.push_handlers(**section_handlers)
996-
else:
997-
section_manager_managed_events = set()
998985

999986
# Note: Excluding on_show because this even can trigger multiple times.
1000987
# It should only be called once when the view is shown.
1001988
view_handlers = {
1002989
event_type: getattr(new_view, event_type, None)
1003990
for event_type in self.event_types
1004-
if event_type != "on_show"
1005-
and event_type not in section_manager_managed_events
1006-
and hasattr(new_view, event_type)
991+
if event_type != "on_show" and hasattr(new_view, event_type)
1007992
}
1008993
if view_handlers:
1009994
self.push_handlers(**view_handlers)
1010995
self._current_view.on_show_view()
1011-
if self._current_view.has_sections:
1012-
self._current_view.section_manager.on_show_view()
1013996

1014997
# Note: After the View has been pushed onto pyglet's stack of event handlers
1015998
# (via push_handlers()), pyglet
@@ -1028,18 +1011,9 @@ def hide_view(self) -> None:
10281011
return
10291012

10301013
self._current_view.on_hide_view()
1031-
if self._current_view.has_sections:
1032-
self._current_view.section_manager.on_hide_view()
1033-
self.remove_handlers(self._current_view.section_manager)
10341014
self.remove_handlers(self._current_view)
10351015
self._current_view = None
10361016

1037-
# def _create(self) -> None:
1038-
# super()._create()
1039-
1040-
# def _recreate(self, changes) -> None:
1041-
# super()._recreate(changes)
1042-
10431017
def flip(self) -> None:
10441018
"""
10451019
Present the rendered content to the screen.
@@ -1249,7 +1223,7 @@ class View:
12491223
Subclassing the window is very inflexible since you can't easily switch
12501224
your update and draw logic.
12511225
1252-
A view is a way to encapsulate that logic so you can easily switch between
1226+
A view is a way to encapsulate that logic, so you can easily switch between
12531227
different parts of your game. Maybe you have a title screen, a game screen,
12541228
and a game over screen. Each of these could be a different view.
12551229
@@ -1261,46 +1235,6 @@ class View:
12611235

12621236
def __init__(self, window: Window | None = None) -> None:
12631237
self.window = arcade.get_window() if window is None else window
1264-
self.key: int | None = None
1265-
self._section_manager: SectionManager | None = None
1266-
1267-
@property
1268-
def section_manager(self) -> SectionManager:
1269-
"""The section manager for this view.
1270-
1271-
If the view has section manager one will be created.
1272-
"""
1273-
if self._section_manager is None:
1274-
self._section_manager = SectionManager(self)
1275-
return self._section_manager
1276-
1277-
@property
1278-
def has_sections(self) -> bool:
1279-
"""Returns ``True`` if this view has sections."""
1280-
if self._section_manager is None:
1281-
return False
1282-
else:
1283-
return self.section_manager.has_sections
1284-
1285-
def add_section(
1286-
self,
1287-
section: arcade.Section,
1288-
at_index: int | None = None,
1289-
at_draw_order: int | None = None,
1290-
) -> None:
1291-
"""
1292-
Adds a section to the view Section Manager.
1293-
1294-
Args:
1295-
section:
1296-
The section to add to this section manager
1297-
at_index (optional):
1298-
The index to insert the section for event capture and
1299-
update events. If ``None`` it will be added at the end.
1300-
at_draw_order (optional):
1301-
Inserts the section in a specific draw order. Overwrites section.draw_order
1302-
"""
1303-
self.section_manager.add_section(section, at_index, at_draw_order)
13041238

13051239
def clear(
13061240
self,

arcade/camera/default.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pyglet.math import Mat4, Vec2, Vec3
77
from typing_extensions import Self
88

9-
from arcade.types import Point
9+
from arcade.types import LBWH, Point, Rect
1010
from arcade.window_commands import get_window
1111

1212
if TYPE_CHECKING:
@@ -29,28 +29,28 @@ class ViewportProjector:
2929

3030
def __init__(
3131
self,
32-
viewport: tuple[int, int, int, int] | None = None,
32+
viewport: Rect | None = None,
3333
*,
3434
context: ArcadeContext | None = None,
3535
):
36-
self._ctx = context or get_window().ctx
37-
self._viewport = viewport or self._ctx.viewport
36+
self._ctx: ArcadeContext = context or get_window().ctx
37+
self._viewport: Rect = viewport or LBWH(*self._ctx.viewport)
3838
self._projection_matrix: Mat4 = Mat4.orthogonal_projection(
39-
0.0, self._viewport[2], 0.0, self._viewport[3], -100, 100
39+
0.0, self._viewport.width, 0.0, self._viewport.height, -100, 100
4040
)
4141

4242
@property
43-
def viewport(self) -> tuple[int, int, int, int]:
43+
def viewport(self) -> Rect:
4444
"""
4545
The viewport use to derive projection and view matrix.
4646
"""
4747
return self._viewport
4848

4949
@viewport.setter
50-
def viewport(self, viewport: tuple[int, int, int, int]) -> None:
50+
def viewport(self, viewport: Rect) -> None:
5151
self._viewport = viewport
5252
self._projection_matrix = Mat4.orthogonal_projection(
53-
0, viewport[2], 0, viewport[3], -100, 100
53+
0, viewport.width, 0, viewport.height, -100, 100
5454
)
5555

5656
def use(self) -> None:
@@ -60,7 +60,7 @@ def use(self) -> None:
6060
"""
6161
self._ctx.current_camera = self
6262

63-
self._ctx.viewport = self._viewport
63+
self._ctx.viewport = self.viewport.viewport # get the integer 4-tuple LBWH
6464

6565
self._ctx.view_matrix = Mat4()
6666
self._ctx.projection_matrix = self._projection_matrix
@@ -121,18 +121,19 @@ def use(self) -> None:
121121
cache's the window viewport to determine the projection matrix.
122122
"""
123123

124+
viewport = self.viewport.viewport
124125
# If the viewport is correct and the default camera is in use,
125126
# then don't waste time resetting the view and projection matrices
126-
if self._ctx.viewport == self.viewport and self._ctx.current_camera == self:
127+
if self._ctx.viewport == viewport and self._ctx.current_camera == self:
127128
return
128129

129130
# If the viewport has changed while the default camera is active then the
130131
# default needs to update itself.
131132
# If it was another camera's viewport being used the default camera should not update.
132-
if self._ctx.viewport != self.viewport and self._ctx.current_camera == self:
133-
self.viewport = self._ctx.viewport
133+
if self._ctx.viewport != viewport and self._ctx.current_camera == self:
134+
self.viewport = LBWH(*self._ctx.viewport)
134135
else:
135-
self._ctx.viewport = self.viewport
136+
self._ctx.viewport = viewport
136137

137138
self._ctx.current_camera = self
138139

arcade/clock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class FixedClock(Clock):
124124
125125
Args:
126126
sibling: The unfixed clock which this clock will sync with.
127-
fixed_tick_rate (float, optional): The fixed number of seconds that pass
127+
fixed_tick_rate: The fixed number of seconds that pass
128128
for this clock every tick. Defaults to ``1.0 / 60.0``.
129129
"""
130130

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""Demonstrates general setup.
2+
3+
If arcade and Python are properly installed, you can run this example with:
4+
python -m arcade.examples.gui.0_basic_setup
5+
6+
Content:
7+
- create a view manually creating UIManager and adding widgets
8+
- create a second view extending UIView and adding widgets
9+
10+
"""
11+
12+
import arcade
13+
from arcade.gui import (
14+
UIManager,
15+
UITextureButton,
16+
UIAnchorLayout,
17+
)
18+
19+
# Preload textures, because they are mostly used multiple times, so they are not
20+
# loaded multiple times
21+
TEX_RED_BUTTON_NORMAL = arcade.load_texture(":resources:gui_basic_assets/button/red_normal.png")
22+
TEX_RED_BUTTON_HOVER = arcade.load_texture(":resources:gui_basic_assets/button/red_hover.png")
23+
TEX_RED_BUTTON_PRESS = arcade.load_texture(":resources:gui_basic_assets/button/red_press.png")
24+
25+
26+
class GreenView(arcade.View):
27+
"""Uses the arcade.View and shows how to integrate UIManager."""
28+
29+
def __init__(self):
30+
super().__init__()
31+
32+
# Create a UIManager
33+
self.ui = UIManager()
34+
35+
# Create a anchor layout, which can be used to position widgets on screen
36+
anchor = self.ui.add(UIAnchorLayout())
37+
38+
# Add a button switch to the other View.
39+
button = anchor.add(
40+
UITextureButton(
41+
text="Switch to blue view",
42+
texture=TEX_RED_BUTTON_NORMAL,
43+
texture_hovered=TEX_RED_BUTTON_HOVER,
44+
texture_pressed=TEX_RED_BUTTON_PRESS,
45+
on_click=lambda: self.window.show_view(self.window.views["other"]),
46+
)
47+
)
48+
49+
# add a button to switch to the blue view
50+
@button.event("on_click")
51+
def on_click(event):
52+
self.window.show_view(BlueView())
53+
54+
def on_show_view(self) -> None:
55+
self.ui.enable()
56+
57+
def on_hide_view(self) -> None:
58+
self.ui.disable()
59+
60+
def on_draw(self):
61+
# Clear the screen
62+
self.clear(color=arcade.uicolor.GREEN_EMERALD)
63+
64+
# Add draw commands that should be below the UI
65+
# ...
66+
67+
self.ui.draw()
68+
69+
# Add draw commands that should be on top of the UI (uncommon)
70+
# ...
71+
72+
73+
class BlueView(arcade.gui.UIView):
74+
"""Uses the arcade.gui.UIView which takes care about the UIManager setup."""
75+
76+
def __init__(self):
77+
super().__init__()
78+
self.background_color = arcade.uicolor.BLUE_PETER_RIVER
79+
80+
# Create a anchor layout, which can be used to position widgets on screen
81+
anchor = self.add_widget(UIAnchorLayout())
82+
83+
# Add a button switch to the other View.
84+
button = anchor.add(
85+
UITextureButton(
86+
text="Switch to green view",
87+
texture=TEX_RED_BUTTON_NORMAL,
88+
texture_hovered=TEX_RED_BUTTON_HOVER,
89+
texture_pressed=TEX_RED_BUTTON_PRESS,
90+
on_click=lambda: self.window.show_view(self.window.views["my"]),
91+
)
92+
)
93+
94+
# add a button to switch to the green view
95+
@button.event("on_click")
96+
def on_click(event):
97+
self.window.show_view(GreenView())
98+
99+
def on_draw_before_ui(self):
100+
# Add draw commands that should be below the UI
101+
pass
102+
103+
def on_draw_after_ui(self):
104+
# Add draw commands that should be on top of the UI (uncommon)
105+
pass
106+
107+
108+
if __name__ == "__main__":
109+
window = arcade.Window(title="GUI Example: Basic Setup")
110+
window.show_view(GreenView())
111+
window.run()

0 commit comments

Comments
 (0)