Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a CollapsingHeader/treenode inside a node, it's ui goes out of bounds of the node; #167

Open
bigbigzxl opened this issue Sep 30, 2022 · 1 comment

Comments

@bigbigzxl
Copy link

bigbigzxl commented Sep 30, 2022

  1. Using a CollapsingHeader/treenode inside a node, it's ui goes out of bounds of the node;
ImNodes::BeginNode(node.id);
{
    ImNodes::BeginStaticAttribute(node.ui.add.rhs);
    if (ImGui::CollapsingHeader("Filtering"))
    {
        ImGui::BulletText(
            "Sections below are demonstrating many aspects of the library.");
        ImGui::TextUnformatted("result");
    }
    ImNodes::EndStaticAttribute();
}
ImNodes::EndNode();

image

@bigbigzxl bigbigzxl changed the title [Question] How to adjust the input attribute position to the top ? Using a CollapsingHeader/treenode inside a node, it's ui goes out of bounds of the node; Oct 1, 2022
@hiroMTB
Copy link

hiroMTB commented Oct 1, 2023

This can be solved by a quick dirty hack like below.

imnodes.cpp

int EndNode()
{
   ...

    ImNodeData& node = editor.Nodes.Pool[GImNodes->CurrentNodeIdx];
    node.Rect = GetItemRect();
   
    int width = node.Rect.GetWidth();
    
   ...    
    return width;
}

// your node implementation

#include <imgui_internal.h>


void drawMyNode(){
  // start your node
  ImNodes::BeginNode(id);
     
  ImGuiWindow* window = ImGui::GetCurrentWindow();
  ImRect backup = window->WorkRect;
  
  static nodeWidth = 100;  // default 100px
  
  // Here we overwrite window value
  window->WorkRect.Min.x = window->DC.CursorPos.x;
  window->WorkRect.Max.x = window->WorkRect.Min.x + nodeWidth;
      
  if(ImGui::CollapsingHeader("My Header", ImGuiTreeNodeFlags_DefaultOpen))
  {
       ImGui::Text("ABC");
  }
  window->WorkRect = backup;  // recover correct value
  ImNodes::EndNode();
  
  nodeWidth = w;
}

What we do with above code is ...

  1. first render node with 100px (or whatever) default width as we don't know the actual width
  2. modified version of EndNode() returns node width
  3. Overwrite window.WorkRect and put it back after CollapsingHeader.

Negative points are ...

  • 1 frame delay
  • dirty
  • it could break imgui internal window related code as we overwrite WorkRect in a bad manner
  • without ImGuiTreeNodeFlags_DefaultOpen, it calculate wrong width

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants