Fix text box selection height on macOS with custom system scale (hack)

This commit is contained in:
2026-04-18 21:01:37 +02:00
parent e65cd3799f
commit 925b83e095
3 changed files with 11 additions and 2 deletions
@@ -379,6 +379,9 @@ namespace FlaxEngine.GUI
var leftEdge = selection.StartIndex <= textBlock.Range.StartIndex ? textBlock.Bounds.UpperLeft : GetCharPosition(selection.StartIndex, out _);
var rightEdge = selection.EndIndex >= textBlock.Range.EndIndex ? textBlock.Bounds.UpperRight : GetCharPosition(selection.EndIndex, out _);
float height = font.Height;
#if PLATFORM_MAC && !PLATFORM_SDL
height /= (float)Platform.Dpi / 96.0f; // TODO: refactor DPI support on macOS to skip such hacks
#endif
float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f);
alpha *= alpha;
Color selectionColor = Color.White * alpha;
+5 -2
View File
@@ -253,8 +253,11 @@ namespace FlaxEngine.GUI
{
var leftEdge = font.GetCharPosition(text, SelectionLeft, ref _layout);
var rightEdge = font.GetCharPosition(text, SelectionRight, ref _layout);
var fontHeight = font.Height;
var textHeight = fontHeight / DpiScale;
float fontHeight = font.Height;
#if PLATFORM_MAC && !PLATFORM_SDL
fontHeight /= (float)Platform.Dpi / 96.0f; // TODO: refactor DPI support on macOS to skip such hacks
#endif
float textHeight = fontHeight / DpiScale;
// Draw selection background
float alpha = Mathf.Min(1.0f, Mathf.Cos(_animateTime * BackgroundSelectedFlashSpeed) * 0.5f + 1.3f);
@@ -556,6 +556,9 @@ namespace FlaxEngine.GUI
{
const float caretWidth = 1.2f;
Float2 caretPos = GetCharPosition(CaretPosition, out var height);
#if PLATFORM_MAC && !PLATFORM_SDL
height /= (float)Platform.Dpi / 96.0f; // TODO: refactor DPI support on macOS to skip such hacks
#endif
return new Rectangle(
caretPos.X - (caretWidth * 0.5f),
caretPos.Y,