menu_03.py Diff
--- /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/development/doc/tutorials/menu/menu_02.py
+++ /home/docs/checkouts/readthedocs.org/user_builds/arcade-library/checkouts/development/doc/tutorials/menu/menu_03.py
@@ -18,9 +18,10 @@
def __init__(self):
super().__init__()
+
self.manager = arcade.gui.UIManager()
- switch_menu_button = arcade.gui.UIFlatButton(text="Pause", width=250)
+ switch_menu_button = arcade.gui.UIFlatButton(text="Pause", width=150)
# Initialise the button with an on_click event.
@switch_menu_button.event("on_click")
@@ -38,16 +39,16 @@
child=switch_menu_button,
)
+ def on_hide_view(self):
+ # Disable the UIManager when the view is hidden.
+ self.manager.disable()
+
def on_show_view(self):
"""This is run once when we switch to this view"""
arcade.set_background_color(arcade.color.DARK_BLUE_GRAY)
# Enable the UIManager when the view is showm.
self.manager.enable()
-
- def on_hide_view(self):
- # Disable the UIManager when the view is hidden.
- self.manager.disable()
def on_draw(self):
"""Render the screen."""
@@ -66,6 +67,33 @@
self.manager = arcade.gui.UIManager()
+ resume = arcade.gui.UIFlatButton(text="Resume", width=150)
+ start_new_game = arcade.gui.UIFlatButton(text="Start New Game", width=150)
+ volume = arcade.gui.UIFlatButton(text="Volume", width=150)
+ options = arcade.gui.UIFlatButton(text="Options", width=150)
+
+ exit = arcade.gui.UIFlatButton(text="Exit", width=320)
+
+ # Initialise a grid in which widgets can be arranged.
+ self.grid = arcade.gui.UIGridLayout(
+ column_count=2, row_count=3, horizontal_spacing=20, vertical_spacing=20
+ )
+
+ # Adding the buttons to the layout.
+ self.grid.add(resume, column=0, row=0)
+ self.grid.add(start_new_game, column=1, row=0)
+ self.grid.add(volume, column=0, row=1)
+ self.grid.add(options, column=1, row=1)
+ self.grid.add(exit, column=0, row=2, column_span=2)
+
+ self.anchor = self.manager.add(arcade.gui.UIAnchorLayout())
+
+ self.anchor.add(
+ anchor_x="center_x",
+ anchor_y="center_y",
+ child=self.grid,
+ )
+
self.main_view = main_view
def on_hide_view(self):
@@ -78,11 +106,11 @@
# Makes the background darker
arcade.set_background_color([rgb - 50 for rgb in arcade.color.DARK_BLUE_GRAY])
+ # Enable the UIManager when the view is showm.
self.manager.enable()
def on_draw(self):
"""Render the screen."""
-
# Clear the screen
self.clear()
self.manager.draw()