Skip to content

Commit b21addc

Browse files
Add page about gdextension docs generation (#9667)
* Adding page about gdextension docs generation --------- Co-authored-by: Max Hilbrunner <[email protected]>
1 parent 7b26368 commit b21addc

File tree

4 files changed

+174
-1
lines changed

4 files changed

+174
-1
lines changed
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
.. _doc_gdextension_docs_system:
2+
3+
GDExtension documentation system
4+
================================
5+
6+
.. note::
7+
8+
Adding documentation for GDExtensions is only possible for Godot 4.3 and later. The support can be integrated into your project
9+
regardless because the snippet will check if you use the appropriate godot-cpp version.
10+
If you set the ``compatability_minimum`` to 4.2 and you load a project with the extension through a 4.2 editor, the
11+
documentation page for that class will be empty. The extension itself will still work.
12+
13+
The GDExtension documentation system works in a similar manner to the built-in engine documentation. It uses a series of
14+
XML files (one per class) to document the exposed constructors, properties, methods, constants, signals, and theme items of each class.
15+
16+
.. note::
17+
18+
We are assuming you are using the project files explained in the :ref:`GDExtension C++ Example <doc_gdextension_cpp_example>`
19+
with the following structure:
20+
21+
gdextension_cpp_example/ # GDExtension directory
22+
|
23+
+--demo/ # game example/demo to test the extension
24+
| |
25+
| +--main.tscn
26+
| |
27+
| +--bin/
28+
| |
29+
| +--gdexample.gdextension
30+
|
31+
+--godot-cpp/ # C++ bindings
32+
|
33+
+--src/ # source code of the extension we are building
34+
| |
35+
| +--register_types.cpp
36+
| +--register_types.h
37+
| +--gdexample.cpp
38+
| +--gdexample.h
39+
40+
Inside the Godot demo project directory of your GDExtension directory, run the following terminal command:
41+
42+
.. code-block:: none
43+
44+
# Replace "godot" with the full path to a Godot editor binary
45+
# if Godot is not installed in your `PATH`.
46+
godot --doctool ../ --gdextension-docs
47+
48+
This command calls upon the Godot editor binary to generate documentation via the ``--doctool``
49+
and ``--gdextension-docs`` commands. The ``../`` addition is to let Godot know where the GDExtension
50+
SConstruct file is located. By calling this command, Godot generates a ``doc_classes`` directory inside the
51+
project directory in which it generates XML files for the GDExtension classes. Those files
52+
can then be edited to add information about member variables, methods, signals, and more.
53+
54+
To add the now edited documentation to the GDExtension and let the editor load it,
55+
you need to add the following lines to your SConstruct file:
56+
57+
.. code-block:: py
58+
59+
if env["target"] in ["editor", "template_debug"]:
60+
try:
61+
doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
62+
sources.append(doc_data)
63+
except AttributeError:
64+
print("Not including class reference as we're targeting a pre-4.3 baseline.")
65+
66+
The if-statement checks if we are compiling the GDExtension library with the ``editor`` and ``template_debug``
67+
flags. SCons then tries to load all the XML files inside the ``doc_classes`` directory and appends them
68+
to the ``sources`` variable which already includes all the source files of your extension. If it fails
69+
it means we are currently trying to compile the library when the ``godot_cpp`` is set to a version before 4.3.
70+
71+
After loading the extension in a 4.3 Godot editor or later and open the documentation of your extension class
72+
either by :kbd:`Ctrl + Click` in the script editor or the Editor help dialog you will see something like this:
73+
74+
.. image:: img/gdextension_docs_generation.webp
75+
76+
Documentation styling
77+
---------------------
78+
79+
To style specific parts of text you can use BBCode tags similarly to how they can be used in :ref:`RichTextLabels <doc_bbcode_in_richtextlabel>`.
80+
You can set text as bold, italic, underlined, colored, codeblocks etc. by embedding them in tags like this:
81+
82+
.. code-block:: none
83+
84+
[b]this text will be shown as bold[/b]
85+
86+
Currently they supported tags for the GDExtension documentation system are:
87+
88+
.. list-table::
89+
:class: wrap-normal
90+
:width: 100%
91+
:widths: 60 40
92+
93+
* - Tag
94+
- Example
95+
96+
* - | **b**
97+
| Makes ``{text}`` use the bold (or bold italics) font of ``RichTextLabel``.
98+
99+
- ``[b]{text}[/b]``
100+
101+
* - | **i**
102+
| Makes ``{text}`` use the italics (or bold italics) font of ``RichTextLabel``.
103+
104+
- ``[i]{text}[/i]``
105+
106+
* - | **u**
107+
| Makes ``{text}`` underlined.
108+
109+
- ``[u]{text}[/u]``
110+
111+
* - | **s**
112+
| Makes ``{text}`` strikethrough.
113+
114+
- ``[s]{text}[/s]``
115+
116+
* - | **kbd**
117+
| Makes ``{text}`` use the mono font and styles the text color and background like a shortcut.
118+
119+
- ``[code]{text}[/code]``
120+
121+
* - | **code**
122+
| Makes inline ``{text}`` use the mono font and styles the text color and background like code.
123+
124+
- ``[code]{text}[/code]``
125+
126+
* - | **codeblocks**
127+
| Makes multiline ``{text}`` use the mono font and styles the text color and background like code.
128+
| The addition of the ``[gdscript]`` tag highlights the GDScript specific syntax.
129+
130+
- | ``[codeblocks]``
131+
| ``[gdscript]``
132+
| ``{text}``
133+
| ``[/gdscript]``
134+
| ``[/codeblocks]``
135+
136+
* - | **center**
137+
| Makes ``{text}`` horizontally centered.
138+
| Same as ``[p align=center]``.
139+
140+
- ``[center]{text}[/center]``
141+
142+
* - | **url**
143+
| Creates a hyperlink (underlined and clickable text). Can contain optional
144+
``{text}`` or display ``{link}`` as is.
145+
| **Must be handled with the "meta_clicked" signal to have an effect,** see :ref:`doc_bbcode_in_richtextlabel_handling_url_tag_clicks`.
146+
147+
- | ``[url]{link}[/url]``
148+
| ``[url={link}]{text}[/url]``
149+
150+
* - | **img**
151+
| Inserts an image from the ``{path}`` (can be any valid :ref:`class_Texture2D` resource).
152+
| If ``{width}`` is provided, the image will try to fit that width maintaining
153+
the aspect ratio.
154+
| If both ``{width}`` and ``{height}`` are provided, the image will be scaled
155+
to that size.
156+
| Add ``%`` to the end of ``{width}`` or ``{height}`` value to specify it as percentages of the control width instead of pixels.
157+
| If ``{valign}`` configuration is provided, the image will try to align to the
158+
surrounding text, see :ref:`doc_bbcode_in_richtextlabel_image_and_table_alignment`.
159+
| Supports configuration options, see :ref:`doc_bbcode_in_richtextlabel_image_options`.
160+
161+
- | ``[img]{path}[/img]``
162+
| ``[img={width}]{path}[/img]``
163+
| ``[img={width}x{height}]{path}[/img]``
164+
| ``[img={valign}]{path}[/img]``
165+
| ``[img {options}]{path}[/img]``
166+
167+
* - | **color**
168+
| Changes the color of ``{text}``. Color must be provided by a common name (see
169+
:ref:`doc_bbcode_in_richtextlabel_named_colors`) or using the HEX format (e.g.
170+
``#ff00ff``, see :ref:`doc_bbcode_in_richtextlabel_hex_colors`).
171+
172+
- ``[color={code/name}]{text}[/color]``

tutorials/scripting/gdextension/gdextension_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _doc_gdextension_file_sections:
1+
.. _doc_gdextension_file:
22

33
The .gdextension file
44
=====================
157 KB
Loading

tutorials/scripting/gdextension/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ GDExtension
1010
what_is_gdextension
1111
gdextension_cpp_example
1212
gdextension_file
13+
gdextension_docs_system

0 commit comments

Comments
 (0)