Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Intersect.Client.Framework/Gwen/Control/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 24 additions & 1 deletion Intersect.Client.Framework/Gwen/ControlInternal/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading