Skip to content

Commit

Permalink
remote: Simplify DPI: add GetFontLoadingRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Apr 17, 2024
1 parent 9a92952 commit 5cbc334
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
24 changes: 23 additions & 1 deletion src/hello_imgui/internal/backend_impls/abstract_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,29 @@ bool _CheckDpiAwareParamsChanges(HelloImGui::RunnerParams& params)
dpiAwareParams.fontRenderingScale = io.FontGlobalScale;
}

if (didFontGlobalScaleChange)
bool didFontLoadingRatioChangeOnRemoteServer = false;
#ifdef HELLOIMGUI_WITH_NETIMGUI
if (params.remoteParams.enableRemoting)
{
float newFontLoadingRatio = NetImgui::GetFontLoadingRatio();
float currentFontLoadingRatio = dpiAwareParams.DpiFontLoadingFactor();
if (fabs(currentFontLoadingRatio - newFontLoadingRatio) > 0.001f)
{
didFontLoadingRatioChangeOnRemoteServer = true;

float oldDpiWindowSizeFactor = dpiAwareParams.dpiWindowSizeFactor;
dpiAwareParams.dpiWindowSizeFactor = dpiAwareParams.dpiWindowSizeFactor * newFontLoadingRatio / currentFontLoadingRatio;
float new_diff = fabs(dpiAwareParams.DpiFontLoadingFactor() - newFontLoadingRatio);
IM_ASSERT(new_diff < 0.001f);
printf("Warning: didFontLoadingRatioChange=true \n"
" currentFontLoadingRatio=%f newFontLoadingRatio=%f\n"
" oldDpiWindowSizeFactor=%f newDpiWindowSizeFactor=%f\n",
currentFontLoadingRatio, newFontLoadingRatio, oldDpiWindowSizeFactor, dpiAwareParams.dpiWindowSizeFactor);
}
}
#endif

if (didFontGlobalScaleChange || didFontLoadingRatioChangeOnRemoteServer)
{
printf("New DpiAwareParams:\n");
_LogDpiParams("_CheckDpiAwareParamsChanges (changed!)", dpiAwareParams);
Expand Down
6 changes: 1 addition & 5 deletions src/netimgui_remote_display/netimgui_remote_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ int main(int argc, char **argv)

runnerParams.callbacks.PreNewFrame = []() {
// Request each client to update their drawing content
NetImguiServer::UI::SetFullDPISettings(
ImGui::GetIO().DisplayFramebufferScale,
1.f / HelloImGui::DpiFontLoadingFactor()
);

NetImguiServer::UI::SetUseServerDPISettings(HelloImGui::DpiFontLoadingFactor());
NetImguiServer::App::UpdateRemoteContent();
};

Expand Down

0 comments on commit 5cbc334

Please sign in to comment.