From 76da87bf07470072c3a16ca93f45f68859d20315 Mon Sep 17 00:00:00 2001 From: tetrapod00 <145553014+tetrapod00@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:37:45 -0800 Subject: [PATCH] Document [ExportToolButton] --- .../scripting/c_sharp/c_sharp_exports.rst | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tutorials/scripting/c_sharp/c_sharp_exports.rst b/tutorials/scripting/c_sharp/c_sharp_exports.rst index a1985b199..b6a875a64 100644 --- a/tutorials/scripting/c_sharp/c_sharp_exports.rst +++ b/tutorials/scripting/c_sharp/c_sharp_exports.rst @@ -489,6 +489,39 @@ If you want to set an initial value, you must specify it explicitly: [Export(PropertyHint.Enum, "Rebecca,Mary,Leah")] public string CharacterName { get; set; } = "Rebecca"; + +Exporting inspector buttons with ``[ExportToolButton]`` +------------------------------------------------------- + +If you want to create a clickable button in the inspector, you can use the +``[ExportToolButton]`` attribute. This exports a Callable property or field as +a clickable button. Since this runs in the editor, usage of the :ref:`[Tool] +` attribute is required. When the button is +pressed, the callable is called: + +.. code-block:: csharp + + [Tool] + public partial class MyNode : Node + { + [ExportToolButton("Click me!")] + public Callable ClickMeButton => Callable.From(ClickMe); + + public void ClickMe() + { + GD.Print("Hello world!"); + } + } + +You can also set an icon for the button with a second argument. If specified, an +icon will be fetched via :ref:`GetThemeIcon() `, +from the ``"EditorIcons"`` theme type. + +.. code-block:: csharp + + [ExportToolButton("Click me!", Icon = "CharacterBody2D")] + public Callable ClickMeButton => Callable.From(ClickMe); + Exporting collections ---------------------