Skip to content

Commit 1780ab7

Browse files
committed
Remove unnecesseray double UIAnchorLayout with controller support and setting of controller events on window
1 parent ffcf125 commit 1780ab7

File tree

5 files changed

+14
-23
lines changed

5 files changed

+14
-23
lines changed

game/iter_fractal_viewer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ def __init__(self, pypresence_client, fractal_name: str):
2525

2626
def on_show_view(self):
2727
super().on_show_view()
28-
self.window.on_stick_motion = self.on_stick_motion
29-
self.window.on_button_press = self.on_button_press
30-
self.window.on_button_release = self.on_button_release
3128

3229
self.shader_program, self.fractal_image = create_iter_calc_shader(
3330
self.fractal_name,

game/sierpinsky_carpet.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def __init__(self, pypresence_client):
1717
self.zoom = 1.0
1818
self.click_center = (self.width / 2, self.height / 2)
1919
self.has_controller = False
20-
21-
self.window.on_stick_motion = self.on_stick_motion
22-
20+
2321
def on_show_view(self):
2422
super().on_show_view()
2523

menus/fractal_chooser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def __init__(self, pypresence_client):
1212
self.pypresence_client = pypresence_client
1313
self.iter_fractal_buttons = []
1414

15-
self.root = self.add_widget(UIFocusGroup())
16-
self.anchor = self.root.add(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
15+
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
1716

1817
self.grid = self.add_widget(arcade.gui.UIGridLayout(row_count=4, column_count=3, horizontal_spacing=10, vertical_spacing=10))
1918
self.anchor.add(self.grid, anchor_x="center", anchor_y="center")
@@ -40,7 +39,7 @@ def on_show_view(self):
4039
self.sierpinsky_carpet_button = self.grid.add(arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text='Sierpinsky Carpet', style=button_style, width=200, height=200), row=row, column=col)
4140
self.sierpinsky_carpet_button.on_click = lambda event: self.sierpinsky_carpet()
4241

43-
self.root.detect_focusable_widgets()
42+
self.anchor.detect_focusable_widgets()
4443

4544
def main_exit(self):
4645
from menus.main import Main

menus/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ class Main(arcade.gui.UIView):
77
def __init__(self, pypresence_client=None):
88
super().__init__()
99

10-
self.root = self.add_widget(UIFocusGroup())
11-
self.anchor = self.root.add(arcade.gui.UIAnchorLayout())
10+
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
1211
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
1312

1413
self.pypresence_client = pypresence_client
@@ -59,7 +58,7 @@ def on_show_view(self):
5958
self.settings_button = self.box.add(arcade.gui.UITextureButton(text="Settings", texture=button_texture, texture_hovered=button_hovered_texture, width=self.window.width / 2, height=150, style=big_button_style))
6059
self.settings_button.on_click = lambda event: self.settings()
6160

62-
self.root.detect_focusable_widgets()
61+
self.anchor.detect_focusable_widgets()
6362

6463
def play(self):
6564
from menus.fractal_chooser import FractalChooser

menus/settings.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from utils.utils import FakePyPresence
77
from utils.preload import button_texture, button_hovered_texture
88

9-
from arcade.gui import UIBoxLayout, UIAnchorLayout
109
from arcade.gui.experimental.focus import UIFocusGroup
1110

1211
class Settings(arcade.gui.UIView):
@@ -30,17 +29,16 @@ def __init__(self, pypresence_client):
3029
self.modified_settings = {}
3130

3231
def create_layouts(self):
33-
self.root = self.add_widget(UIFocusGroup())
34-
self.anchor = self.root.add(UIAnchorLayout(size_hint=(1, 1)))
32+
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
3533

36-
self.box = UIBoxLayout(space_between=50, align="center", vertical=False)
34+
self.box = arcade.gui.UIBoxLayout(space_between=50, align="center", vertical=False)
3735
self.anchor.add(self.box, anchor_x="center", anchor_y="top", align_x=10, align_y=-75)
3836

39-
self.top_box = UIBoxLayout(space_between=self.window.width / 160, vertical=False)
37+
self.top_box = arcade.gui.UIBoxLayout(space_between=self.window.width / 160, vertical=False)
4038
self.anchor.add(self.top_box, anchor_x="left", anchor_y="top", align_x=10, align_y=-10)
4139

42-
self.key_layout = self.box.add(UIBoxLayout(space_between=20, align='left'))
43-
self.value_layout = self.box.add(UIBoxLayout(space_between=13, align='left'))
40+
self.key_layout = self.box.add(arcade.gui.UIBoxLayout(space_between=20, align='left'))
41+
self.value_layout = self.box.add(arcade.gui.UIBoxLayout(space_between=13, align='left'))
4442

4543
def on_show_view(self):
4644
super().on_show_view()
@@ -68,7 +66,7 @@ def display_categories(self):
6866

6967
self.top_box.add(category_button)
7068

71-
self.root.detect_focusable_widgets()
69+
self.anchor.detect_focusable_widgets()
7270

7371
def display_category(self, category):
7472
if hasattr(self, 'apply_button'):
@@ -96,7 +94,7 @@ def display_category(self, category):
9694
self.value_layout.add(dropdown)
9795

9896
elif setting_dict['type'] == "bool":
99-
button_layout = self.value_layout.add(arcade.gui.UIBoxLayout(space_between=50, vertical=False))
97+
button_layout = self.value_layout.add(arcade.gui.arcade.gui.UIBoxLayout(space_between=50, vertical=False))
10098

10199
on_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="ON", style=button_style, width=150, height=50)
102100
self.on_radiobuttons[setting] = on_radiobutton
@@ -139,7 +137,7 @@ def display_category(self, category):
139137
self.apply_button.on_click = lambda event: self.apply_settings()
140138
self.anchor.add(self.apply_button, anchor_x="right", anchor_y="bottom", align_x=-10, align_y=10)
141139

142-
self.root.detect_focusable_widgets()
140+
self.anchor.detect_focusable_widgets()
143141

144142
def apply_settings(self):
145143
for config_key, value in self.modified_settings.items():
@@ -272,7 +270,7 @@ def credits(self):
272270

273271
self.key_layout.add(self.credits_label)
274272

275-
self.root.detect_focusable_widgets()
273+
self.anchor.detect_focusable_widgets()
276274

277275
def set_highlighted_style(self, element):
278276
element.texture = button_hovered_texture

0 commit comments

Comments
 (0)