From 7b9da3786d19bfc14de600eee56061ac9d2bd005 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 23 Sep 2024 15:57:21 -0500 Subject: [PATCH] Fix carrot position when no text but text alignment --- Source/Engine/Render2D/Font.cpp | 14 +++++++++++++- Source/Engine/UI/GUI/Common/TextBox.cs | 1 - 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Render2D/Font.cpp b/Source/Engine/Render2D/Font.cpp index 8fcb2e020..41924e50b 100644 --- a/Source/Engine/Render2D/Font.cpp +++ b/Source/Engine/Render2D/Font.cpp @@ -402,7 +402,19 @@ Float2 Font::GetCharPosition(const StringView& text, int32 index, const TextLayo { // Check if there is no need to do anything if (text.IsEmpty()) - return layout.Bounds.Location; + { + Float2 location = layout.Bounds.Location; + if (layout.VerticalAlignment == TextAlignment::Center) + location.Y += layout.Bounds.Size.Y * 0.5f - static_cast(_height) * 0.5f; + else if (layout.VerticalAlignment == TextAlignment::Far) + location.Y += layout.Bounds.Size.Y - static_cast(_height) * 0.5f; + + if (layout.HorizontalAlignment == TextAlignment::Center) + location.X += layout.Bounds.Size.X * 0.5f; + else if (layout.HorizontalAlignment == TextAlignment::Far) + location.X += layout.Bounds.Size.X; + return location; + } // Process text Array lines; diff --git a/Source/Engine/UI/GUI/Common/TextBox.cs b/Source/Engine/UI/GUI/Common/TextBox.cs index 2398d75c5..f99d7140a 100644 --- a/Source/Engine/UI/GUI/Common/TextBox.cs +++ b/Source/Engine/UI/GUI/Common/TextBox.cs @@ -292,7 +292,6 @@ namespace FlaxEngine.GUI float alpha = Mathf.Saturate(Mathf.Cos(_animateTime * CaretFlashSpeed) * 0.5f + 0.7f); alpha = alpha * alpha * alpha * alpha * alpha * alpha; Render2D.FillRectangle(CaretBounds, CaretColor * alpha); - } // Restore rendering state