@@ -5,180 +5,67 @@ Adding documentation
55
66.. note ::
77
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 ``compatibility_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.
8+ Adding documentation for GDExtensions is only possible with Godot 4.3 and later.
129
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.
10+ The GDExtension documentation system works in a similar manner to the built-in engine documentation: It uses
11+ :ref: `XML files <doc_class_reference_primer >` (one per class) to document the exposed constructors, properties, methods,
12+ constants, signals, and more.
1513
16- .. note ::
14+ To get started, identify your project's ``demo `` folder, which should contain a Godot project with your extension
15+ installed and working. If you are using `godot-cpp-template <https://github.com/godotengine/godot-cpp-template >`__, your
16+ GDExtension project already has a ``demo `` folder. Alternatively, you can add one by following the steps
17+ described in :ref: `doc_godot_cpp_getting_started `.
18+ Inside the ``demo `` folder, run the following terminal command:
1719
18- We are assuming you are using the project files explained in the :ref: `example project <doc_godot_cpp_getting_started >`
19- with the following structure:
20-
21- .. code-block :: none
22-
23- gdextension_cpp_example/ # GDExtension directory
24- |
25- +--demo/ # game example/demo to test the extension
26- | |
27- | +--main.tscn
28- | |
29- | +--bin/
30- | |
31- | +--gdexample.gdextension
32- |
33- +--godot-cpp/ # C++ bindings
34- |
35- +--src/ # source code of the extension we are building
36- | |
37- | +--register_types.cpp
38- | +--register_types.h
39- | +--gdexample.cpp
40- | +--gdexample.h
41-
42- Inside the Godot demo project directory of your GDExtension directory, run the following terminal command:
43-
44- .. code-block :: none
20+ .. code-block :: shell
4521
4622 # Replace "godot" with the full path to a Godot editor binary
4723 # if Godot is not installed in your `PATH`.
4824 godot --doctool ../ --gdextension-docs
4925
50- This command calls upon the Godot editor binary to generate documentation via the ``--doctool ``
51- and `` --gdextension-docs `` commands. The ``../ `` addition is to let Godot know where the GDExtension
52- SConstruct file is located. By calling this command, Godot generates a `` doc_classes `` directory inside the
53- project directory in which it generates XML files for the GDExtension classes. Those files
54- can then be edited to add information about member variables, methods, signals, and more .
26+ This command instructs Godot to generate documentation via the ``--doctool `` and `` --gdextension-docs `` commands.
27+ The ``../ `` argument specifies the base path of your GDExtension.
28+
29+ After running this command, you should find XML files for your registered GDExtension classes inside the `` doc_classes ``
30+ folder in your GDExtension project. You could edit them now, but for this tutorial, the empty files will suffice .
5531
56- To add the now edited documentation to the GDExtension and let the editor load it,
57- you need to add the following lines to your SConstruct file:
32+ Now that you have XML files containing your documentation, the next step is to include them in your GDExtension binary.
33+ Assuming you are using SCons as your build system, you can add the following lines to your ``SConstruct `` file. If you
34+ are using `godot-cpp-template <https://github.com/godotengine/godot-cpp-template >`__, your file should already contain
35+ these lines.
5836
5937.. code-block :: py
6038
6139 if env[" target" ] in [" editor" , " template_debug" ]:
62- try :
63- doc_data = env.GodotCPPDocData(" src/gen/doc_data.gen.cpp" , source = Glob(" doc_classes/*.xml" ))
64- sources.append(doc_data)
65- except AttributeError :
66- print (" Not including class reference as we're targeting a pre-4.3 baseline." )
40+ doc_data = env.GodotCPPDocData(" src/gen/doc_data.gen.cpp" , source = Glob(" doc_classes/*.xml" ))
41+ sources.append(doc_data)
6742
68- The if-statement checks if we are compiling the GDExtension library with the ``editor `` and ``template_debug ``
69- flags. SCons then tries to load all the XML files inside the ``doc_classes `` directory and appends them
70- to the ``sources `` variable which already includes all the source files of your extension. If it fails
71- it means we are currently trying to compile the library when the ``godot_cpp `` is set to a version before 4.3.
43+ The if-statement avoids adding the documentation to release builds of your GDExtension, where it is not needed.
44+ SCons then loads all the XML files inside the ``doc_classes `` directory, and appends the resulting targets
45+ to the ``sources `` array, to be included in your GDExtension build.
7246
73- After loading the extension in a 4.3 Godot editor or later and open the documentation of your extension class
74- either by :kbd: `Ctrl + Click ` in the script editor or the Editor help dialog you will see something like this:
47+ After building, launch your ``demo `` project again. You can open the documentation of one of your extension
48+ classes either using :kbd: `Ctrl + Click ` on a class name in the script editor, or inside by finding it in the Editor
49+ help dialog. If everything went well, you should see something like this:
7550
7651.. image :: img/gdextension_docs_generation.webp
7752
78- Documentation styling
79- ---------------------
80-
81- 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 >`.
82- You can set text as bold, italic, underlined, colored, codeblocks etc. by embedding them in tags like this:
83-
84- .. code-block :: none
85-
86- [b]this text will be shown as bold[/b]
87-
88- Currently, the supported tags for the GDExtension documentation system are:
89-
90- .. list-table ::
91- :class: wrap-normal
92- :width: 100%
93- :widths: 60 40
94-
95- * - Tag
96- - Example
97-
98- * - | **b **
99- | Makes ``{text}`` use the bold (or bold italics) font of ``RichTextLabel``.
100-
101- - ``[b]{text}[/b] ``
102-
103- * - | **i **
104- | Makes ``{text}`` use the italics (or bold italics) font of ``RichTextLabel``.
105-
106- - ``[i]{text}[/i] ``
107-
108- * - | **u **
109- | Makes ``{text}`` underlined.
110-
111- - ``[u]{text}[/u] ``
112-
113- * - | **s **
114- | Makes ``{text}`` strikethrough.
115-
116- - ``[s]{text}[/s] ``
117-
118- * - | **kbd **
119- | Makes ``{text}`` use a grey beveled background, indicating a keyboard shortcut.
120-
121- - ``[kbd]{text}[/kbd] ``
122-
123- * - | **code **
124- | Makes inline ``{text}`` use the mono font and styles the text color and background like code.
125-
126- - ``[code]{text}[/code] ``
127-
128- * - | **codeblocks **
129- | Makes multiline ``{text}`` use the mono font and styles the text color and background like code.
130- | The addition of the ``[gdscript]`` tag highlights the GDScript specific syntax.
131-
132- - | ``[codeblocks] ``
133- | ``[gdscript]``
134- | ``{text}``
135- | ``[/gdscript]``
136- | ``[/codeblocks]``
137-
138- * - | **center **
139- | Makes ``{text}`` horizontally centered.
140- | Same as ``[p align=center]``.
141-
142- - ``[center]{text}[/center] ``
143-
144- * - | **url **
145- | Creates a hyperlink (underlined and clickable text). Can contain optional ``{text}`` or display ``{link}`` as is.
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`).
53+ Writing and styling documentation
54+ ---------------------------------
17155
172- - ``[color={code/name}]{text}[/color] ``
56+ The format of the class reference XML files is the same as the one used by Godot. Is is documented in
57+ :ref: `doc_class_reference_primer `.
17358
59+ If you are looking for pointers to write high quality documentation, feel free to refer to Godot's
60+ `documentation guidelines <https://contributing.godotengine.org/en/latest/documentation/guidelines/index.html >`__.
17461
17562Publishing documentation online
17663-------------------------------
17764
17865You may want to publish an online reference for your GDExtension, similar to this website.
17966The most important step is to build reStructuredText (``.rst ``) files from your XML class reference:
18067
181- .. code-block :: bash
68+ .. code-block :: shell
18269
18370 # You need a version.py file, so download it first.
18471 curl -sSLO https://raw.githubusercontent.com/godotengine/godot/refs/heads/master/version.py
@@ -190,7 +77,10 @@ The most important step is to build reStructuredText (``.rst``) files from your
19077 Your ``.rst `` files will now be available in ``docs/classes/ ``. From here, you can use
19178any documentation builder that supports reStructuredText syntax to create a website from them.
19279
193- `godot-docs <https://github.com/godotengine/godot-docs >`_ uses `Sphinx <https://www.sphinx-doc.org/en/master/ >`_. You can use the repository as a basis to build your own documentation system. The following guide describes the basic steps, but they are not exhaustive: You will need a bit of personal insight to make it work.
80+ `godot-docs <https://github.com/godotengine/godot-docs >`_ uses `Sphinx <https://www.sphinx-doc.org/en/master/ >`_.
81+ You can use the repository as a basis to build your own documentation system.
82+ The following guide describes the basic steps, but they are not exhaustive:
83+ You will need a bit of personal insight to make it work.
19484
195851. Add `godot-docs <https://github.com/godotengine/godot-docs >`_ as a submodule to your ``docs/ `` folder.
196862. Copy over its ``conf.py ``, ``index.rst ``, ``.readthedocs.yaml `` files into ``/docs/ ``. You may later decide to copy over and edit more of godot-docs' files, like ``_templates/layout.html ``.
0 commit comments