mirror of
https://github.com/csd4ni3l/fractal-viewer.git
synced 2026-01-01 04:13:41 +01:00
Remove unnecesseray double UIAnchorLayout with controller support and setting of controller events on window
This commit is contained in:
@@ -25,9 +25,6 @@ class IterFractalViewer(arcade.gui.UIView):
|
|||||||
|
|
||||||
def on_show_view(self):
|
def on_show_view(self):
|
||||||
super().on_show_view()
|
super().on_show_view()
|
||||||
self.window.on_stick_motion = self.on_stick_motion
|
|
||||||
self.window.on_button_press = self.on_button_press
|
|
||||||
self.window.on_button_release = self.on_button_release
|
|
||||||
|
|
||||||
self.shader_program, self.fractal_image = create_iter_calc_shader(
|
self.shader_program, self.fractal_image = create_iter_calc_shader(
|
||||||
self.fractal_name,
|
self.fractal_name,
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ class SierpinskyCarpetViewer(arcade.gui.UIView):
|
|||||||
self.click_center = (self.width / 2, self.height / 2)
|
self.click_center = (self.width / 2, self.height / 2)
|
||||||
self.has_controller = False
|
self.has_controller = False
|
||||||
|
|
||||||
self.window.on_stick_motion = self.on_stick_motion
|
|
||||||
|
|
||||||
def on_show_view(self):
|
def on_show_view(self):
|
||||||
super().on_show_view()
|
super().on_show_view()
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ class FractalChooser(arcade.gui.UIView):
|
|||||||
self.pypresence_client = pypresence_client
|
self.pypresence_client = pypresence_client
|
||||||
self.iter_fractal_buttons = []
|
self.iter_fractal_buttons = []
|
||||||
|
|
||||||
self.root = self.add_widget(UIFocusGroup())
|
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
|
||||||
self.anchor = self.root.add(arcade.gui.UIAnchorLayout(size_hint=(1, 1)))
|
|
||||||
|
|
||||||
self.grid = self.add_widget(arcade.gui.UIGridLayout(row_count=4, column_count=3, horizontal_spacing=10, vertical_spacing=10))
|
self.grid = self.add_widget(arcade.gui.UIGridLayout(row_count=4, column_count=3, horizontal_spacing=10, vertical_spacing=10))
|
||||||
self.anchor.add(self.grid, anchor_x="center", anchor_y="center")
|
self.anchor.add(self.grid, anchor_x="center", anchor_y="center")
|
||||||
@@ -40,7 +39,7 @@ class FractalChooser(arcade.gui.UIView):
|
|||||||
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)
|
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)
|
||||||
self.sierpinsky_carpet_button.on_click = lambda event: self.sierpinsky_carpet()
|
self.sierpinsky_carpet_button.on_click = lambda event: self.sierpinsky_carpet()
|
||||||
|
|
||||||
self.root.detect_focusable_widgets()
|
self.anchor.detect_focusable_widgets()
|
||||||
|
|
||||||
def main_exit(self):
|
def main_exit(self):
|
||||||
from menus.main import Main
|
from menus.main import Main
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ class Main(arcade.gui.UIView):
|
|||||||
def __init__(self, pypresence_client=None):
|
def __init__(self, pypresence_client=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.root = self.add_widget(UIFocusGroup())
|
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
|
||||||
self.anchor = self.root.add(arcade.gui.UIAnchorLayout())
|
|
||||||
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
|
self.box = self.anchor.add(arcade.gui.UIBoxLayout(space_between=10), anchor_x='center', anchor_y='center')
|
||||||
|
|
||||||
self.pypresence_client = pypresence_client
|
self.pypresence_client = pypresence_client
|
||||||
@@ -59,7 +58,7 @@ class Main(arcade.gui.UIView):
|
|||||||
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))
|
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))
|
||||||
self.settings_button.on_click = lambda event: self.settings()
|
self.settings_button.on_click = lambda event: self.settings()
|
||||||
|
|
||||||
self.root.detect_focusable_widgets()
|
self.anchor.detect_focusable_widgets()
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
from menus.fractal_chooser import FractalChooser
|
from menus.fractal_chooser import FractalChooser
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from utils.constants import button_style, dropdown_style, slider_style, settings
|
|||||||
from utils.utils import FakePyPresence
|
from utils.utils import FakePyPresence
|
||||||
from utils.preload import button_texture, button_hovered_texture
|
from utils.preload import button_texture, button_hovered_texture
|
||||||
|
|
||||||
from arcade.gui import UIBoxLayout, UIAnchorLayout
|
|
||||||
from arcade.gui.experimental.focus import UIFocusGroup
|
from arcade.gui.experimental.focus import UIFocusGroup
|
||||||
|
|
||||||
class Settings(arcade.gui.UIView):
|
class Settings(arcade.gui.UIView):
|
||||||
@@ -30,17 +29,16 @@ class Settings(arcade.gui.UIView):
|
|||||||
self.modified_settings = {}
|
self.modified_settings = {}
|
||||||
|
|
||||||
def create_layouts(self):
|
def create_layouts(self):
|
||||||
self.root = self.add_widget(UIFocusGroup())
|
self.anchor = self.add_widget(UIFocusGroup(size_hint=(1, 1)))
|
||||||
self.anchor = self.root.add(UIAnchorLayout(size_hint=(1, 1)))
|
|
||||||
|
|
||||||
self.box = UIBoxLayout(space_between=50, align="center", vertical=False)
|
self.box = arcade.gui.UIBoxLayout(space_between=50, align="center", vertical=False)
|
||||||
self.anchor.add(self.box, anchor_x="center", anchor_y="top", align_x=10, align_y=-75)
|
self.anchor.add(self.box, anchor_x="center", anchor_y="top", align_x=10, align_y=-75)
|
||||||
|
|
||||||
self.top_box = UIBoxLayout(space_between=self.window.width / 160, vertical=False)
|
self.top_box = arcade.gui.UIBoxLayout(space_between=self.window.width / 160, vertical=False)
|
||||||
self.anchor.add(self.top_box, anchor_x="left", anchor_y="top", align_x=10, align_y=-10)
|
self.anchor.add(self.top_box, anchor_x="left", anchor_y="top", align_x=10, align_y=-10)
|
||||||
|
|
||||||
self.key_layout = self.box.add(UIBoxLayout(space_between=20, align='left'))
|
self.key_layout = self.box.add(arcade.gui.UIBoxLayout(space_between=20, align='left'))
|
||||||
self.value_layout = self.box.add(UIBoxLayout(space_between=13, align='left'))
|
self.value_layout = self.box.add(arcade.gui.UIBoxLayout(space_between=13, align='left'))
|
||||||
|
|
||||||
def on_show_view(self):
|
def on_show_view(self):
|
||||||
super().on_show_view()
|
super().on_show_view()
|
||||||
@@ -68,7 +66,7 @@ class Settings(arcade.gui.UIView):
|
|||||||
|
|
||||||
self.top_box.add(category_button)
|
self.top_box.add(category_button)
|
||||||
|
|
||||||
self.root.detect_focusable_widgets()
|
self.anchor.detect_focusable_widgets()
|
||||||
|
|
||||||
def display_category(self, category):
|
def display_category(self, category):
|
||||||
if hasattr(self, 'apply_button'):
|
if hasattr(self, 'apply_button'):
|
||||||
@@ -96,7 +94,7 @@ class Settings(arcade.gui.UIView):
|
|||||||
self.value_layout.add(dropdown)
|
self.value_layout.add(dropdown)
|
||||||
|
|
||||||
elif setting_dict['type'] == "bool":
|
elif setting_dict['type'] == "bool":
|
||||||
button_layout = self.value_layout.add(arcade.gui.UIBoxLayout(space_between=50, vertical=False))
|
button_layout = self.value_layout.add(arcade.gui.arcade.gui.UIBoxLayout(space_between=50, vertical=False))
|
||||||
|
|
||||||
on_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="ON", style=button_style, width=150, height=50)
|
on_radiobutton = arcade.gui.UITextureButton(texture=button_texture, texture_hovered=button_hovered_texture, text="ON", style=button_style, width=150, height=50)
|
||||||
self.on_radiobuttons[setting] = on_radiobutton
|
self.on_radiobuttons[setting] = on_radiobutton
|
||||||
@@ -139,7 +137,7 @@ class Settings(arcade.gui.UIView):
|
|||||||
self.apply_button.on_click = lambda event: self.apply_settings()
|
self.apply_button.on_click = lambda event: self.apply_settings()
|
||||||
self.anchor.add(self.apply_button, anchor_x="right", anchor_y="bottom", align_x=-10, align_y=10)
|
self.anchor.add(self.apply_button, anchor_x="right", anchor_y="bottom", align_x=-10, align_y=10)
|
||||||
|
|
||||||
self.root.detect_focusable_widgets()
|
self.anchor.detect_focusable_widgets()
|
||||||
|
|
||||||
def apply_settings(self):
|
def apply_settings(self):
|
||||||
for config_key, value in self.modified_settings.items():
|
for config_key, value in self.modified_settings.items():
|
||||||
@@ -272,7 +270,7 @@ class Settings(arcade.gui.UIView):
|
|||||||
|
|
||||||
self.key_layout.add(self.credits_label)
|
self.key_layout.add(self.credits_label)
|
||||||
|
|
||||||
self.root.detect_focusable_widgets()
|
self.anchor.detect_focusable_widgets()
|
||||||
|
|
||||||
def set_highlighted_style(self, element):
|
def set_highlighted_style(self, element):
|
||||||
element.texture = button_hovered_texture
|
element.texture = button_hovered_texture
|
||||||
|
|||||||
Reference in New Issue
Block a user