From 9c1817330d27c3b59b5baed1aa178b94c4f35b3b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 27 Jul 2026 20:49:41 -0500 Subject: [PATCH 1/3] Fix text box highlighting not using DPI --- Source/Engine/UI/GUI/Common/TextBox.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/TextBox.cs b/Source/Engine/UI/GUI/Common/TextBox.cs index 1346a8c2b..c077597aa 100644 --- a/Source/Engine/UI/GUI/Common/TextBox.cs +++ b/Source/Engine/UI/GUI/Common/TextBox.cs @@ -66,7 +66,7 @@ namespace FlaxEngine.GUI } /// - /// The vertical alignment of the text. + /// The horizontal alignment of the text. /// [EditorDisplay("Text Style"), EditorOrder(2024), Tooltip("The horizontal alignment of the text.")] public TextAlignment HorizontalAlignment @@ -268,7 +268,7 @@ namespace FlaxEngine.GUI if (selectedLinesCount == 1) { // Selected is part of single line - Rectangle r1 = new Rectangle(leftEdge.X, leftEdge.Y, rightEdge.X - leftEdge.X, fontHeight); + Rectangle r1 = new Rectangle(leftEdge.X, leftEdge.Y, rightEdge.X - leftEdge.X, textHeight); Render2D.FillRectangle(r1, selectionColor); } else @@ -276,17 +276,17 @@ namespace FlaxEngine.GUI float leftMargin = _layout.Bounds.Location.X; // Selected is more than one line - Rectangle r1 = new Rectangle(leftEdge.X, leftEdge.Y, 1000000000, fontHeight); + Rectangle r1 = new Rectangle(leftEdge.X, leftEdge.Y, 1000000000, textHeight); Render2D.FillRectangle(r1, selectionColor); // for (int i = 3; i <= selectedLinesCount; i++) { leftEdge.Y += textHeight; - Rectangle r = new Rectangle(leftMargin, leftEdge.Y, 1000000000, fontHeight); + Rectangle r = new Rectangle(leftMargin, leftEdge.Y, 1000000000, textHeight); Render2D.FillRectangle(r, selectionColor); } // - Rectangle r2 = new Rectangle(leftMargin, rightEdge.Y, rightEdge.X - leftMargin, fontHeight); + Rectangle r2 = new Rectangle(leftMargin, rightEdge.Y, rightEdge.X - leftMargin, textHeight); Render2D.FillRectangle(r2, selectionColor); } } From d2057d9c4f7b6c64ae3e1af9b063dc8ef4b63f3b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 27 Jul 2026 21:02:16 -0500 Subject: [PATCH 2/3] Fix caret height. DPI is handled in the GetCharPosition method of the text boxes. --- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 415a3c9c8..d3dbcc57a 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -563,7 +563,7 @@ namespace FlaxEngine.GUI caretPos.X - (caretWidth * 0.5f), caretPos.Y, caretWidth, - height * DpiScale); + height); } } From 2eb36590dcfecdf8a18894395964152a0c0e9c2e Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 27 Jul 2026 21:02:38 -0500 Subject: [PATCH 3/3] Fix highlight height and underline location to be dpi aware. --- Source/Engine/UI/GUI/Common/RichTextBoxBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs index ff94a73f0..97e1d88a5 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs @@ -378,7 +378,7 @@ 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; + float height = font.Height / DpiScale; #if PLATFORM_MAC && !PLATFORM_SDL height /= (float)Platform.Dpi / 96.0f; // TODO: refactor DPI support on macOS to skip such hacks #endif @@ -431,7 +431,7 @@ namespace FlaxEngine.GUI if (textBlock.Style.UnderlineBrush != null) { var underLineHeight = 2.0f; - var height = font.Height; + var height = font.Height / DpiScale; var underlineRect = new Rectangle(textBlock.Bounds.Location.X, textBlock.Bounds.Location.Y + height - underLineHeight * 0.5f, textBlock.Bounds.Width, underLineHeight); textBlock.Style.UnderlineBrush.Draw(underlineRect, textBlock.Style.Color); }