Skip to content

Commit c196cab

Browse files
committed
Add custom Sphinx roles for editor UI
1 parent 7bc1c2b commit c196cab

File tree

4 files changed

+162
-24
lines changed

4 files changed

+162
-24
lines changed

_static/css/custom.css

+19
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@
150150
--kbd-shadow-color: #b0b7bf;
151151
--kbd-text-color: #444d56;
152152

153+
--ui-btn-background-color: #d3d7e1;
154+
153155
--code-example-good-color: #3fb950;
154156
--code-example-bad-color: #f85149;
155157

@@ -279,6 +281,8 @@
279281
--kbd-outline-color: #3d4144;
280282
--kbd-shadow-color: #1e2023;
281283
--kbd-text-color: #e2f2ff;
284+
285+
--ui-btn-background-color: #22252d;
282286

283287
--code-example-good-color: #3fb950;
284288
--code-example-bad-color: #f85149;
@@ -1844,3 +1848,18 @@ p + .classref-constant {
18441848
#godot-giscus {
18451849
margin-bottom: 1em;
18461850
}
1851+
1852+
/* Custom Sphinx roles for editor UI */
1853+
/* The :ui: and :uiproperty: roles just render as bold. */
1854+
.role-ui {
1855+
font-weight: 700;
1856+
}
1857+
1858+
.role-button, .role-menu {
1859+
font-size: 80%;
1860+
border-radius: 4px;
1861+
padding: 2.4px 6px;
1862+
margin: auto 2px;
1863+
border: 0px solid #7fbbe3;
1864+
background: var(--ui-btn-background-color);
1865+
}

conf.py

+17
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@
254254

255255
linkcheck_timeout = 10
256256

257+
# -- Custom Sphinx roles for UI -------------------------------------------
258+
259+
rst_prolog = """
260+
.. role:: button
261+
:class: role-button role-ui
262+
263+
.. role:: menu
264+
:class: role-menu role-ui
265+
266+
.. role:: uiproperty
267+
:class: role-ui
268+
269+
.. role:: ui
270+
:class: role-ui
271+
272+
"""
273+
257274
# -- I18n settings --------------------------------------------------------
258275

259276
# Godot localization is handled via https://github.com/godotengine/godot-docs-l10n

contributing/documentation/docs_writing_guidelines.rst

