Skip to content

Commit

Permalink
✨ [Nodes] Show description of inputs next to the pin
Browse files Browse the repository at this point in the history
Allows to show the description of Input Functions somewhere, and adds a second place to see description of Input Values
  • Loading branch information
JulesFouchy committed Mar 18, 2024
1 parent 2a9de9e commit 6a4eac5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
18 changes: 14 additions & 4 deletions src/Cool/ImGui/ImGuiExtras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@ namespace Cool::ImGuiExtras {
void help_marker(const char* text)
{
ImGui::SameLine();
ImGui::TextDisabled(" " ICOMOON_INFO);
help_marker_icon();
if (ImGui::BeginItemTooltip())
{
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.f);
ImGui::TextUnformatted(text);
ImGui::PopTextWrapPos();
help_marker_tooltip_content(text);
ImGui::EndTooltip();
}
}

void help_marker_icon()
{
ImGui::TextDisabled(" " ICOMOON_INFO);
}

void help_marker_tooltip_content(const char* text)
{
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.f);
ImGui::TextUnformatted(text);
ImGui::PopTextWrapPos();
}

bool angle_wheel(const char* label, float* value_p, int number_of_snaps, float snaps_offset, bool always_snap)
{
static constexpr float thickness = 2.0f;
Expand Down
7 changes: 6 additions & 1 deletion src/Cool/ImGui/ImGuiExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

namespace Cool::ImGuiExtras {

/// A small "?" that displays some text when hovered.
/// A small info icon that displays some text when hovered.
void help_marker(const char* text);

/// A building block for help_marker(). In most cases you should just use help_marker(). This is only needed when you need to customize how help_marker() is rendered.
void help_marker_icon();
/// A building block for help_marker(). In most cases you should just use help_marker(). This is only needed when you need to customize how help_marker() is rendered.
void help_marker_tooltip_content(const char* text);

/// A widget to pick an angle (in radians), displayed as a direction on a wheel
/// When SHIFT is pressed (or `always_snap` is set to true) the angle will snap to some precise angles. `number_of_snaps` controls the number of such angles, and `snaps_offset` will offset these.
/// `number_of_snaps` must be >= 1. `snaps_offset` is expressed in radians.
Expand Down
27 changes: 24 additions & 3 deletions src/Cool/Nodes/EditorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Cool/DebugOptions/DebugOptions.h"
#include "Cool/ImGui/Fonts.h"
#include "Cool/ImGui/IcoMoonCodepoints.h"
#include "Cool/ImGui/ImGuiExtras.h"
#include "Cool/ImGui/ImGuiExtrasStyle.h"
#include "Cool/ImGui/icon_fmt.h"
#include "Cool/Nodes/EditorImpl.h"
Expand Down Expand Up @@ -324,6 +325,13 @@ static auto output_pin_icon(size_t pin_index)
: ax::Drawing::IconType::Circle;
}

void NodesEditorImpl::help_marker_for_pin(std::string text)
{
ImGuiExtras::help_marker_icon();
if (ImGui::IsItemHovered(ImGuiHoveredFlags_ForTooltip))
_deferred_tooltip_text = std::move(text); // HACK don't create the tooltip here, because imgui-node-editor doesn't support it (even when calling Suspend() and Resume()) because of a bug (https://github.com/thedmd/imgui-node-editor/issues/282)
}

void NodesEditorImpl::render_node(Node& node, NodeId const& id, NodesConfig& nodes_cfg, NodesLibrary const& library, ax::NodeEditor::Utilities::BlueprintNodeBuilder& builder)
{
auto const color = nodes_cfg.node_color(node, id);
Expand Down Expand Up @@ -375,6 +383,11 @@ void NodesEditorImpl::render_node(Node& node, NodeId const& id, NodesConfig& nod
ImGui::TextUnformatted(input_pin.name().c_str());
ImGui::Spring(0);
}
if (!input_pin.description().empty())
{
help_marker_for_pin(input_pin.description());
ImGui::Spring(0);
}
ImGui::PopStyleVar();
builder.EndInput();
}
Expand All @@ -392,6 +405,11 @@ void NodesEditorImpl::render_node(Node& node, NodeId const& id, NodesConfig& nod
ImGui::Spring(0);
ImGui::TextUnformatted(output_pin.name().c_str());
}
if (!output_pin.description().empty())
{
ImGui::Spring(0);
help_marker_for_pin(output_pin.description());
}
ImGui::Spring(0);
render_pin_icon(output_pin_icon(idx), alpha, nodes_cfg.pin_color(output_pin, idx, node, id));
ImGui::PopStyleVar();
Expand Down Expand Up @@ -711,11 +729,9 @@ auto NodesEditorImpl::imgui_workspace(NodesConfig& nodes_cfg, NodesLibrary const
}

bool graph_has_changed = false;
_deferred_tooltip_text.reset(); // Might be filled by one of the nodes, and will be rendered later

ed::SetCurrentEditor(_context);
// GImGui->CurrentWindow->DrawList->AddRectFilled(ImVec2{0.f, 0.f}, ImVec2{0.f, 0.f}, ImGui::GetColorU32(ImGuiCol_SeparatorHovered), 0.0f); // TODO(JF) Remove this. (But atm when removing it the view gets clipped when zooming in) EDIT this is caused by the suspend / resume
GImGui->CurrentWindow->DrawList->AddLine(ImVec2{0.f, 0.f}, ImVec2{0.f, 0.f}, ImGui::GetColorU32(ImGuiCol_SeparatorHovered)); // TODO(JF) Remove this. (But atm when removing it the view gets clipped when zooming in) EDIT this is caused by the suspend / resume

ed::Begin("Node editor");

render_editor(nodes_cfg, library);
Expand All @@ -740,6 +756,11 @@ auto NodesEditorImpl::imgui_workspace(NodesConfig& nodes_cfg, NodesLibrary const
}

ed::Suspend();
if (_deferred_tooltip_text.has_value() && ImGui::BeginTooltip())
{
ImGuiExtras::help_marker_tooltip_content(_deferred_tooltip_text->c_str());
ImGui::EndTooltip();
}
if (ImGui::BeginPopup("Nodes Library Menu"))
{
auto const new_node_def_id = imgui_nodes_menu(library, nodes_cfg.maybe_disable_node_definition(), _menu_just_opened);
Expand Down
4 changes: 3 additions & 1 deletion src/Cool/Nodes/EditorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class NodesEditorImpl : public INodesEditor {
auto wants_to_open_nodes_menu() const -> bool;
void open_nodes_menu();
void remove_all_links_connected_to_input_pin(PinId const& input_pin_id, NodesConfig& nodes_cfg);
void help_marker_for_pin(std::string text);

private:
internal::UniqueEdContext _context{};
Expand All @@ -88,7 +89,8 @@ class NodesEditorImpl : public INodesEditor {
Pin const* _new_link_pin = nullptr;
bool _link_has_just_been_released{false}; // HACK because we can't open the nodes menu just after a link has been released (otherwise _next_node_position is wrong). So we have to delay the opening.

int _frames_count{0};
int _frames_count{0};
std::optional<std::string> _deferred_tooltip_text{};

private:
// ImColor GetIconColor(PinType type);
Expand Down
5 changes: 3 additions & 2 deletions src/Cool/Nodes/Pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Cool {

Pin::Pin(std::string_view name)
: _name{name}
Pin::Pin(std::string name, std::string description)
: _name{std::move(name)}
, _description{std::move(description)}
, _id{reg::internal::generate_uuid()}
{
}
Expand Down
5 changes: 4 additions & 1 deletion src/Cool/Nodes/Pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ enum class PinKind {
class Pin {
public:
Pin() = default;
explicit Pin(std::string_view name);
Pin(std::string name, std::string description);
Pin(Pin const&) = default;
Pin(Pin&&) = default;
auto operator=(Pin const&) -> Pin& = default;
auto operator=(Pin&&) -> Pin& = default;
virtual ~Pin() = default;

[[nodiscard]] auto name() const -> std::string const& { return _name; }
[[nodiscard]] auto description() const -> std::string const& { return _description; }
[[nodiscard]] auto id() const -> PinId const& { return _id; }

void set_id(PinId const& id) { _id = id; }
Expand All @@ -36,6 +37,7 @@ class Pin {

private:
std::string _name{};
std::string _description{};
PinId _id{};

private:
Expand All @@ -46,6 +48,7 @@ class Pin {
{
archive(
cereal::make_nvp("Name", _name),
cereal::make_nvp("Description", _description),
cereal::make_nvp("ID", _id)
);
}
Expand Down

0 comments on commit 6a4eac5

Please sign in to comment.