From 746eb80300f788e1c340f8d5b363a9eac94f7499 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 1 Sep 2022 11:23:16 +0400 Subject: [PATCH] Allow interface scale of 50%. --- ui/style/style_core_scale.cpp | 2 +- ui/style/style_core_scale.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ui/style/style_core_scale.cpp b/ui/style/style_core_scale.cpp index 2aefdc2..9e0038f 100644 --- a/ui/style/style_core_scale.cpp +++ b/ui/style/style_core_scale.cpp @@ -21,7 +21,7 @@ int DevicePixelRatio() { } void SetDevicePixelRatio(int ratio) { - DevicePixelRatioValue = ratio; + DevicePixelRatioValue = std::clamp(ratio, 1, kScaleMax / kScaleMin); } int Scale() { diff --git a/ui/style/style_core_scale.h b/ui/style/style_core_scale.h index 93ac4da..2fba205 100644 --- a/ui/style/style_core_scale.h +++ b/ui/style/style_core_scale.h @@ -16,7 +16,7 @@ namespace style { inline constexpr auto kScaleAuto = 0; -inline constexpr auto kScaleMin = 75; +inline constexpr auto kScaleMin = 50; inline constexpr auto kScaleDefault = 100; inline constexpr auto kScaleMax = 300; @@ -34,9 +34,12 @@ void SetScale(int scale); template [[nodiscard]] inline T ConvertScale(T value, int scale) { - return (value < 0.) - ? (-ConvertScale(-value, scale)) - : T(base::SafeRound((double(value) * scale / 100.) - 0.01)); + if (value < 0.) { + return -ConvertScale(-value, scale); + } + const auto result = T(base::SafeRound( + (double(value) * scale / 100.) - 0.01)); + return (!std::is_integral_v || !value || result) ? result : 1; } template