Git Product home page Git Product logo

imnodes's Introduction

ImNodes

A standalone Dear ImGui node graph implementation.

image

Library provides core features needed to create a node graph, while leaving it to the user to define content of node. Node layouting is left to the user, however comprehensible example is available which can be used as a base.

A (very) trivial example

static ImNodes::CanvasState canvas;

if (ImGui::Begin("ImNodes", nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
{
    ImNodes::BeginCanvas(&canvas);

    struct Node
    {
        ImVec2 pos{};
        bool selected{};
        ImNodes::Ez::SlotInfo inputs[1];
        ImNodes::Ez::SlotInfo outputs[1];
    };

    static Node nodes[3] = {
        {{50, 100}, false, {{"In", 1}}, {{"Out", 1}}},
        {{250, 50}, false, {{"In", 1}}, {{"Out", 1}}},
        {{250, 100}, false, {{"In", 1}}, {{"Out", 1}}},
    };

    for (Node& node : nodes)
    {
        if (ImNodes::Ez::BeginNode(&node, "Node Title", &node.pos, &node.selected))
        {
            ImNodes::Ez::InputSlots(node.inputs, 1);
            ImNodes::Ez::OutputSlots(node.outputs, 1);
            ImNodes::Ez::EndNode();
        }
    }

    ImNodes::Connection(&nodes[1], "In", &nodes[0], "Out");
    ImNodes::Connection(&nodes[2], "In", &nodes[0], "Out");

    ImNodes::EndCanvas();
}
ImGui::End();

image

imnodes's People

Contributors

andoma avatar jdswebb avatar roblunx avatar rokups avatar sonoro1234 avatar sphaero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imnodes's Issues

Input/Output more than one kind of value

Hello,
I have a question about the I/O nodes.
I was wondering how can one get a output to match more types?
I tried something like this but it did not seem to work:
{"ADD Vector3", []() -> MyNode* { return new MyNode("ADD Vector3", { {"A",WN Position | Rotation | Scale}, {"B",WN Position | Rotation | Scale} }, { {"Output" ,WN Position | Rotation | Scale} }); } }

Am i doing something wrong or is it not yet implemented?

Thank you and sorry for the trouble.

Refusing connections for two nodes already connected

All slots are of the same kind, after output1 is connected to input1 it should be possible to connect output1 to input2.
ImNodesGIF

The error is found in https://github.com/rokups/ImNodes/blob/master/ImNodes.cpp#L832 that should be
if (ignored.node_id == impl->node.id && strcmp(ignored.slot_name, impl->slot.title) == 0 &&

Now trying to make a PR but I must first solve an issue with my last PR where
struct style_ was changed to struct Style which results in a redefinition in C code

Better sample code and documentation

I pasted the sample code on the readme.
I got this
imgui/ImNodesEz.cpp:125: bool ImNodes::Ez::BeginNode(void*, const char*, ImVec2*, bool*): Assertion `GContext != nullptr' failed.
Aborted (core dumped)

something something context. OK.
You have another sample code. Looked through it. Ah!

Pasted this in:
static ImNodes::Ez::Context* context = ImNodes::Ez::CreateContext();

Only to be met with a new assertion fail!
imgui/imgui_draw.cpp:1792: void ImDrawListSplitter::SetCurrentChannel(ImDrawList*, int): Assertion `idx >= 0 && idx < _Count' failed.

Perhaps the sample code was written for a previous version of the library which is now outdated.
In any case, having something to run and play with incrementally is immensely helpful.

CMake Error at CMakeLists.txt:58 (add_executable):

Hello,

I have a problem with the lib:
Would you like to help me @rokups?

C:\Users\Damian\Documents\ImNodes\build>cmake .. .
CMake Warning:
  Ignoring extra path from command line:

   "."


-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- The C compiler identification is MSVC 19.35.32217.1
-- The CXX compiler identification is MSVC 19.35.32217.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- IMGUI_IMPL_SDL set to ON but SDL2 could not be found.
-- Found OpenGL: opengl32
-- IMGUI_IMPL_GLUT set to ON but GLUT could not be found.
-- Configuring done (8.6s)
CMake Error at CMakeLists.txt:58 (add_executable):
  Cannot find source file:

    C:/Users/Damian/Documents/ImNodes/build/imgui-1.85/examples/libs/gl3w/GL/gl3w.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc


CMake Error at build/imgui-1.85/CMakeLists.txt:430 (add_executable):
  Cannot find source file:

    C:/Users/Damian/Documents/ImNodes/build/imgui-1.85/examples/libs/gl3w/GL/gl3w.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
  .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
Call Stack (most recent call first):
  build/imgui-1.85/CMakeLists.txt:507 (IMGUI_EXAMPLE)


-- Generating done (0.1s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

Change `assert` macro to `IM_ASSERT`

I want to use this module in a project of mine, but I defined my own IM_ASSERT. ImNodes seems to just use assert from <assert.h>, but I think it would make more sense if it would also use IM_ASSERT, like the rest of ImGui. The fix should be easy, I was able to literally find and replace assert by IM_ASSERT in ImNodes.cpp.

How to query for removed connection?

I've tried GetPendingConnection but it results even if there is no connection.
I need to query when a connection that is already connected to a node is removed or delete.
Perhaps a function to get state if the connection is deleted using double left click can be added to the API?
Looking around i've noticed that that functionality is not exposed (in the sample.cpp)

Separator/CollapsingHeader exceeds node's width

		if (ImNodes::Ez::BeginNode(node, node->m_var_name, &node->m_pos, &node->m_selected))
		{
                        ImGui::Separator(); //here
                        //other drawings
		}

results to
2021-03-14_12-15

More testing shows that anywhere the ImGui::Separator() is called as long as inside the ImNodes::Ez::BeginNode and ImNodes::Ez::EndNode it results to the same problem

Unused variables in the code

Hi,
While trying to compile ImNodes as part of my application and I noticed that there are two unused variables:

../external/ImNodes/ImNodes.cpp: In function ‘void ImNodes::EndCanvas()’:
../external/ImNodes/ImNodes.cpp:269:23: error: unused variable ‘style’ [-Werror=unused-variable]
const ImGuiStyle& style = ImGui::GetStyle();
^
../external/ImNodes/ImNodes.cpp: In function ‘void ImNodes::EndSlot()’:
../external/ImNodes/ImNodes.cpp:689:23: error: unused variable ‘style’ [-Werror=unused-variable]
const ImGuiStyle& style = ImGui::GetStyle();

Thanks,
Sagi

Inquiry

Hi, im looking for node graph libraries that i can use for a school project. Ive been keeping an eye on this library for a while now and i have some questions which I would be really glad if someone can answer.

I think this one is easier to use than the other imnodes library.

  • Is the title text of the node editable? (Clicking in the title bar of the node to go into text input mode or something)
  • Can nodes have different components? For example, a node with only integers input can be connected/linked into another node with a string input.
  • How will these nodes of different structures be put in a single container? Im thinking of vector of node struct, but the node can have different struct definition (this is more like cpp general question)

Thank you.

Table not rendering correctly

The code

if (ImNodes::Ez::BeginNode(node, node->m_var_name, &node->m_pos, &node->m_selected))
{
  if (ImGui::BeginTable("test", 2))
  {
    ImGui::TableNextRow();
    ImGui::TableNextColumn();
    ImGui::Text("Name:");
    ImGui::Text("Value:");

    ImGui::TableNextColumn();
    ImGui::Text("%s", node->m_var_name);
    ImGui::Text("%s", node->m_var_value);

    ImGui::EndTable();
  }

  ImNodes::Ez::InputSlots(node->m_in_slots.data(), node->m_in_slots.size());  
  ImNodes::Ez::OutputSlots(node->m_out_slots.data(), node->m_out_slots.size());
  //more
  ImNodes::Ez::EndNode();
}

shows the screenshot below
2021-03-14_10-37

The use case is to cleanly show the names of the fields and the values of the fields in a tabular form.

EndCanvas unselect one node

HI!
I noticed a bug in ImNodes::EndCanvas() function.
It's reset the single_selected_node to null if ctrl and shift keys not clicked,
So when I click a node with mouse only, the function ImNodes::Ez::BeginNodeset select to true,
but in next call to this function, select becomes false.

I don't sure why you made ImNodes::EndCanvas() function act and if it's really a bug,
but I think that after clicking a node it should be selected without using shift or ctrl keys.

Sagi

Is general slot type provided?

In the example, I can only connect an input slot with an output slot. However, I want some general slots beyond input and output which can be connected each other even though the slots are in the same node. Could you please give me some suggestions? Thank you a lot.

Support for highlight around Node

Hi, I got really far now in my project using this lib. Thanks!

Now I'm wondering if ImNodes will have the "highlight" around the border of the node? kind of like a glow. My use case is that whenever I am to move the canvas' camera offset to a certain node (using find), i want to give a feedback to the user to signify that this is the node that's found.

Nodes with only output slots? Assertion error

Just comment a line which renders the input slots in sample.cpp:

ImNodes::Ez::InputSlots(node->input_slots.data(), node->input_slots.size());
ImNodes: /home/arnaud/src/build-ImNodes-Desktop-Default/imgui-1.70/imgui.cpp:6779: void ImGui::EndGroup(): Assertion `!window->DC.GroupStack.empty()' failed.

Position of loaded nodes from file is not consistent/correct

I'm saving my nodes to an .ini file. Here's a screenshot before saving:

2021-03-25_22-10

And here's the content of the .ini saved file:

[node_0]
name = a
kind = VARIABLE
x = 1291.000000
y = 205.000000
value_slot = INTEGER
value = 3
input_1 = INTEGER
output_1 = INTEGER

[node_1]
name = b
kind = VARIABLE
x = 1740.000000
y = 203.000000
value_slot = INTEGER
value = 8
input_1 = INTEGER
output_1 = INTEGER

But everytime I load the node from the ini file. I get inconsistent results. Here are sample of loading them:
2021-03-25_22-11

2021-03-25_22-11_1

For more information, here's a snippet how I save/load the node to the file:

//saving
for (Node* node : Nodes::v_nodes) //std::vector<Node*>
{
                //struct Node { ImVec2 m_pos }; //just like in the sample.cpp
		std::string str_x = std::to_string(node->m_pos.x);
		std::string str_y = std::to_string(node->m_pos.y);
		ini.SetValue(section, "x", str_x.c_str());
		ini.SetValue(section, "y", str_y.c_str());
}
//loading
const float x = std::stof(ini.GetValue(section, "x"));
const float y = std::stof(ini.GetValue(section, "y"));

Node* node = new Node();
node->m_pos = ImVec2(x, y);
Nodes::v_nodes.push_back(node);
//ImNodes::AutoPositionNode(node); //cant do this as there is no context yet
Nodes::first_load = true;

//in render
ImNodes::BeginCanvas(canvas);
if (Nodes::first_load)
{
		for (Node* node : Nodes::v_nodes)
			ImNodes::AutoPositionNode(node);

		Nodes::first_load = false;
}
ImNodes::EndCanvas();

context menu on node content

Imagine I want to add a context menu on node content. In the sample.cpp:

                // Custom node content may go here
                ImGui::Text("Content of %s", node->Title);
                const char* names[5] = { "Label1", "Label2", "Label3", "Label4", "Label5" };
                for (int n = 0; n < 5; n++)
                {
                    ImGui::Selectable(names[n]);
                    if (ImGui::BeginPopupContextItem()) // <-- use last item id as popup id
                    {
                        ImGui::Text("This a popup for \"%s\"!", names[n]);
                        if (ImGui::Button("Close"))
                            ImGui::CloseCurrentPopup();
                        ImGui::EndPopup();
                    }
                    if (ImGui::IsItemHovered())
                        ImGui::SetTooltip("Right-click to open popup");
                }

This is just pasted from imgui_demo.cpp

This doesn't work. Only the context menu for adding nodes is opened.

Horizontal scrollbar doesn't function

Changing the Window flags to:

    if (ImGui::Begin("ImNodes", nullptr, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar))

The horizontal scrollbar doesn't appear to scroll.

Add picture inside of the node

Hi, first of all I want to thank the developers for efforts and spent time for lib dev!

Is it possible to add picture to the node background and custom setup the pins distance and positions inside of the node?

If not, is there any plans in future to add this feature?

Thank you!

ImBezierClosestPointCasteljau deprecation

ImBezierClosestPointCasteljau was dropped in 1.80 so that ImNodes does not compile.
Perhaps IMGUI_VERSION_NUM < 18000 could be used for using this or ImBezierCubicClosestPointCasteljau

I tried without IMGUI_DISABLE_OBSOLETE_FUNCTIONS but it did not work as ImBezierClosestPointCasteljau was not kepped in imgui.h ocornut/imgui#3746

cmake version required

I don't think you're using any features of cmake 3.14, are you? So it would help if you would lower it to prevent unnecessary errors.

I just lowered it to 3.12 (on a linux machine) and it runs fine.

Cmake report error on Windows platform

CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.11/Modules/FindPkgConfig.cmake:39 (find_package_handle_standard_args)
  CMakeLists.txt:28 (find_package)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.