diff options
author | Johnny Matthews <guitargeek> | 2021-09-24 18:02:51 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-09-24 18:13:40 +0300 |
commit | ef45399f3be0955ba8a8c678a5f5ed18ed8c7759 (patch) | |
tree | 96384293376901e39c364ed7f01b690a95ddfe42 /source/blender/editors | |
parent | 4a2c63f4bd7e3cbb8cd80655270f3184d660e51d (diff) |
Nodes: initial support for socket tooltips
This adds initial limited support for socket tooltips. It's limited
in a couple of ways for now:
* Only works when hovering over the socket shape, not when hovering
over the value in the socket.
* Only works for built-in nodes that already use the new node
declaration system. This can later be extended to support pynodes.
Those limitations are well worth it for now, given that the
implementation is quite simple and the impact on usability is quite
large. More complex updates to the layout system, that would allow
showing socket tooltips in the nodes, can be done later. With the
current implementation we can at least start writing tooltips for
geometry nodes now.
This commit already adds tooltips for the Cylinder node as an example.
Differential Revision: https://developer.blender.org/D12607
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_node/node_draw.cc | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index b57696cb676..499ccb8a889 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -79,6 +79,7 @@ #include "RNA_access.h" #include "NOD_geometry_nodes_eval_log.hh" +#include "NOD_node_declaration.hh" #include "FN_field_cpp_type.hh" @@ -1085,12 +1086,37 @@ static void node_socket_draw_nested(const bContext *C, but, [](bContext *C, void *argN, const char *UNUSED(tip)) { SocketTooltipData *data = (SocketTooltipData *)argN; - std::optional<std::string> str = create_socket_inspection_string( + std::optional<std::string> socket_inspection_str = create_socket_inspection_string( C, *data->ntree, *data->node, *data->socket); - if (str.has_value()) { - return BLI_strdup(str->c_str()); + + std::stringstream output; + if (data->node->declaration != nullptr) { + ListBase *list; + Span<blender::nodes::SocketDeclarationPtr> decl_list; + + if (data->socket->in_out == SOCK_IN) { + list = &data->node->inputs; + decl_list = data->node->declaration->inputs(); + } + else { + list = &data->node->outputs; + decl_list = data->node->declaration->outputs(); + } + + const int socket_index = BLI_findindex(list, data->socket); + const blender::nodes::SocketDeclaration &socket_decl = *decl_list[socket_index]; + blender::StringRef description = socket_decl.description(); + if (!description.is_empty()) { + output << TIP_(description.data()) << ".\n\n"; + } + + if (socket_inspection_str.has_value()) { + output << *socket_inspection_str; + return BLI_strdup(output.str().c_str()); + } } - return BLI_strdup(TIP_("The socket value has not been computed yet")); + output << TIP_("The socket value has not been computed yet"); + return BLI_strdup(output.str().c_str()); }, data, MEM_freeN); |