Skip to content

Commit

Permalink
Fixup Save/LoadLastRunWindowBounds: also save DpiWindowSizeFactor / r…
Browse files Browse the repository at this point in the history
…estore size with DPI handling
  • Loading branch information
pthom committed Jul 5, 2024
1 parent 1a53360 commit 60d0f73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ void AbstractRunner::Setup()
Impl_Select_Gl_Version();
#endif

SetupDpiAwareParams();
PrepareWindowGeometry();

auto fnRenderCallbackDuringResize = [this]()
Expand All @@ -730,6 +729,9 @@ void AbstractRunner::Setup()

Impl_SetWindowIcon();

SetupDpiAwareParams();


// This should be done before Impl_LinkPlatformAndRenderBackends()
// because, in the case of glfw ImGui_ImplGlfw_InstallCallbacks
// will chain the user callbacks with ImGui callbacks;
Expand Down
11 changes: 8 additions & 3 deletions src/hello_imgui/internal/hello_imgui_ini_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,16 @@ namespace HelloImGui
// DpiWindowSizeFactor was added late, so it may not be present in the ini file
if (appWindowSection.find("DpiWindowSizeFactor") != appWindowSection.end())
{
float dpiWindowSizeFactor_WhenSaved = iniFile["AppWindow"]["DpiWindowSizeFactor"].as<float>();
bool isDpiSane = (dpiWindowSizeFactor_WhenSaved >= 0.1) || (dpiWindowSizeFactor_WhenSaved <= 10.0);
float dpiWindowSizeFactor_Now =
HelloImGui::GetRunnerParams()->dpiAwareParams.dpiWindowSizeFactor;
float dpiWindowSizeFactor_WhenSaved =
iniFile["AppWindow"]["DpiWindowSizeFactor"].as<float>();
bool isDpiSane = (dpiWindowSizeFactor_WhenSaved >= 0.1f) &&
(dpiWindowSizeFactor_WhenSaved <= 10.f) &&
(dpiWindowSizeFactor_Now > 0.1f) &&
(dpiWindowSizeFactor_Now < 10.f);
if (isDpiSane)
{
float dpiWindowSizeFactor_Now = HelloImGui::GetRunnerParams()->dpiAwareParams.dpiWindowSizeFactor;
float ratio = dpiWindowSizeFactor_Now / dpiWindowSizeFactor_WhenSaved;
if (ratio != 1.f)
{
Expand Down

0 comments on commit 60d0f73

Please sign in to comment.