Skip to content

Commit 646df39

Browse files
committed
Examples: added SDL3+Vulkan example - enable multi-viewports. (#8084, #8085)
1 parent 942b64a commit 646df39

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

examples/example_sdl3_vulkan/main.cpp

+29-9
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,23 @@ int main(int, char**)
433433
ImGuiIO& io = ImGui::GetIO(); (void)io;
434434
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
435435
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
436+
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
437+
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
438+
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
439+
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
436440

437441
// Setup Dear ImGui style
438442
ImGui::StyleColorsDark();
439443
//ImGui::StyleColorsLight();
440444

445+
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
446+
ImGuiStyle& style = ImGui::GetStyle();
447+
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
448+
{
449+
style.WindowRounding = 0.0f;
450+
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
451+
}
452+
441453
// Setup Platform/Renderer backends
442454
ImGui_ImplSDL3_InitForVulkan(window);
443455
ImGui_ImplVulkan_InitInfo init_info = {};
@@ -557,17 +569,25 @@ int main(int, char**)
557569

558570
// Rendering
559571
ImGui::Render();
560-
ImDrawData* draw_data = ImGui::GetDrawData();
561-
const bool is_minimized = (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f);
562-
if (!is_minimized)
572+
ImDrawData* main_draw_data = ImGui::GetDrawData();
573+
const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f);
574+
wd->ClearValue.color.float32[0] = clear_color.x * clear_color.w;
575+
wd->ClearValue.color.float32[1] = clear_color.y * clear_color.w;
576+
wd->ClearValue.color.float32[2] = clear_color.z * clear_color.w;
577+
wd->ClearValue.color.float32[3] = clear_color.w;
578+
if (!main_is_minimized)
579+
FrameRender(wd, main_draw_data);
580+
581+
// Update and Render additional Platform Windows
582+
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
563583
{
564-
wd->ClearValue.color.float32[0] = clear_color.x * clear_color.w;
565-
wd->ClearValue.color.float32[1] = clear_color.y * clear_color.w;
566-
wd->ClearValue.color.float32[2] = clear_color.z * clear_color.w;
567-
wd->ClearValue.color.float32[3] = clear_color.w;
568-
FrameRender(wd, draw_data);
569-
FramePresent(wd);
584+
ImGui::UpdatePlatformWindows();
585+
ImGui::RenderPlatformWindowsDefault();
570586
}
587+
588+
// Present Main Platform Window
589+
if (!main_is_minimized)
590+
FramePresent(wd);
571591
}
572592

573593
// Cleanup

0 commit comments

Comments
 (0)