Skip to content

Commit 509336b

Browse files
committed
Add ability to create tooltip descriptions for dynamically exported properties
1 parent 78c6632 commit 509336b

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

core/object/object.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,8 @@ void Object::_bind_methods() {
20552055
BIND_OBJ_CORE_METHOD(mi);
20562056
}
20572057

2058+
BIND_OBJ_CORE_METHOD(MethodInfo(Variant::STRING, "_get_property_description", PropertyInfo(Variant::STRING_NAME, "property")));
2059+
20582060
// These are actually `Variant` methods, but that doesn't matter since scripts can't inherit built-in types.
20592061

20602062
BIND_OBJ_CORE_METHOD(MethodInfo(Variant::BOOL, "_iter_init", PropertyInfo(Variant::ARRAY, "iter")));

doc/classes/Object.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,30 @@
270270
[b]Note:[/b] Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via [code]super[/code] in GDScript or its equivalents in other languages. Call order depends on the [code]reversed[/code] argument of [method notification] and varies between different notifications. Most notifications are sent in the forward order (i.e. Object class first, most derived class last).
271271
</description>
272272
</method>
273+
<method name="_get_property_description" qualifiers="virtual">
274+
<return type="String" />
275+
<param index="0" name="property" type="StringName" />
276+
<description>
277+
Override this method to provide a custom description for the given [param property]. The description is displayed as a tooltip in the Inspector dock when hovering over the property.
278+
This is particularly useful for dynamically exported properties (via [method _get_property_list]) which cannot be documented using the standard documentation system.
279+
[codeblocks]
280+
[gdscript]
281+
func _get_property_description(property):
282+
if property == "my_dynamic_property":
283+
return "A dynamically exported property with a custom tooltip."
284+
return ""
285+
[/gdscript]
286+
[csharp]
287+
public override string _GetPropertyDescription(StringName property)
288+
{
289+
if (property == "my_dynamic_property")
290+
return "A dynamically exported property with a custom tooltip.";
291+
return "";
292+
}
293+
[/csharp]
294+
[/codeblocks]
295+
</description>
296+
</method>
273297
<method name="_property_can_revert" qualifiers="virtual">
274298
<return type="bool" />
275299
<param index="0" name="property" type="StringName" />

editor/inspector/editor_inspector.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,16 @@ Control *EditorProperty::make_custom_tooltip(const String &p_text) const {
14051405
}
14061406
}
14071407

1408+
if (object->has_method("_get_property_description")) {
1409+
const String custom_description = object->call("_get_property_description", property);
1410+
if (!custom_description.is_empty()) {
1411+
if (!prologue.is_empty()) {
1412+
prologue += '\n';
1413+
}
1414+
prologue += custom_description;
1415+
}
1416+
}
1417+
14081418
if (!symbol.is_empty() || !prologue.is_empty()) {
14091419
return EditorHelpBitTooltip::make_tooltip(const_cast<EditorProperty *>(this), symbol, prologue);
14101420
}
@@ -2304,6 +2314,16 @@ Control *EditorInspectorSection::make_custom_tooltip(const String &p_text) const
23042314
}
23052315
}
23062316

2317+
if (object->has_method("_get_property_description")) {
2318+
const String custom_description = object->call("_get_property_description", related_enable_property);
2319+
if (!custom_description.is_empty()) {
2320+
if (!prologue.is_empty()) {
2321+
prologue += '\n';
2322+
}
2323+
prologue += custom_description;
2324+
}
2325+
}
2326+
23072327
if (!symbol.is_empty() || !prologue.is_empty()) {
23082328
return EditorHelpBitTooltip::make_tooltip(const_cast<EditorInspectorSection *>(this), symbol, prologue);
23092329
}

0 commit comments

Comments
 (0)