Browse Source

Fix TextLayout overflow (#17914)

* Update TextLayout only if finalSize is different from _constraint

* Added comment
pull/17948/head
Compunet 1 year ago
committed by GitHub
parent
commit
8fe22dc3ee
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      src/Avalonia.Controls/Presenters/TextPresenter.cs

18
src/Avalonia.Controls/Presenters/TextPresenter.cs

@ -634,6 +634,8 @@ namespace Avalonia.Controls.Presenters
protected override Size ArrangeOverride(Size finalSize)
{
var finalWidth = finalSize.Width;
var textWidth = Math.Ceiling(TextLayout.OverhangLeading + TextLayout.WidthIncludingTrailingWhitespace + TextLayout.OverhangTrailing);
if (finalSize.Width < textWidth)
@ -641,15 +643,17 @@ namespace Avalonia.Controls.Presenters
finalSize = finalSize.WithWidth(textWidth);
}
if (MathUtilities.AreClose(_constraint.Width, finalSize.Width))
// Check if the '_constraint' has changed since the last measure,
// if so recalculate the TextLayout according to the new size
// NOTE: It is important to check this against the actual final size
// (excluding the trailing whitespace) to avoid TextLayout overflow.
if (MathUtilities.AreClose(_constraint.Width, finalWidth) == false)
{
return finalSize;
}
_constraint = new Size(Math.Ceiling(finalSize.Width), double.PositiveInfinity);
_constraint = new Size(Math.Ceiling(finalWidth), double.PositiveInfinity);
_textLayout?.Dispose();
_textLayout = null;
_textLayout?.Dispose();
_textLayout = null;
}
return finalSize;
}

Loading…
Cancel
Save