Skip to content

Commit

Permalink
docs(imgui): introduce ImGuiContextHolder in sample
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Nov 30, 2024
1 parent fc52a90 commit 63817a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions engine/samples/imgui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 7 additions & 1 deletion engine/samples/imgui/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 63817a1

Please sign in to comment.