Geometry Node: Multi-input socket tooltip #104468

Merged
Jacques Lucke merged 33 commits from mod_moder/blender:multi_input_tooltip into main 2024-04-22 19:49:08 +02:00
1 changed files with 66 additions and 0 deletions
Showing only changes of commit d4e058badb - Show all commits

View File

@ -1665,6 +1665,67 @@ static geo_log::GeoTreeLog *geo_tree_log_for_socket(const bNodeTree &ntree,
return tree_draw_ctx.geo_log_by_zone.lookup_default(zone, nullptr);
}
static int64_t line_size(const StringRef string)
{
return string.find_last_of("\n");
}
static Vector<std::string> lines(std::string text)
{
Vector<std::string> result;
std::istringstream text_stream(text);
for (std::string line; std::getline(text_stream, line);) {
result.append(line);
}
return result;
}
static std::optional<std::string> create_multi_input_log_inspection_string(
const bNodeTree &ntree, const bNodeSocket &socket, TreeDrawContext &tree_draw_ctx)
{
if (!socket.is_multi_input()) {
return std::nullopt;
}
Vector<std::string> inputs;
for (const bNodeLink *link : socket.directly_linked_links()) {
if (link->fromnode->is_dangling_reroute()) {
continue;
}
const bNodeSocket &connected_socket = *link->fromsock;
geo_log::GeoTreeLog *geo_tree_log = geo_tree_log_for_socket(
ntree, connected_socket, tree_draw_ctx);
std::optional<std::string> input_log = create_log_inspection_string(geo_tree_log,
connected_socket);
if (input_log.has_value()) {
inputs.append(std::move(*input_log));
}
}
if (inputs.is_empty()) {
return std::nullopt;
}
std::stringstream ss;
for (const int index : inputs.index_range()) {
const std::string &info = inputs[index];
ss << index + 1 << ". ";
const Vector<std::string> lines_of_info = lines(info);
for (const std::string &line : lines_of_info) {
ss << " " << line;
if (&line != &lines_of_info.last()) {
ss << "\n";
}
}
if (&info != &inputs.last()) {
ss << ".\n";
}
}
return ss.str();
}
JacquesLucke marked this conversation as resolved
Review

Not sure important here, but the const probably prevents moving the string.

Not sure important here, but the `const` probably prevents moving the string.

I think since move constructor of std::basic_string is not explicit and RVO is enabled by compiler, this should be handled correct (for source: https://www.cppstories.com/2017/01/const-move-and-rvo/)

I think since move constructor of `std::basic_string` is not explicit and RVO is enabled by compiler, this should be handled correct (for source: https://www.cppstories.com/2017/01/const-move-and-rvo/)
Review

Fair enough. The situation may be a bit more complex with multiple return statements, and because we return an optional, but doesn't matter too much here anyway.

Fair enough. The situation may be a bit more complex with multiple return statements, and because we return an `optional`, but doesn't matter too much here anyway.
static std::string node_socket_get_tooltip(const SpaceNode *snode,
mod_moder marked this conversation as resolved Outdated

Please use multiple lines here instead of putting the statement into the if condition.

Please use multiple lines here instead of putting the statement into the `if` condition.
const bNodeTree &ntree,
const bNodeSocket &socket)
@ -1687,6 +1748,11 @@ static std::string node_socket_get_tooltip(const SpaceNode *snode,
if (std::optional<std::string> info = create_log_inspection_string(geo_tree_log, socket)) {
inspection_strings.append(std::move(*info));
}
else if (std::optional<std::string> info = create_multi_input_log_inspection_string(
ntree, socket, tree_draw_ctx))
{
inspection_strings.append(std::move(*info));
}
if (std::optional<std::string> info = create_declaration_inspection_string(socket)) {
inspection_strings.append(std::move(*info));
}