diff --git a/Walnut/src/Walnut/Application.cpp b/Walnut/src/Walnut/Application.cpp index cee68754..4eb2f568 100644 --- a/Walnut/src/Walnut/Application.cpp +++ b/Walnut/src/Walnut/Application.cpp @@ -379,6 +379,7 @@ static void glfw_error_callback(int error, const char* description) fprintf(stderr, "Glfw Error %d: %s\n", error, description); } + namespace Walnut { Application::Application(const ApplicationSpecification& specification) @@ -403,6 +404,8 @@ namespace Walnut { } glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + if (!m_Specification.ParentWindow) + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); m_WindowHandle = glfwCreateWindow(m_Specification.Width, m_Specification.Height, m_Specification.Name.c_str(), NULL, NULL); // Setup Vulkan @@ -437,7 +440,8 @@ namespace Walnut { //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows - //io.ConfigViewportsNoAutoMerge = true; + if(!m_Specification.ParentWindow) + io.ConfigViewportsNoAutoMerge = true; //io.ConfigViewportsNoTaskBarIcon = true; // Setup Dear ImGui style @@ -473,8 +477,12 @@ namespace Walnut { // Load default font ImFontConfig fontConfig; fontConfig.FontDataOwnedByAtlas = false; - ImFont* robotoFont = io.Fonts->AddFontFromMemoryTTF((void*)g_RobotoRegular, sizeof(g_RobotoRegular), 20.0f, &fontConfig); - io.FontDefault = robotoFont; + ImFont* font; + if (!m_Specification.DefaultFont) { + font = io.Fonts->AddFontFromMemoryTTF((void*)g_RobotoRegular, sizeof(g_RobotoRegular), 20.0f, &fontConfig); + } else + font = io.Fonts->AddFontDefault(&fontConfig); + io.FontDefault = font; // Upload Fonts { @@ -504,6 +512,7 @@ namespace Walnut { err = vkDeviceWaitIdle(g_Device); check_vk_result(err); ImGui_ImplVulkan_DestroyFontUploadObjects(); + } } @@ -582,60 +591,66 @@ namespace Walnut { ImGui::NewFrame(); { - static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; - - // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, - // because it would be confusing to have two docking targets within each others. - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking; - if (m_MenubarCallback) - window_flags |= ImGuiWindowFlags_MenuBar; - - const ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->WorkPos); - ImGui::SetNextWindowSize(viewport->WorkSize); - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; - window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; - - // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background - // and handle the pass-thru hole, so we ask Begin() to not render a background. - if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) - window_flags |= ImGuiWindowFlags_NoBackground; - - // Important: note that we proceed even if Begin() returns false (aka window is collapsed). - // This is because we want to keep our DockSpace() active. If a DockSpace() is inactive, - // all active windows docked into it will lose their parent and become undocked. - // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise - // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible. - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - ImGui::Begin("DockSpace Demo", nullptr, window_flags); - ImGui::PopStyleVar(); - - ImGui::PopStyleVar(2); - - // Submit the DockSpace - ImGuiIO& io = ImGui::GetIO(); - if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) - { - ImGuiID dockspace_id = ImGui::GetID("VulkanAppDockspace"); - ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); - } - - if (m_MenubarCallback) - { - if (ImGui::BeginMenuBar()) + if (!m_Specification.NoDockSpace && m_Specification.ParentWindow) { + ImGui::End(); + static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None; + + // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, + // because it would be confusing to have two docking targets within each others. + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDocking; + if (m_MenubarCallback) + window_flags |= ImGuiWindowFlags_MenuBar; + + const ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(viewport->WorkPos); + ImGui::SetNextWindowSize(viewport->WorkSize); + ImGui::SetNextWindowViewport(viewport->ID); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove; + window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus; + + // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background + // and handle the pass-thru hole, so we ask Begin() to not render a background. + if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) + window_flags |= ImGuiWindowFlags_NoBackground; + + // Important: note that we proceed even if Begin() returns false (aka window is collapsed). + // This is because we want to keep our DockSpace() active. If a DockSpace() is inactive, + // all active windows docked into it will lose their parent and become undocked. + // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise + // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible. + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + ImGui::Begin("DockSpace Demo", nullptr, window_flags); + ImGui::PopStyleVar(); + + ImGui::PopStyleVar(2); + + // Submit the DockSpace + ImGuiIO& io = ImGui::GetIO(); + if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) + { + ImGuiID dockspace_id = ImGui::GetID("VulkanAppDockspace"); + ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); + } + + if (m_MenubarCallback) { - m_MenubarCallback(); - ImGui::EndMenuBar(); + if (ImGui::BeginMenuBar()) + { + m_MenubarCallback(); + ImGui::EndMenuBar(); + } } } for (auto& layer : m_LayerStack) layer->OnUIRender(); - ImGui::End(); + if (!m_Specification.NoDockSpace && m_Specification.ParentWindow) { + + ImGui::End(); + } } // Rendering diff --git a/Walnut/src/Walnut/Application.h b/Walnut/src/Walnut/Application.h index 1e966a32..bb1ba5c9 100644 --- a/Walnut/src/Walnut/Application.h +++ b/Walnut/src/Walnut/Application.h @@ -21,6 +21,9 @@ namespace Walnut { std::string Name = "Walnut App"; uint32_t Width = 1600; uint32_t Height = 900; + bool ParentWindow = true; + bool DefaultFont = true; + bool NoDockSpace = false; }; class Application