Using a CollapsingHeader/treenode inside a node, it's ui goes out of bounds of the node;
bigbigzxl opened this issue · 1 comments
bigbigzxl commented
- 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();
hiroMTB commented
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 ...
- first render node with 100px (or whatever) default width as we don't know the actual width
- modified version of EndNode() returns node width
- 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