From df105fb20387af72d88f42064a03232fe4c5478c Mon Sep 17 00:00:00 2001 From: Arufonsu <17498701+Arufonsu@users.noreply.github.com> Date: Sat, 14 Feb 2026 21:18:22 -0300 Subject: [PATCH] fix: text input caret Signed-off-by: Arufonsu <17498701+Arufonsu@users.noreply.github.com> --- .../Gwen/Control/Label.cs | 30 +++++++++---------- .../Gwen/ControlInternal/Text.cs | 25 +++++++++++++++- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Intersect.Client.Framework/Gwen/Control/Label.cs b/Intersect.Client.Framework/Gwen/Control/Label.cs index 778fe86f19..2019a33012 100644 --- a/Intersect.Client.Framework/Gwen/Control/Label.cs +++ b/Intersect.Client.Framework/Gwen/Control/Label.cs @@ -745,31 +745,31 @@ protected override void OnChildBoundsChanged(Base child, Rectangle oldChildBound { base.OnChildBoundsChanged(child, oldChildBounds, newChildBounds); - if (oldChildBounds.Size != newChildBounds.Size) + if (oldChildBounds.Size == newChildBounds.Size) { - if (_autoSizeToContents) - { - Invalidate(); - } - else + return; + } + + if (!_autoSizeToContents) + { + if (child is Text) { - if (child is Text) + var textSize = newChildBounds.Size; + var ownSize = Size; + if (textSize.X > ownSize.X || textSize.Y > ownSize.Y) { - var textSize = newChildBounds.Size; - var ownSize = Size; - if (textSize.X > ownSize.X || textSize.Y > ownSize.Y) - { - OnTextExceedsSize(ownSize, textSize); - } + OnTextExceedsSize(ownSize, textSize); } - - AlignTextElement(_textElement); } } + + // Always invalidate when text bounds change + Invalidate(); } protected virtual void OnTextExceedsSize(Point ownSize, Point textSize) { + Invalidate(); } public virtual void SetTextScale(float scale) diff --git a/Intersect.Client.Framework/Gwen/ControlInternal/Text.cs b/Intersect.Client.Framework/Gwen/ControlInternal/Text.cs index f6e4107a76..8aaf5b8073 100644 --- a/Intersect.Client.Framework/Gwen/ControlInternal/Text.cs +++ b/Intersect.Client.Framework/Gwen/ControlInternal/Text.cs @@ -365,11 +365,34 @@ public Point GetCharacterPosition(int index) } var substring = displayedText[..index]; - var substringSize = Skin.Renderer.MeasureText(font, fontSize: _fontSize, substring) with + var substringSize = Skin.Renderer.MeasureText(font, fontSize: _fontSize, substring, _scale) with { Y = 0, }; + if (substringSize.X <= 0 && substring.Length > 0) + { + var referenceCharWidth = Skin.Renderer.MeasureText(font, fontSize: _fontSize, "n", _scale).X; + + if (referenceCharWidth <= 0) + { + referenceCharWidth = (int)(_fontSize * 0.6f); + } + + var spaceWidth = (int)(referenceCharWidth * 0.4f); + var accumulatedWidth = 0; + + for (int i = 0; i < substring.Length; i++) + { + var charStr = substring[i].ToString(); + var charSize = Skin.Renderer.MeasureText(font, fontSize: _fontSize, charStr, _scale); + + accumulatedWidth += charSize.X > 0 ? charSize.X : spaceWidth; + } + + return new Point(accumulatedWidth, 0); + } + return substringSize; }