Nelarius / imnodes

A small, dependency-free node editor for dear imgui
MIT License
2.07k stars 254 forks source link

add icon for node #21

Closed ketoo closed 4 years ago

ketoo commented 4 years ago

Demo listed below:

image

Nelarius commented 4 years ago

Thanks for the contribution again!

I have an alternate proposal for adding icons to the title bar: check out the commit in my title_bar_rework branch. It makes the title bar immediate-mode, just like the node attributes.

I think it's a better approach since it actually reduces the node state, and as a result there's fewer things that the imnodes API needs to "know" about. As a bonus, you can now leave the title bar out by just not calling Begin/EndNodeTitleBar!

Here's a quick and dirty example I did using ImGui's font atlas texture 😄 :

Screenshot 2020-02-19 at 9 25 51

And the code to generate the node in the screencap:

imnodes::BeginNode(1);

// Here's the new bit 👇
imnodes::BeginNodeTitleBar();
ImGui::Image(
        texture.id,
        ImVec2(40.f, 15.f),
        ImVec2(0.f, 0.f),
        ImVec2(0.2f, 0.5f));
ImGui::SameLine();
ImGui::TextUnformatted("image node");
imnodes::EndNodeTitleBar();

imnodes::BeginInputAttribute(2);
ImGui::Text("input");
imnodes::EndAttribute();

imnodes::BeginOutputAttribute(3);
ImGui::Indent(80.0f);
ImGui::Text("output");
imnodes::EndAttribute();

imnodes::EndNode();

If you have nothing against this approach, I will close this pr and merge my branch 👍

ketoo commented 4 years ago

Great, your way better and close the concept of immediate-mode. Please close this PR and merge your branch into the master branch.