From 63817a1cadcfcc9e8a41724f2a97777821c35625 Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Thu, 21 Nov 2024 16:34:28 +0100 Subject: [PATCH] docs(imgui): introduce ImGuiContextHolder in sample --- engine/samples/imgui/main.cpp | 6 ++++++ engine/samples/imgui/page.md | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/samples/imgui/main.cpp b/engine/samples/imgui/main.cpp index f09eebe14d..762d68dfda 100644 --- a/engine/samples/imgui/main.cpp +++ b/engine/samples/imgui/main.cpp @@ -96,6 +96,12 @@ int main(int argc, char** argv) cubos.plugin(imguiPlugin); /// [Adding the plugin] + /// [ImGui initialization] + cubos.startupSystem("set ImGui context").after(imguiInitTag).call([](ImGuiContextHolder& holder) { + ImGui::SetCurrentContext(holder.context); + }); + /// [ImGui initialization] + /// [ImGui Demo] cubos.system("show ImGui demo").tagged(imguiTag).call([]() { ImGui::Begin("Dear ImGui + Cubos"); diff --git a/engine/samples/imgui/page.md b/engine/samples/imgui/page.md index c5ae5a0c15..59a97eaba5 100644 --- a/engine/samples/imgui/page.md +++ b/engine/samples/imgui/page.md @@ -16,7 +16,13 @@ Then, make sure to add the plugin. @snippet imgui/main.cpp Adding the plugin -Once the ImGui plugin is added, you can create systems to display ImGui windows and widgets. Here's a system which opens an ImGui window, and its demo. +When you're using ImGui directly in an application or a library, you must also make sure to initialize the ImGui context on it. +To do so, you can add a startup system just like the one below: + +@snippet imgui/main.cpp ImGui initialization + +You can read more about this in the documentation of @ref cubos::engine::ImGuiContextHolder. +Now, you can create systems to display ImGui windows and widgets. Here's a system which opens an ImGui window, and its demo. @snippet imgui/main.cpp ImGui Demo