+101
Original file line numberDiff line numberDiff line change
@@ -762,3 +762,104 @@ Follow these guidelines for when to refer to a specific Godot version:
762762
- If a feature was added in a 3.x major or minor version, **do not specify** when
763763
the feature was added. These features are old enough that the exact version
764764
in which they were added is not relevant.
765+
766+
Use roles for editor UI
767+
-----------------------
768+
769+
Much of the manual involves describing a sequence of UI actions in the editor,
770+
like clicking a button, opening a menu, or setting a property in the inspector.
771+
To keep formatting standardized, we use custom Sphinx roles for UI elements.
772+
773+
The following roles are defined:
774+
775+
- ``:button:`` A button, toggle, or other clickable UI element. If the reader
776+
is meant to click on it, and it's not a menu, use this. Renders as
777+
:button:`bold, with a background`.
778+
- ``:menu:`` A series of menus to click through. When listing a series of
779+
menus, separate them with ``>``. Renders as :menu:`bold, with a background`.
780+
- ``:uiproperty:`` A property *in the inspector*. When describing a property in
781+
*code*, instead either use ``code style`` or link to the property, as
782+
described earlier. Renders as :uiproperty:`bold`.
783+
- ``:ui:`` A role for any other editor UI elements. Use this if you would have
784+
otherwise just used **bold style**. Use this for input fields, docks, tabs,
785+
windows, bottom panels, etc. Also used for nested project settings or
786+
inspector sections. Renders as :ui:`bold`.
787+
788+
The first two roles, ``:button:`` and ``:menu:`` are used for editor UI that the
789+
reader is meant to click on, and they use an attention-grabbing visual style. The
790+
other roles, ``:uiproperty:`` and ``:ui:``, are used for other UI and show up
791+
often in text, so they just use bold text to be less distracting.
792+
793+
Our custom roles are inspired by the Sphinx `guilabel <https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-guilabel>`_
794+
and `menuselection <https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-menuselection>`_
795+
roles. However, we use our own implementation to better match the specific needs
796+
of Godot's documentation, using `custom RST roles <https://docutils.sourceforge.io/docs/ref/rst/directives.html#custom-interpreted-text-roles>`_
797+
and some custom CSS.
798+
799+
Examples
800+
~~~~~~~~
801+
802+
These are some example sections that use the roles, in context. Check the source
803+
of this page to see which roles are used.
804+
805+
Adding a sprite and setting some properties
806+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
807+
808+
In the :ui:`Scene` dock, click :button:`2D Scene` to create a new scene.
809+
810+
Add a new :ref:`Sprite2D <class_Sprite2D>` to the scene by right-clicking on the
811+
root node and choosing :button:`Add Child Node...`. In the :ui:`Create New Node`
812+
window, search for "Sprite2D", select it, and then click :button:`Create`.
813+
814+
On the sprite, under :ui:`Offset`, set :uiproperty:`Offset` to ``(16, 32)``
815+
and enable :uiproperty:`Flip H`. Set :uiproperty:`Animation > HFrames` to ``10``.
816+
In :ui:`CanvasItem > Visibility`, set the :uiproperty:`Modulate` color to
817+
``ff0000``.
818+
819+
.. tip::
820+
821+
Don't forget to save your scene in :menu:`Scene > Save Scene...`. When the
822+
:ui:`Save Scene As...` window pops up, enter "my_scene.tscn" in the
823+
:ui:`File` field, then click :button:`Save`.
824+
825+
Setting project settings
826+
^^^^^^^^^^^^^^^^^^^^^^^^
827+
828+
Go to :menu:`Project > Project Settings`, then select the
829+
:ref:`Max FPS <class_ProjectSettings_property_application/run/max_fps>`
830+
setting under :ui:`Application > Run`. Don't forget to click the
831+
:button:`Advanced Settings` toggle. Then, in :ui:`Filter Settings`, search for
832+
"physics". Under :ui:`Physics > 3D > Solver`, set
833+
:uiproperty:`Solver Iterations` to ``16``.
834+
835+
All styles in context
836+
^^^^^^^^^^^^^^^^^^^^^
837+
838+
Use this section to see how the custom roles look, particularly within admonitions.
839+
840+
|styleroles|
841+
842+
.. note::
843+
844+
|styleroles|
845+
846+
.. warning::
847+
848+
|styleroles|
849+
850+
.. danger::
851+
852+
|styleroles|
853+
854+
.. tip::
855+
856+
|styleroles|
857+
858+
.. admonition:: Custom admonition
859+
860+
|styleroles|
861+
862+
.. All the inline roles which are used in the docs. External links don't work in a substitution.
863+
.. |styleroles| replace:: Built-in styles: ``code``, **bold**, and *italics*.
864+
Built-in roles: :kbd:`kbd`, :ref:`ref <doc_about_intro>`, :ref:`ref <class_node>`.
865+
Custom roles: :button:`button`, :menu:`menu > submenu`, :uiproperty:`uiproperty`, :ui:`ui`.

getting_started/step_by_step/nodes_and_scenes.rst

+25-24
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,33 @@ opening the project, you should see an empty editor.
7373
.. image:: img/nodes_and_scenes_01_empty_editor.webp
7474

7575
In an empty scene, the Scene dock on the left shows several options to add a
76-
root node quickly. "2D Scene" adds a :ref:`Node2D <class_Node2D>` node,
77-
"3D Scene" adds a :ref:`Node3D <class_Node3D>` node,
78-
and "User Interface" adds a :ref:`Control <class_Control>` node.
76+
root node quickly. :button:`2D Scene` adds a :ref:`Node2D <class_Node2D>` node,
77+
:button:`3D Scene` adds a :ref:`Node3D <class_Node3D>` node,
78+
and :button:`User Interface` adds a :ref:`Control <class_Control>` node.
7979
These presets are here for convenience; they are not mandatory.
80-
"Other Node" lets you select any node to be the root node.
81-
In an empty scene, "Other Node" is equivalent to pressing the "Add Child Node"
80+
:button:`Other Node` lets you select any node to be the root node.
81+
In an empty scene, :button:`Other Node` is equivalent to pressing the :button:`Add Child Node`
8282
button at the top-left of the Scene dock, which usually adds
8383
a new node as a child of the currently selected node.
8484

8585
We're going to add a single :ref:`Label <class_Label>` node to our scene. Its function is to draw
8686
text on the screen.
8787

88-
Press the "Add Child Node" button or "Other Node" to create a root node.
88+
Press the :button:`Add Child Node` button or :button:`Other Node` to create a
89+
root node.
8990

