Skip to content

Commit

Permalink
add support for imgui without docking
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Dec 7, 2023
1 parent 0673349 commit 9e3a740
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
10 changes: 8 additions & 2 deletions source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void Player::render() {
BackendNewFrame();
ImGui::NewFrame();

#ifdef _WIN32
#if defined(_WIN32) && defined(IMGUI_HAS_VIEWPORT)
if (config->Data.Mpv.UseWid) {
ImGuiViewport *vp = ImGui::GetMainViewport();
vp->Flags &= ~ImGuiViewportFlags_CanHostOtherWindows; // HACK: disable main viewport merge
Expand All @@ -157,10 +157,12 @@ void Player::render() {
SwapBuffers();
mpv->reportSwap();

#ifdef IMGUI_HAS_VIEWPORT
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
#endif
}
}

Expand Down Expand Up @@ -195,8 +197,12 @@ void Player::initGui() {
io.IniFilename = nullptr;
io.ConfigWindowsMoveFromTitleBarOnly = true;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
#ifdef IMGUI_HAS_DOCK
if (config->Data.Interface.Docking) io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
#endif
#ifdef IMGUI_HAS_VIEWPORT
if (config->Data.Interface.Viewports) io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
#endif

loadFonts();

Expand Down Expand Up @@ -277,7 +283,7 @@ void Player::loadFonts() {
ImGui::SetTheme(interface.Theme.c_str(), &style, interface.Rounding, interface.Shadow);

ImGuiIO &io = ImGui::GetIO();
#ifdef _WIN32
#if defined(_WIN32) && defined(IMGUI_HAS_VIEWPORT)
if (config->Data.Mpv.UseWid) io.ConfigViewportsNoAutoMerge = true;
#endif

Expand Down
10 changes: 10 additions & 0 deletions source/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ void ImGui::SetTheme(const char* theme, ImGuiStyle* dst, bool rounding, bool sha
style->PopupRounding = rounding ? 4.0f : 0.0f;
style->ChildRounding = rounding ? 4.0f : 0.0f;

#ifdef IMGUI_HAS_SHADOWS
style->WindowShadowSize = shadow ? 50.0f : 0.0f;
style->Colors[ImGuiCol_WindowShadow] = ImVec4(0, 0, 0, 1.0f);
#endif
}

// https://github.com/adobe/imgui/blob/master/docs/Spectrum.md
Expand Down Expand Up @@ -79,8 +81,10 @@ void ImGui::StyleColorsSpectrum(ImGuiStyle* dst) {
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.41f, 0.68f, 1.00f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.07f, 0.10f, 0.15f, 0.97f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.26f, 0.42f, 1.00f);
#ifdef IMGUI_HAS_DOCK
colors[ImGuiCol_DockingPreview] = ImVec4(0.26f, 0.59f, 0.98f, 0.70f);
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
#endif
colors[ImGuiCol_PlotLines] = ImVec4(0.15f, 0.50f, 0.92f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.29f, 0.61f, 0.96f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.15f, 0.50f, 0.92f, 1.00f);
Expand All @@ -96,7 +100,9 @@ void ImGui::StyleColorsSpectrum(ImGuiStyle* dst) {
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
#ifdef IMGUI_HAS_SHADOWS
colors[ImGuiCol_WindowShadow] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
#endif
}

// https://github.com/ocornut/imgui/issues/707#issuecomment-1372640066
Expand Down Expand Up @@ -141,7 +147,9 @@ void ImGui::StyleColorsDracula(ImGuiStyle* dst) {
colors[ImGuiCol_ResizeGrip] = ImVec4{0.44f, 0.37f, 0.61f, 0.29f};
colors[ImGuiCol_ResizeGripHovered] = ImVec4{0.74f, 0.58f, 0.98f, 0.29f};
colors[ImGuiCol_ResizeGripActive] = ImVec4{0.84f, 0.58f, 1.0f, 0.29f};
#ifdef IMGUI_HAS_DOCK
colors[ImGuiCol_DockingPreview] = ImVec4{0.44f, 0.37f, 0.61f, 1.0f};
#endif
}

// https://github.com/ocornut/imgui/issues/707#issuecomment-917151020
Expand Down Expand Up @@ -187,8 +195,10 @@ void ImGui::StyleColorsDeepDark(ImGuiStyle* dst) {
colors[ImGuiCol_TabActive] = ImVec4(0.20f, 0.20f, 0.20f, 0.36f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.00f, 0.00f, 0.00f, 0.52f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
#ifdef IMGUI_HAS_DOCK
colors[ImGuiCol_DockingPreview] = ImVec4(0.33f, 0.67f, 0.86f, 1.00f);
colors[ImGuiCol_DockingEmptyBg] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
#endif
colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
Expand Down
3 changes: 0 additions & 3 deletions source/views/command_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ void CommandPalette::draw() {
ImGui::SetNextWindowSize(popupSize, ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(pos.x + size.x * 0.5f, pos.y + size.y * 0.1), ImGuiCond_Always, ImVec2(0.5f, 0.0f));
if (ImGui::BeginPopup("##command_palette")) {
if (ImGui::GetIO().AppFocusLost || ImGui::GetWindowViewport()->Flags & ImGuiViewportFlags_IsMinimized)
ImGui::CloseCurrentPopup();

if (justOpened) {
focusInput = true;
match("");
Expand Down
12 changes: 9 additions & 3 deletions source/views/context_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ void ContextMenu::draw() {
m_open = false;
}

if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGuiIO &io = ImGui::GetIO();
#if defined(_WIN32) && defined(IMGUI_HAS_VIEWPORT)
if (config->Data.Mpv.UseWid && io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGuiWindowClass windowClass;
windowClass.ViewportFlagsOverrideSet = ImGuiViewportFlags_TopMost;
ImGui::SetNextWindowClass(&windowClass);
}
#endif

if (ImGui::BeginPopup("##context_menu", ImGuiWindowFlags_NoMove)) {
if (ImGui::GetIO().AppFocusLost || ImGui::GetWindowViewport()->Flags & ImGuiViewportFlags_IsMinimized)
ImGui::CloseCurrentPopup();
if (io.AppFocusLost) ImGui::CloseCurrentPopup();
#ifdef IMGUI_HAS_VIEWPORT
if (ImGui::GetWindowViewport()->Flags & ImGuiViewportFlags_IsMinimized) ImGui::CloseCurrentPopup();
#endif

draw(build());

Expand Down
7 changes: 4 additions & 3 deletions source/views/quickview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ void Quickview::drawPopup() {

ImGui::SetNextWindowSize(ImVec2(width, wSize.y), ImGuiCond_Always);
ImGui::SetNextWindowPos(ImVec2(wPos.x + wSize.x - width, wPos.y), ImGuiCond_Always);
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {

#if defined(_WIN32) && defined(IMGUI_HAS_VIEWPORT)
if (config->Data.Mpv.UseWid && ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGuiWindowClass windowClass;
windowClass.ViewportFlagsOverrideSet = ImGuiViewportFlags_TopMost;
ImGui::SetNextWindowClass(&windowClass);
}
#endif

if (ImGui::BeginPopup("##quickview")) {
if (ImGui::GetIO().AppFocusLost || ImGui::GetWindowViewport()->Flags & ImGuiViewportFlags_IsMinimized)
ImGui::CloseCurrentPopup();
drawTabBar();
ImGui::EndPopup();
}
Expand Down
6 changes: 6 additions & 0 deletions source/views/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,22 @@ void Settings::drawInterfaceTab() {
if (ImGui::BeginTabItem("views.settings.interface"_i18n)) {
ImGui::TextUnformatted("views.settings.interface.gui"_i18n);
ImGui::Indent();
#ifdef IMGUI_HAS_DOCK
ImGui::Checkbox("views.settings.interface.docking"_i18n, &data.Interface.Docking);
ImGui::SameLine();
ImGui::HelpMarker("views.settings.interface.docking.help"_i18n);
#endif
#ifdef IMGUI_HAS_VIEWPORT
ImGui::SameLine(scaled(20));
ImGui::Checkbox("views.settings.interface.viewports"_i18n, &data.Interface.Viewports);
ImGui::SameLine();
ImGui::HelpMarker("views.settings.interface.viewports.help"_i18n);
#endif
ImGui::Checkbox("views.settings.interface.rounding"_i18n, &data.Interface.Rounding);
#ifdef IMGUI_HAS_SHADOWS
ImGui::SameLine(scaled(20));
ImGui::Checkbox("views.settings.interface.shadow"_i18n, &data.Interface.Shadow);
#endif
ImGui::SliderInt("views.settings.interface.fps"_i18n, &data.Interface.Fps, 15, 200);
ImGui::SameLine();
ImGui::HelpMarker("views.settings.interface.fps.help"_i18n);
Expand Down

0 comments on commit 9e3a740

Please sign in to comment.