Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to hide the parent window #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 65 additions & 50 deletions Walnut/src/Walnut/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -504,6 +512,7 @@ namespace Walnut {
err = vkDeviceWaitIdle(g_Device);
check_vk_result(err);
ImGui_ImplVulkan_DestroyFontUploadObjects();

}
}

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Walnut/src/Walnut/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down