9091
.. image:: img/nodes_and_scenes_02_scene_dock.webp
9192

92-
The Create Node dialog opens, showing the long list of available nodes.
93+
The :ui:`Create New Node` dialog opens, showing the long list of available nodes.
9394

9495
.. image:: img/nodes_and_scenes_03_create_node_window.webp
9596

9697
Select the Label node. You can type its name to filter down the list.
9798

9899
.. image:: img/nodes_and_scenes_04_create_label_window.webp
99100

100-
Click on the Label node to select it and click the Create button at the bottom
101-
of the window.
101+
Click on the Label node to select it and click the :button:`Create` button at
102+
the bottom of the window.
102103

103104
.. image:: img/nodes_and_scenes_05_editor_with_label.webp
104105

@@ -110,11 +111,11 @@ and the node's properties appear in the Inspector dock on the right.
110111
Changing a node's properties
111112
----------------------------
112113

113-
The next step is to change the Label's "Text" property. Let's change it to
114-
"Hello World".
114+
The next step is to change the Label's :uiproperty:`Text` property. Let's change
115+
it to "Hello World".
115116

116117
Head to the Inspector dock on the right of the viewport. Click inside the field
117-
below the Text property and type "Hello World".
118+
below the :uiproperty:`Text` property and type "Hello World".
118119

119120
.. image:: img/nodes_and_scenes_06_label_text.webp
120121

@@ -137,17 +138,18 @@ move it to the center of the view delimited by the rectangle.
137138
Running the scene
138139
-----------------
139140

140-
Everything's ready to run the scene! Press the **Run Current Scene** button in
141-
the top-right of the screen or press :kbd:`F6` (:kbd:`Cmd + R` on macOS).
141+
Everything's ready to run the scene! Press the :button:`Run Current Scene`
142+
button in the top-right of the screen or press :kbd:`F6` (:kbd:`Cmd + R` on
143+
macOS).
142144

143145
.. image:: img/nodes_and_scenes_09_play_scene_button.webp
144146

145-
A popup invites you to save the scene, which is required to run it.
146-
Click the Save button in the file browser to save it as ``label.tscn``.
147+
A popup invites you to save the scene, which is required to run it. Click the
148+
:button:`Save` button in the file browser to save it as ``label.tscn``.
147149

148150
.. image:: img/nodes_and_scenes_10_save_scene_as.webp
149151

150-
.. note:: The Save Scene As dialog, like other file dialogs in the editor, only
152+
.. note:: The :ui:`Save Scene As` dialog, like other file dialogs in the editor, only
151153
allows you to save files inside the project. The ``res://`` path at
152154
the top of the window represents the project's root directory and
153155
stands for "resource path". For more information about file paths in
@@ -162,8 +164,8 @@ Close the window or press :kbd:`F8` (:kbd:`Cmd + .` on macOS) to quit the runnin
162164
Setting the main scene
163165
----------------------
164166

165-
To run our test scene, we used the **Run Current Scene** button. Another button
166-
next to it, **Run Project**, allows you to set and run the project's
167+
To run our test scene, we used the :button:`Run Current Scene` button. Another button
168+
next to it, :button:`Run Project`, allows you to set and run the project's
167169
**main scene**. You can also press :kbd:`F5` (:kbd:`Cmd + B` on macOS) to do so.
168170

169171
.. image:: img/nodes_and_scenes_12_play_button.webp
@@ -176,8 +178,8 @@ A popup window appears and invites you to select the main scene.
176178

177179
.. image:: img/nodes_and_scenes_13_main_scene_popup.webp
178180

179-
Click the Select button, and in the file dialog that appears, double click on
180-
``label.tscn``.
181+
Click the :button:`Select` button, and in the file dialog that appears, double
182+
click on ``label.tscn``.
181183

182184
.. image:: img/nodes_and_scenes_14_select_main_scene.webp
183185

@@ -186,9 +188,8 @@ will use this scene as a starting point.
186188

187189
.. note:: The editor saves the main scene's path in a project.godot file in your
188190
project's directory. While you can edit this text file directly to
189-
change project settings, you can also use the "Project -> Project
190-
Settings" window to do so. For more information, see
191-
:ref:`doc_project_settings`.
191+
change project settings, you can also use the :menu:`Project > Project Settings`
192+
window to do so. For more information, see :ref:`doc_project_settings`.
192193

193194
In the next part, we will discuss another key concept in games and in Godot:
194195
creating instances of a scene.

0 commit comments

Comments
 (0)