Gui/more docs by eruvanos · Pull Request #2373 · pythonarcade/arcade · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions arcade/examples/gui/own_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Read more about properties in the `arcade.gui` documentation.

If arcade and Python are properly installed, you can run this example with:
python -m arcade.examples.gui.own_progressbar
python -m arcade.examples.gui.own_widgets
"""

from __future__ import annotations
Expand Down Expand Up @@ -127,7 +127,7 @@ def _update_bar(self):
class MyView(UIView):
def __init__(self):
super().__init__()
self.ui = arcade.gui.UIManager()
self.background_color = arcade.uicolor.BLUE_BELIZE_HOLE

root = self.ui.add(UIAnchorLayout())
bars = root.add(UIBoxLayout(space_between=10))
Expand Down
Binary file added doc/example_code/images/gui_own_layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/example_code/images/gui_own_widgets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions doc/example_code/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,18 @@ Graphical User Interface

:ref:`gui_6_size_hints`

.. figure:: images/thumbs/gui_own_widgets.png
:figwidth: 170px
:target: gui_own_widgets.html

:ref:`gui_own_widgets`

.. figure:: images/thumbs/gui_own_layout.png
:figwidth: 170px
:target: gui_own_layout.html

:ref:`gui_own_layout`

.. note::

Not all existing examples made it into this section. You can find more under `Arcade GUI Examples <https://github.com/pythonarcade/arcade/tree/development/arcade/examples/gui>`_
Expand Down
25 changes: 16 additions & 9 deletions doc/programming_guide/gui/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ A :class:`UIWidget` has following properties.
move or resize its children; use a :py:class:`~arcade.gui.UILayout`
instead.

``visible``
A boolean indicating if the widget is visible or not. If a widget is not
visible, itself and any child widget will not be rendered.
Especially useful for hiding parts of the GUI like dialogs or popups.

``size_hint``
A tuple of two normalized floats (``0.0``-``1.0``) describing the portion
of the parent's width and height this widget prefers to occupy.
Expand Down Expand Up @@ -237,9 +242,9 @@ behaviour. Currently the available Mixins are still under heavy development.

Available:

- :py:class:`UIDraggableMixin`
- :py:class:`UIMouseFilterMixin`
- :py:class:`UIWindowLikeMixin`
- :py:class:`UIDraggableMixin` - Makes a widget draggable with the mouse.
- :py:class:`UIMouseFilterMixin` - Captures all mouse events.
- :py:class:`UIWindowLikeMixin` - Makes a widget behave like a window, combining draggable and mouse filter behaviour.

UIConstructs
============
Expand All @@ -248,8 +253,8 @@ Constructs are predefined structures of widgets and layouts like a message box.

Available:

- :py:class:`UIMessageBox`
- :py:class:`UIButtonRow`
- :py:class:`UIMessageBox` - A simple message box with a title, message and buttons.
- :py:class:`UIButtonRow` - A row of buttons.

Available Elements
==================
Expand Down Expand Up @@ -511,8 +516,8 @@ game developer should mostly interact with user-interface events, which are
dispatched from specific :py:class:`~arcade.gui.UIWidget`s like an ``on_click``
of a button.

In rare cases a developer might implement some widgets themselves or want to
modify the existing GUI behavior. In those cases a developer might register own
In cases where a developer implement own widgets themselves or want to
modify the existing GUI behavior, the developer might register own
pyglet event types on widgets or overwrite the
:py:class:`~arcade.gui.UIWidget.on_event` method. In that case, refer to
existing widgets as an example.
Expand Down Expand Up @@ -552,6 +557,8 @@ events.
Property
````````

:py:class:`~arcade.gui.Property` is an pure-Python implementation of Kivy
like Properties. They are used to detect attribute changes of widgets and trigger
:py:class:`~arcade.gui.Property` is an pure-Python implementation of Kivy-like Properties.
They are used to detect attribute changes of widgets and especially to trigger
rendering. They are mostly used within GUI widgets, but are globally available since 3.0.0.

Properties are a less verbose way to implement the observer pattern compared to the property decorator.
1 change: 1 addition & 0 deletions doc/programming_guide/gui/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Find the required information in the following sections:
layouts
style
own_widgets
own_layout



40 changes: 40 additions & 0 deletions doc/programming_guide/gui/own_layout.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _gui_own_layout:

Own Layout
----------

Creating own layouts is the master class of creating own widgets.
It allows you to create custom layouts that can be used in your application to position widgets.

General use cases for own layouts are:

- Create a layout that positions widgets in a specific way, like in a circle.
- Animate widgets in a specific way, like a carousel.

Where to start
~~~~~~~~~~~~~~

To create own layout, you need to create a new class that inherits from :class:`arcade.gui.UILayout`.

The main method you need to implement is:

- :meth:`arcade.gui.UILayout.do_layout` - This method is called to layout the child widgets.

Widgets added to the layout are accessible via the :attr:`arcade.gui.UILayout._children` attribute,
which is a list of all added widgets with the parameter provided when added.

Children should be placed within the bounds of the layout.
And should respect size_hint, size_hint_min and size_hint_max of the children.


It also provides a great user experience when you provide custom docs for the :meth:`arcade.gui.UIWidget.add` method.
So the user knows how to add widgets to your layout and which parameter are supported.

In the following example, we will create a layout that positions widgets in a circle and slowly rotating them.

Example `CircleLayout`
~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../../../arcade/examples/gui/own_layout.py


18 changes: 10 additions & 8 deletions doc/programming_guide/gui/own_widgets.rst