From 170293475c36b4c462bdad372a03533d2b948bf1 Mon Sep 17 00:00:00 2001 From: Fabian Schempp Date: Tue, 13 Apr 2021 22:11:58 +0200 Subject: Nodes: Tooltip for Group Input properties With this patch, users can define custom tooltips for the exposed properties of their Geometry Nodes Groups. Currently this custom tooltips are only used in the modifier panel, but its a long term goal to use it in the node editor. Reviewer: Hans Goudey Differential Revision: https://developer.blender.org/D10884 --- source/blender/editors/space_node/node_buttons.c | 5 +++++ source/blender/makesdna/DNA_node_types.h | 1 + source/blender/makesrna/intern/rna_nodetree.c | 10 ++++++++++ source/blender/modifiers/intern/MOD_nodes.cc | 8 ++++++++ 4 files changed, 24 insertions(+) (limited to 'source') diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index eb89658857b..336b0c46a81 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -157,6 +157,11 @@ static void draw_socket_list(const bContext *C, RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, socket, &socket_ptr); uiItemR(layout, &socket_ptr, "name", 0, NULL, ICON_NONE); + /* Display descriptions only for Geometry Nodes, since it's only used in the modifier panel. */ + if (ntree->type == NTREE_GEOMETRY) { + uiItemR(layout, &socket_ptr, "description", 0, NULL, ICON_NONE); + } + if (socket->typeinfo->interface_draw) { socket->typeinfo->interface_draw((bContext *)C, layout, &socket_ptr); } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 334d683deff..282d71f6a87 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -125,6 +125,7 @@ typedef struct bNodeSocket { /** Custom dynamic defined label, MAX_NAME. */ char label[64]; + char description[64]; /** Cached data from execution. */ void *cache; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 1016d31f11b..21460607e38 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -9725,6 +9725,11 @@ static void rna_def_node_socket(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Identifier", "Unique identifier for mapping sockets"); + prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "description"); + RNA_def_property_ui_text(prop, "Tooltip", "Socket tooltip"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocket_update"); + prop = RNA_def_property(srna, "is_output", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_NodeSocket_is_output_get", NULL); RNA_def_property_clear_flag(prop, PROP_EDITABLE); @@ -9869,6 +9874,11 @@ static void rna_def_node_socket_interface(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Identifier", "Unique identifier for mapping sockets"); + prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "description"); + RNA_def_property_ui_text(prop, "Tooltip", "Socket tooltip"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + prop = RNA_def_property(srna, "is_output", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_NodeSocket_is_output_get", NULL); RNA_def_property_clear_flag(prop, PROP_EDITABLE); diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 4fc940b3244..216a1c43d3e 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -703,6 +703,14 @@ static IDProperty *socket_add_property(IDProperty *settings_prop_group, IDP_AddToGroup(ui_container, prop_ui_group); } + /* Set property description (tooltip). */ + IDPropertyTemplate property_description_template; + property_description_template.string.str = socket.description; + property_description_template.string.len = BLI_strnlen(socket.description, MAX_NAME) + 1; + property_description_template.string.subtype = IDP_STRING_SUB_UTF8; + IDProperty *description = IDP_New(IDP_STRING, &property_description_template, "description"); + IDP_AddToGroup(prop_ui_group, description); + /* Create the properties for the socket's UI settings. */ if (property_type.create_min_ui_prop != nullptr) { IDP_AddToGroup(prop_ui_group, property_type.create_min_ui_prop(socket, "min")); -- cgit v1.2.3