fix/interface-scale

This commit is contained in:
xrEugene
2026-08-06 17:27:28 +03:00
parent 1e5d8e3329
commit bb223ff093
3 changed files with 35 additions and 2 deletions
+5 -2
View File
@@ -129,10 +129,13 @@ namespace FlaxEditor.Options
float prevInterfaceScale = Options.Interface.InterfaceScale;
Options = options;
OnOptionsChanged();
// Scale interface relative to the current value (eg. when using system-provided Dpi Scale)
// Scale interface relative to the current value (eg. when using system-provided Dpi Scale).
// Apply this before OnOptionsChanged so newly created fonts get rasterized at the target DPI scale (avoids blurry text).
Platform.CustomDpiScale *= Options.Interface.InterfaceScale / prevInterfaceScale;
Font.SetGlobalScale(Platform.DpiScale);
OnOptionsChanged();
}
else
{
+18
View File
@@ -3,12 +3,30 @@
#include "Font.h"
#include "FontAsset.h"
#include "FontManager.h"
#include "Engine/Content/Content.h"
#include "Engine/Core/Log.h"
#include "Engine/Threading/Threading.h"
#include "IncludeFreeType.h"
Array<AssetReference<FontAsset>, HeapAllocation> Font::FallbackFonts;
float Font::GetGlobalScale()
{
return FontManager::FontScale;
}
void Font::SetGlobalScale(float scale)
{
if (scale <= 0.0f || Math::NearEqual(FontManager::FontScale, scale)) return;
FontManager::FontScale = scale;
// Invalidate all loaded font assets so cached glyphs are re-rasterized and Font metrics are recomputed at the new scale
auto assets = Content::GetAssets<FontAsset>();
for (auto* asset : assets) if (asset) asset->Invalidate();
FontManager::Flush();
}
Font::Font(FontAsset* parentAsset, float size)
: ManagedScriptingObject(SpawnParams(Guid::New(), Font::TypeInitializer))
, _asset(parentAsset)
+12
View File
@@ -261,6 +261,18 @@ public:
/// </summary>
API_FIELD() static Array<AssetReference<FontAsset>, HeapAllocation> FallbackFonts;
/// <summary>
/// Gets the global font scaling factor used to rasterize font glyphs at higher resolutions (eg. for high-DPI displays or UI scaling).
/// </summary>
API_PROPERTY() static float GetGlobalScale();
/// <summary>
/// Sets the global font scaling factor used to rasterize font glyphs at higher resolutions (eg. for high-DPI displays or UI scaling).
/// Calling this rebuilds the cached glyphs and metrics of every loaded font so text rendered afterwards stays crisp at the new scale.
/// </summary>
/// <param name="scale">The new font scale (must be greater than 0).</param>
API_FUNCTION() static void SetGlobalScale(float scale);
/// <summary>
/// Gets parent font asset that contains font family used by this font.
/// </summary>