rokups / ImNodes

Node graph implementation for Dear ImGui. Used in https://github.com/rokups/rbfx
MIT License
656 stars 57 forks source link

Separator/CollapsingHeader exceeds node's width #30

Open flamendless opened 3 years ago

flamendless commented 3 years ago
        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

sonoro1234 commented 3 years ago

It seems that the same is happening in Nelarius/imnodes: https://github.com/Nelarius/imnodes/tree/ee6d4071eef5d253e6402e488e93f64208ae195a#known-issues

What happens if everything is inside a Table?

flamendless commented 3 years ago

What happens if everything is inside a Table?

It doesn't get drawn properly.

    if (ImGui::BeginTable("TableNode##NodeVar", 2, ImGuiTableFlags_SizingFixedFit))
    {
                ImGui::Separator(); //this doesnt get drawn
        ImGui::TableNextRow();
        ImGui::TableNextColumn();
               ImGui::Separator(); //this is drawn but it exceeds the node size as well
        ImGui::Text("Name:");
        ImGui::Text("Value:");

        ImGui::TableNextColumn();
        ImGui::Text("%s", m_name);

        if (m_value)
            m_value->draw();
        else
            m_value_orig.draw();

        ImGui::EndTable();
    }
flamendless commented 3 years ago

I've renamed the title of this issue as this misbehavior also happens for collapsing header inside the node.

Im trying to draw all the values connected to a certain node.

2021-03-23_10-18

Also, this misbehavior happens also for TreeNode (when hovered on the tree title)

sphaero commented 2 years ago

I'm also seeing this when using a table inside a Node:

image

Just this code in a node:

static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY;

        if (ImGui::BeginTable("table1", 3, flags))
        {
            for (int row = 0; row < 3; row++)
            {
                ImGui::TableNextRow();
                for (int column = 0; column < 3; column++)
                {
                    ImGui::TableSetColumnIndex(column);
                    ImGui::Text("Hello %d,%d", column, row);
                }
            }
            ImGui::EndTable();
        }
sphaero commented 2 years ago

This needs some inside ImGui perspective. I think it might be caused by the fact that item space is provided by a window and a Node is not a window.

See here for the separator: https://github.com/ocornut/imgui/blob/6fae29679a8f9b163f6ef11bd643c4aa859cc31b/imgui_widgets.cpp#L1393

It jus gets the max width from the underlying window. When we're in a node this should be the max width of the node. Perhaps we need to register nodes as a window?

sphaero commented 2 years ago

A workaround might be to wrap the widgets which exceed the width inside a BeginChild()/EndChild()