From 439de26a26beddbb3028f2fa7029799b4ee8b17d Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Tue, 10 Mar 2026 10:52:45 +0100 Subject: [PATCH 1/2] Fix menu and fps overlay scaling Main menu would retain the width from the biggest scale set on this boot - reset the size to 1x1 and let the imgui resize itself back up. The 2nd issue with the fps overlay was relating to having different scales for the menu and the fps overlay. Different scales require setting the required style for padding etc. Because we only have one global style we need to constantly shuffle styles between the main menu and the fps overlay. --- OptiScaler/menu/menu_common.cpp | 32 ++++++++++++++++++++------------ OptiScaler/menu/menu_common.h | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/OptiScaler/menu/menu_common.cpp b/OptiScaler/menu/menu_common.cpp index b4b686bb..15d0dc79 100644 --- a/OptiScaler/menu/menu_common.cpp +++ b/OptiScaler/menu/menu_common.cpp @@ -1806,6 +1806,15 @@ bool MenuCommon::RenderMenu() // If Fps overlay is visible if (config->ShowFps.value_or_default()) { + // Rescale the fps overlay every frame because it shares style with the main menu + if (config->FpsScale.has_value() && config->FpsScale.value() != config->MenuScale.value_or_default()) + { + ImGuiStyle& style = ImGui::GetStyle(); + ImGuiStyle styleold = style; + style = ImGuiStyle(); + style.ScaleAllSizes(fpsScale); + } + // Set overlay position ImGui::SetNextWindowPos(overlayPosition, ImGuiCond_Always); @@ -1820,9 +1829,6 @@ bool MenuCommon::RenderMenu() else ImGui::PushStyleColor(ImGuiCol_PlotLines, green); - auto size = ImVec2 { 0.0f, 0.0f }; - ImGui::SetNextWindowSize(size); - if (ImGui::Begin("Performance Overlay", nullptr, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing | @@ -2152,10 +2158,10 @@ bool MenuCommon::RenderMenu() flags |= ImGuiWindowFlags_AlwaysAutoResize; // if UI scale is changed rescale the style - if (_imguiSizeUpdate || config->FpsScale.has_value()) + // FpsScale changes style every frame so this need to revert it for the main menu + if (_mainWindowSizeUpdate || + (config->FpsScale.has_value() && config->FpsScale.value() != config->MenuScale.value_or_default())) { - _imguiSizeUpdate = false; - ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle styleold = style; // Backup colors style = ImGuiStyle(); // IMPORTANT: ScaleAllSizes will change the original size, @@ -2176,10 +2182,13 @@ bool MenuCommon::RenderMenu() style.ScaleAllSizes(config->MenuScale.value_or_default()); style.MouseCursorScale = 1.0f; CopyMemory(style.Colors, styleold.Colors, sizeof(style.Colors)); // Restore colors - } - auto size = ImVec2 { 0.0f, 0.0f }; - ImGui::SetNextWindowSize(size); + if (_mainWindowSizeUpdate) + { + ImGui::SetNextWindowSize({ 1.0f, 1.0f }); + _mainWindowSizeUpdate = false; + } + } // Main menu window if (windowTitle.empty()) @@ -5503,12 +5512,11 @@ bool MenuCommon::RenderMenu() config->MenuScale = 0.5f + (float) n / 10.0f; ImGuiStyle& style = ImGui::GetStyle(); - style.ScaleAllSizes(config->MenuScale.value()); if (config->MenuScale.value() < 1.0f) style.MouseCursorScale = 1.0f; - _imguiSizeUpdate = true; + _mainWindowSizeUpdate = true; } } @@ -5873,7 +5881,7 @@ void MenuCommon::Init(HWND InHwnd, bool isUWP) if (!Config::Instance()->OverlayMenu.value_or_default()) { - _imguiSizeUpdate = true; + _mainWindowSizeUpdate = true; _hdrTonemapApplied = false; } diff --git a/OptiScaler/menu/menu_common.h b/OptiScaler/menu/menu_common.h index 82df51b0..dd44d201 100644 --- a/OptiScaler/menu/menu_common.h +++ b/OptiScaler/menu/menu_common.h @@ -114,7 +114,7 @@ class MenuCommon // ui scale inline static int _selectedScale = 5; - inline static bool _imguiSizeUpdate = true; + inline static bool _mainWindowSizeUpdate = true; // overlay states inline static bool _dx11Ready = false; From 36e38cd284f692184efd728f62a4b827ec26f79f Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:43:38 +0100 Subject: [PATCH 2/2] Use PushStyleVar to set style for the FPS Overlay --- OptiScaler/menu/menu_common.cpp | 41 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/OptiScaler/menu/menu_common.cpp b/OptiScaler/menu/menu_common.cpp index 15d0dc79..6c081ac0 100644 --- a/OptiScaler/menu/menu_common.cpp +++ b/OptiScaler/menu/menu_common.cpp @@ -1806,13 +1806,23 @@ bool MenuCommon::RenderMenu() // If Fps overlay is visible if (config->ShowFps.value_or_default()) { + bool stylePushed = false; + + static auto defaultStyle = ImGuiStyle(); + // Rescale the fps overlay every frame because it shares style with the main menu if (config->FpsScale.has_value() && config->FpsScale.value() != config->MenuScale.value_or_default()) { - ImGuiStyle& style = ImGui::GetStyle(); - ImGuiStyle styleold = style; - style = ImGuiStyle(); - style.ScaleAllSizes(fpsScale); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, defaultStyle.WindowPadding * fpsScale); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, defaultStyle.FramePadding * fpsScale); + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, defaultStyle.CellPadding * fpsScale); + ImGui::PushStyleVar(ImGuiStyleVar_SeparatorTextPadding, defaultStyle.SeparatorTextPadding * fpsScale); + + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, defaultStyle.ItemSpacing * fpsScale); + ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, defaultStyle.ItemInnerSpacing * fpsScale); + ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, defaultStyle.IndentSpacing * fpsScale); + + stylePushed = true; } // Set overlay position @@ -2100,6 +2110,9 @@ bool MenuCommon::RenderMenu() ImGui::End(); + if (stylePushed) + ImGui::PopStyleVar(7); + // Left / Right if (config->FpsOverlayPos.value_or_default() == 0 || config->FpsOverlayPos.value_or_default() == 2) overlayPosition.x = 0; @@ -2158,10 +2171,10 @@ bool MenuCommon::RenderMenu() flags |= ImGuiWindowFlags_AlwaysAutoResize; // if UI scale is changed rescale the style - // FpsScale changes style every frame so this need to revert it for the main menu - if (_mainWindowSizeUpdate || - (config->FpsScale.has_value() && config->FpsScale.value() != config->MenuScale.value_or_default())) + if (_mainWindowSizeUpdate) { + _mainWindowSizeUpdate = false; + ImGuiStyle& style = ImGui::GetStyle(); ImGuiStyle styleold = style; // Backup colors style = ImGuiStyle(); // IMPORTANT: ScaleAllSizes will change the original size, @@ -2183,11 +2196,7 @@ bool MenuCommon::RenderMenu() style.MouseCursorScale = 1.0f; CopyMemory(style.Colors, styleold.Colors, sizeof(style.Colors)); // Restore colors - if (_mainWindowSizeUpdate) - { - ImGui::SetNextWindowSize({ 1.0f, 1.0f }); - _mainWindowSizeUpdate = false; - } + ImGui::SetNextWindowSize({ 1.0f, 1.0f }); } // Main menu window @@ -5121,13 +5130,9 @@ bool MenuCommon::RenderMenu() ImGuiSliderFlags_ClampOnInput)) { if (currentIndex == 0) - { config->FpsScale.reset(); - } else - { config->FpsScale = values[currentIndex]; - } } } @@ -5511,10 +5516,8 @@ bool MenuCommon::RenderMenu() _selectedScale = n; config->MenuScale = 0.5f + (float) n / 10.0f; - ImGuiStyle& style = ImGui::GetStyle(); - if (config->MenuScale.value() < 1.0f) - style.MouseCursorScale = 1.0f; + ImGui::GetStyle().MouseCursorScale = 1.0f; _mainWindowSizeUpdate = true; }