Example code for reproducing thedmd/imgui-node-editor#205
See short video explanation (4 minutes)
./fetch_external.sh
mkdir build
cd build
cmake ..
make -j
It was not possible to use the ImGui version inside node editor, since it is outdated, hence this separate repository.
The code is contained in two short files:
-
main_imgui_sdl3_opengl3.cpp: This file is an almost direct copy of imgui/examples/example_glfw_opengl3/main.cpp, the only difference being that it calls functions from node_clipping_issue.cpp (for the Gui and context setup)
-
node_clipping_issue.cpp Demo code.
This demo is able to trigger subtle issues that arise when using docked windows, and/or windows whose size is unknown at the first frame (so that the canvas does not know its size)
4 issues can be triggered: they are detailed below. I'm sorry if all of them are grouped in a single project, but it seemed to be the most efficient way to communicate about them. Most of the fixes are simple, but the fix for issue 205 is only a workaround.
Issue 205: thedmd/imgui-node-editor#205
Clipping is not related to the window with the latest imgui"
Adding a simple pixel at m_WidgetRect.Max is enough to bypass the issue. This is not a real fix, since it merely adds a fake pixel at (xmax, ymax), so that the app knows where the clipping should end. A better solution would be required.
Workaround: at imgui_canvas.cpp:122 (see commit)
bool ImGuiEx::Canvas::Begin(ImGuiID id, const ImVec2& size)
{
...
...
// Adding a simple pixel at m_WidgetRect.Max is enough to temporarily solve the issue
// (the color is selected to be as transparent as possible)
m_DrawList->AddLine(m_WidgetRect.Max, m_WidgetRect.Max, IM_COL32(0, 0, 0, 1)); // <= **** Added this workaround ****
PR "186" : thedmd/imgui-node-editor#186
if ImGuiEx::Canvas::Begin returns false (which can happen if the window is too small and the canvas is Clipped), then the subsequent call to ImGuiEx::Canvas::End() will trigger an IM_ASSERT
This bug is quite complex to trigger:
- the window size must be still unknown at first display
- you may need to remove imgui.ini and NodeEditor.json to trigger it so that the window size is actually unknown
- a widget must be displayed before the node editor (see ImGui::Text("Hello world") below)
- Fix: at imgui_node_editor.cpp:1126 (see commit)*
void ed::EditorContext::Begin(const char* id, const ImVec2& size)
{
...
if (!m_IsInitialized)
{
// Cycle canvas so it has a change to setup its size before settings are loaded
if (m_Canvas.Begin(id, canvasSize)) // <== **** Added this if ****
m_Canvas.End();
LoadSettings();
m_IsInitialized = true;
}
ed::CreateItemAction::Begin: if (m_CurrentStage == None) => m_InActive = false Otherwise, we may reach IM_ASSERT(false == m_InActive) upon next call. This happens at first display
Fix: at imgui_node_editor.cpp:4710 (see commit)
bool ed::CreateItemAction::Begin()
{
...
...
if (m_CurrentStage == None)
{
m_InActive = false; // <== **** Added this statement ****
return false;
}
(operator- is now provided by imgui)