Hello Omar,
As we discussed on Wednesday 2026-10-14, a library that changes the coordinate space may need to be informed when a window is begun (at every Begin() / End()).
Feel free to accept this PR, refuse or delay it ;-)
Concrete example in imgui-node-editor
Its zoomable canvas needs to know when a window is begun from inside it, in order to use the original coordinate system.
Otherwise, popups, combos, color pickers and tooltips opened by a widget's own code are placed and hit-tested in canvas units (thedmd/imgui-node-editor#242, thedmd/imgui-node-editor#322).
imgui-node-editor provides Suspend() / Resume() but this is not enough, since the widget opens them itself.
This PR adds:
ImGuiContext::BeginWindowCallback: called byBegin(), after its asserts.ImGuiContext::EndWindowCallback: called at the end ofEnd().- one null test each, and one user data shared by both.
- a single slot: a library saves the previous values when it sets them, and restores them when it is done (e.g. a node editor inside a popup of another one).
IMGUI_HAS_BEGIN_END_WINDOW_CALLBACKSlets a library test for it (although a version check would do too).
What this fixes in the node editor (in my fork)
- With the callbacks, my fork of the node editor opens popups, combos, color pickers and tooltips begun from within the canvas at the right place, and they are usable (A/B image below).
- The node editor's canvas using the callbacks, on top of thedmd's master: the change, and its tests in @thedmd's test harness (popups, a combo, a color picker and a tooltip inside a node, at zoom 2).
(I will send a pull request to @thedmd shortly after.)
What this does not fix in the node editor
Child windows would need more work: they do trigger the callbacks (BeginChild() calls Begin()).
However, the canvas cannot fix them this way:
- a child belongs to a node's content, and must zoom and pan with it;
- but Dear ImGui draws it in its own draw list, which the canvas does not transform, and clips it in screen space.
They would probably need a transform inside Dear ImGui.
How this is handled in my fork of the node editor
My fork's canvas uses the callback to detect them, and asserts with an explanation instead of a broken display.
The fork: pthom/imgui-node-editor, branch imgui_bundle. Its changes are explained in fork_imgui_bundle.md; the callbacks, and how the canvas uses them, in its chapter 3, "Patching Dear ImGui".
Tested
With a headless check (balanced calls, the parent window current when a child begins), and with the node editor's tests in my fork, which uses the callbacks: the tests, on top of thedmd's master.
Credits and info
- The idea to respond to
ImGui::Begin/Endcame from @lukaasm (see comment on thedmd/imgui-node-editor#242). - @thedmd seemed to approve of the idea (see comment on thedmd/imgui-node-editor#242).
What could be done for child windows using transforms?
Below is a quick exploration of what could be done for child windows. Nothing is done at the moment for them in this commit.
Dear ImGui's transforms act on the output (the drawing part):
ShadeVertsTransformPos(), on a range of vertices;- the draw data's
DisplayPos/FramebufferScale; - since 1.93,
_FringeScale, for zoomed vertex content.
For a child window inside a canvas:
- Updating the drawing coordinates seems within reach: with
EndWindowCallback, the canvas could transform the child's draw list, as it does its own. - However, updating the input coordinates seems out of reach: the hovered window is found in
NewFrame(), with the screen mouse, against rectangles the canvas would lay out in its own units.
A side note: the API for BeginCreate/EndCreate, in imgui-node-editor
Quick note for @thedmd: this API has a different policy in the develop branch and in the master branch.
masterbranch:EndCreate()should always be called, as withImGui::Begin().developbranch:EndCreate()should be called only whenBeginCreate()returns true
So in order to accept both policies I added a commit to my fork: Editor: Make EndCreate() optional after a BeginCreate() that returned false, with its tests. Tell me if you want a pull request for that.
Activity
53c30832Instead of direct callbacks I though about proposing new hooks. Did you explored this way?
Hi @thedmd, thanks a lot for your answer!
Yes, actually the hooks were my first proposal. I presented a version with hooks to Omar. However, he told me that looping over the hooks array at each Begin() is too costly, and to use two dedicated function pointers instead.
Unrelated, but I take the opportunity to thank you very much for integrating my previous pull requests!
Also, I think I should tell you about nice demos of the node editor which I recently added to Dear ImGui Bundle. They work either in C++ (emscripten), or in Python (online demo, using pyodide):
(While you are viewing this in Python or in C++ you may click the green demos button at the top right to look for more demos if you are interested).
Fine by me. Thanks. If that manage to get included in ImGui I will definitely take advantage of this feature.
Related PR for imgui-node-editor: https://github.com/thedmd/imgui-node-editor/pull/343