@@ -145,6 +145,60 @@ bool ImGuiEx::Canvas::Begin(ImGuiID id, const ImVec2& size)
145
145
146
146
m_InBeginEnd = true ;
147
147
148
+ // [ADAPT_IMGUI_BUNDLE]: added ImGuiContextHookType_BeginWindow, ImGuiContextHookType_EndWindow, cf https://github.com/thedmd/imgui-node-editor/issues/242#issuecomment-1681806764
149
+ {
150
+ auto beginWindowHook = ImGuiContextHook{};
151
+ beginWindowHook.UserData = this ;
152
+ beginWindowHook.Type = ImGuiContextHookType_BeginWindow;
153
+ beginWindowHook.Callback = []( ImGuiContext * context, ImGuiContextHook * hook )
154
+ {
155
+ // ImGui::SetNextWindowViewport( ImGui::GetCurrentWindow()->Viewport->ID );
156
+
157
+ auto canvas = reinterpret_cast < Canvas * >( hook->UserData );
158
+ if ( canvas->m_SuspendCounter == 0 )
159
+ {
160
+ if ( ( context->NextWindowData .Flags & ImGuiNextWindowDataFlags_HasPos ) != 0 )
161
+ {
162
+ auto pos = canvas->FromLocal ( context->NextWindowData .PosVal );
163
+ ImGui::SetNextWindowPos ( pos, context->NextWindowData .PosCond , context->NextWindowData .PosPivotVal );
164
+ }
165
+
166
+ if ( context->BeginPopupStack .size () )
167
+ {
168
+ auto & popup = context->BeginPopupStack .back ();
169
+ popup.OpenPopupPos = canvas->FromLocal ( popup.OpenPopupPos );
170
+ popup.OpenMousePos = canvas->FromLocal ( popup.OpenMousePos );
171
+ }
172
+
173
+ if ( context->OpenPopupStack .size () )
174
+ {
175
+ auto & popup = context->OpenPopupStack .back ();
176
+ popup.OpenPopupPos = canvas->FromLocal ( popup.OpenPopupPos );
177
+ popup.OpenMousePos = canvas->FromLocal ( popup.OpenMousePos );
178
+ }
179
+
180
+ }
181
+ canvas->m_BeginWindowCursorBackup = ImGui::GetCursorScreenPos ();
182
+ canvas->Suspend ();
183
+ };
184
+
185
+ m_beginWindowHook = ImGui::AddContextHook ( ImGui::GetCurrentContext (), &beginWindowHook );
186
+
187
+ auto endWindowHook = ImGuiContextHook{};
188
+ endWindowHook.UserData = this ;
189
+ endWindowHook.Type = ImGuiContextHookType_EndWindow;
190
+ endWindowHook.Callback = []( ImGuiContext * ctx, ImGuiContextHook * hook )
191
+ {
192
+ auto canvas = reinterpret_cast < Canvas * >( hook->UserData );
193
+ canvas->Resume ();
194
+ ImGui::SetCursorScreenPos ( canvas->m_BeginWindowCursorBackup );
195
+ ImGui::GetCurrentWindow ()->DC .IsSetPos = false ;
196
+ };
197
+
198
+ m_endWindowHook = ImGui::AddContextHook ( ImGui::GetCurrentContext (), &endWindowHook );
199
+ }
200
+ // [/ADAPT_IMGUI_BUNDLE]
201
+
148
202
return true ;
149
203
}
150
204
@@ -180,6 +234,14 @@ void ImGuiEx::Canvas::End()
180
234
// m_DrawList->AddRect(m_WidgetPosition - ImVec2(1.0f, 1.0f), m_WidgetPosition + m_WidgetSize + ImVec2(1.0f, 1.0f), IM_COL32(196, 0, 0, 255));
181
235
182
236
m_InBeginEnd = false ;
237
+
238
+ // [ADAPT_IMGUI_BUNDLE]: added ImGuiContextHookType_BeginWindow, ImGuiContextHookType_EndWindow, cf https://github.com/thedmd/imgui-node-editor/issues/242#issuecomment-1681806764
239
+ {
240
+ ImGui::RemoveContextHook ( ImGui::GetCurrentContext (), m_beginWindowHook );
241
+ ImGui::RemoveContextHook ( ImGui::GetCurrentContext (), m_endWindowHook );
242
+ }
243
+ // [/ADAPT_IMGUI_BUNDLE]
244
+
183
245
}
184
246
185
247
void ImGuiEx::Canvas::SetView (const ImVec2& origin, float scale)
0 commit comments