Skip to content

Commit

Permalink
Merge pull request #15 from lilggamegenius/docking
Browse files Browse the repository at this point in the history
Add support for ImGui's docking branch, which includes Multi Viewports, if available
  • Loading branch information
kfsone authored Oct 24, 2023
2 parents e377d26 + 0be0fbe commit f59b092
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/imguiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn) noexcept
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
#endif

#ifdef IMGUI_HAS_VIEWPORT
glfwWindowHint(GLFW_VISIBLE, static_cast<int>(!config.hideMainWindow_));
/// TODO: If the main window is hidden, should we bother setting window information if it can't be seen?
#endif

// Create window with graphics context
GLFWwindow* window =
glfwCreateWindow(config.width_, config.height_, config.windowTitle_, nullptr, nullptr);
Expand All @@ -75,7 +80,26 @@ imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn) noexcept
ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
}

ImGui::StyleColorsDark();
#ifdef IMGUI_HAS_DOCK
if(config.enableDocking_){
ImGui::GetIO().ConfigFlags |=
ImGuiConfigFlags_DockingEnable; // Enable Docking
}
#endif

#ifdef IMGUI_HAS_VIEWPORT
if(config.enableViewport_){
ImGui::GetIO().ConfigFlags |=
ImGuiConfigFlags_ViewportsEnable; // Enable Docking
}
ImGui::GetIO().ConfigViewportsNoAutoMerge = !config.enableViewportAutoMerge_;
#endif

if(config.startDark_){
ImGui::StyleColorsDark();
} else {
ImGui::StyleColorsLight();
}

// Setup Platform/Renderer backends
/// TODO: Needs to be based on cmake config.
Expand Down Expand Up @@ -123,6 +147,14 @@ imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn) noexcept
// swap the render/draw buffers so the user can see this frame.
glfwSwapBuffers(window);

#ifdef IMGUI_HAS_VIEWPORT
// Update and Render additional Platform Windows
if((ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != 0){
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
#endif

// change the native (host) window size if requested.
if (newSize.has_value()) {
glfwSetWindowSize(window, newSize.value().first, newSize.value().second);
Expand Down
19 changes: 19 additions & 0 deletions src/imguiwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ struct ImGuiWrapConfig

// startDark_ enables StyleColorsDark after creating the window.
bool startDark_{true};

#ifdef IMGUI_HAS_DOCK
// enableDocking_ enables windows to dock with each other
bool enableDocking_{false};
#endif

#ifdef IMGUI_HAS_VIEWPORT
// enableViewport_ enables windows to be pulled out of the main window and exist independently
bool enableViewport_{false};

// enableViewportAutoMerge_ lets windows merge with the main window if dragged within its bounds.
// Disabling this forces the windows to be independent
bool enableViewportAutoMerge_{true};

// hideMainWindow_ sets the main window to be invisible.
// This is only useful if enableViewportAutoMerge_ is false as otherwise nothing is displayed
/// TODO: Perhaps enforce this in code somewhere?
bool hideMainWindow_{false};
#endif
};

// imgui_main implements a main-loop that constructs a GL window and calls the supplied
Expand Down

0 comments on commit f59b092

Please sign in to comment.