Skip to content

Commit b534ec1

Browse files
committed
Add UI scaling option
On some platforms/displays, the auto-detected font size might be a bit too small or large, so we should let the user apply a custom scaling factor.
1 parent 080e48b commit b534ec1

File tree

5 files changed

+155
-46
lines changed

5 files changed

+155
-46
lines changed

src/gui/ProjectMGUI.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ void ProjectMGUI::Draw()
130130
return;
131131
}
132132

133+
if (_userScalingFactor != GetClampedUserScalingFactor())
134+
{
135+
UpdateFontSize();
136+
}
137+
133138
ImGui_ImplSDL2_NewFrame();
134139
ImGui_ImplOpenGL3_NewFrame();
135140
ImGui::NewFrame();
@@ -218,9 +223,16 @@ float ProjectMGUI::GetScalingFactor()
218223
SDL_GetWindowSize(_renderingWindow, &windowWidth, &windowHeight);
219224
SDL_GL_GetDrawableSize(_renderingWindow, &renderWidth, &renderHeight);
220225

226+
_userScalingFactor = GetClampedUserScalingFactor();
227+
221228
// If the OS has a scaled UI, this will return the inverse factor. E.g. if the display is scaled to 200%,
222229
// the renderWidth (in actual pixels) will be twice as much as the "virtual" unscaled window width.
223-
return ((static_cast<float>(windowWidth) / static_cast<float>(renderWidth)) + (static_cast<float>(windowHeight) / static_cast<float>(renderHeight))) * 0.5f;
230+
return ((static_cast<float>(windowWidth) / static_cast<float>(renderWidth)) + (static_cast<float>(windowHeight) / static_cast<float>(renderHeight))) * 0.5f * _userScalingFactor;
231+
}
232+
233+
float ProjectMGUI::GetClampedUserScalingFactor()
234+
{
235+
return std::min(3.0f, std::max(0.1f, static_cast<float>(Poco::Util::Application::instance().config().getDouble("window.uiScale", 1.0))));
224236
}
225237

226238
void ProjectMGUI::DisplayToastNotificationHandler(const Poco::AutoPtr<DisplayToastNotification>& notification)

src/gui/ProjectMGUI.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class ProjectMGUI : public Poco::Util::Subsystem
107107
private:
108108
float GetScalingFactor();
109109

110+
static float GetClampedUserScalingFactor();
111+
110112
void DisplayToastNotificationHandler(const Poco::AutoPtr<DisplayToastNotification>& notification);
111113

112114
ProjectMWrapper* _projectMWrapper{nullptr};
@@ -122,6 +124,7 @@ class ProjectMGUI : public Poco::Util::Subsystem
122124

123125
uint64_t _lastFrameTicks{0}; //!< Tick count of the last frame (see SDL_GetTicks64)
124126

127+
float _userScalingFactor{1.0f}; //!< The user-defined UI scaling factor.
125128
float _textScalingFactor{0.0f}; //!< The text scaling factor.
126129

127130
MainMenu _mainMenu{*this};

0 commit comments

Comments
 (0)