Skip to content

Commit 6e75669

Browse files
authored
Merge pull request #10607 from tetrapod00/csharp-export-tool-button
Document `[ExportToolButton]` attribute
2 parents d0f7ee6 + 76da87b commit 6e75669

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tutorials/scripting/c_sharp/c_sharp_exports.rst

+33
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,39 @@ If you want to set an initial value, you must specify it explicitly:
489489
[Export(PropertyHint.Enum, "Rebecca,Mary,Leah")]
490490
public string CharacterName { get; set; } = "Rebecca";
491491
492+
493+
Exporting inspector buttons with ``[ExportToolButton]``
494+
-------------------------------------------------------
495+
496+
If you want to create a clickable button in the inspector, you can use the
497+
``[ExportToolButton]`` attribute. This exports a Callable property or field as
498+
a clickable button. Since this runs in the editor, usage of the :ref:`[Tool]
499+
<doc_running_code_in_the_editor>` attribute is required. When the button is
500+
pressed, the callable is called:
501+
502+
.. code-block:: csharp
503+
504+
[Tool]
505+
public partial class MyNode : Node
506+
{
507+
[ExportToolButton("Click me!")]
508+
public Callable ClickMeButton => Callable.From(ClickMe);
509+
510+
public void ClickMe()
511+
{
512+
GD.Print("Hello world!");
513+
}
514+
}
515+
516+
You can also set an icon for the button with a second argument. If specified, an
517+
icon will be fetched via :ref:`GetThemeIcon() <class_Control_method_get_theme_icon>`,
518+
from the ``"EditorIcons"`` theme type.
519+
520+
.. code-block:: csharp
521+
522+
[ExportToolButton("Click me!", Icon = "CharacterBody2D")]
523+
public Callable ClickMeButton => Callable.From(ClickMe);
524+
492525
Exporting collections
493526
---------------------
494527

0 commit comments

Comments
 (0)