ImGuiManager: Defer scale updates

Fixes OSD spinbox closing on click, and popups closing on window resize.
This commit is contained in:
Stenzek 2024-02-19 22:37:25 +09:00 committed by Connor McLaughlin
parent e6303cef9e
commit d3c97bedb9
3 changed files with 17 additions and 11 deletions

View File

@ -701,7 +701,7 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config)
// Handle OSD scale changes by pushing a window resize through.
if (new_config.OsdScale != old_config.OsdScale)
ImGuiManager::WindowResized();
ImGuiManager::RequestScaleUpdate();
// Options which need a full teardown/recreate.
if (!GSConfig.RestartOptionsAreEqual(old_config))

View File

@ -47,6 +47,7 @@ namespace ImGuiManager
std::pair<float, float> pos;
};
static void UpdateScale();
static void SetStyle();
static void SetKeyMap();
static bool LoadFontData();
@ -96,6 +97,7 @@ static constexpr float OSD_FADE_OUT_TIME = 0.4f;
// need to keep track of this, so we can reinitialize on renderer switch
static bool s_fullscreen_ui_was_initialized = false;
static bool s_scale_changed = false;
static std::array<ImGuiManager::SoftwareCursor, InputManager::MAX_SOFTWARE_CURSORS> s_software_cursors = {};
@ -134,6 +136,7 @@ bool ImGuiManager::Initialize()
}
s_global_scale = std::max(0.5f, g_gs_device->GetWindowScale() * (GSConfig.OsdScale / 100.0f));
s_scale_changed = false;
ImGui::CreateContext();
@ -225,11 +228,13 @@ void ImGuiManager::WindowResized()
s_window_height = static_cast<float>(new_height);
ImGui::GetIO().DisplaySize = ImVec2(s_window_width, s_window_height);
UpdateScale();
// Scale might have changed as a result of window resize.
RequestScaleUpdate();
}
// restart imgui frame on the new window size to pick it up, otherwise we draw to the old size
ImGui::EndFrame();
NewFrame();
void ImGuiManager::RequestScaleUpdate()
{
s_scale_changed = true;
}
void ImGuiManager::UpdateScale()
@ -240,9 +245,6 @@ void ImGuiManager::UpdateScale()
if ((!HasFullscreenFonts() || !ImGuiFullscreen::UpdateLayoutScale()) && scale == s_global_scale)
return;
// This is assumed to be called mid-frame.
ImGui::EndFrame();
s_global_scale = scale;
SetStyle();
@ -251,8 +253,6 @@ void ImGuiManager::UpdateScale()
if (!g_gs_device->UpdateImGuiFontTexture())
pxFailRel("Failed to recreate font texture after scale+resize");
NewFrame();
}
void ImGuiManager::NewFrame()
@ -260,6 +260,12 @@ void ImGuiManager::NewFrame()
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = s_last_render_time.GetTimeSecondsAndReset();
if (s_scale_changed)
{
s_scale_changed = false;
UpdateScale();
}
ImGui::NewFrame();
// Disable nav input on the implicit (Debug##Default) window. Otherwise we end up requesting keyboard

View File

@ -35,7 +35,7 @@ namespace ImGuiManager
void WindowResized();
/// Updates scaling of the on-screen elements.
void UpdateScale();
void RequestScaleUpdate();
/// Call at the beginning of the frame to set up ImGui state.
void NewFrame();