Fixes TextPath rendering bugs (#1308)

* Do not emit line break when rendering
* Don't be greedy when measuring.
* Fix a condition that decides if the path fits in the allotted space.

Closes #1307
This commit is contained in:
Patrik Svensson
2023-09-18 08:04:57 +02:00
committed by GitHub
parent 2af3f7faeb
commit 943c045fab
4 changed files with 43 additions and 34 deletions

View File

@ -74,7 +74,7 @@ public sealed class TextPath : IRenderable, IHasJustification
return new Measurement(
Math.Min(length, maxWidth),
Math.Max(length, maxWidth));
Math.Min(length, maxWidth));
}
/// <inheritdoc/>
@ -119,9 +119,6 @@ public sealed class TextPath : IRenderable, IHasJustification
// Align the result
Aligner.Align(parts, Justification, maxWidth);
// Insert a line break
parts.Add(Segment.LineBreak);
return parts;
}
@ -134,7 +131,7 @@ public sealed class TextPath : IRenderable, IHasJustification
}
// Will it fit as is?
if (_parts.Sum(p => Cell.GetCellLength(p)) + (_parts.Length - 1) < maxWidth)
if (_parts.Sum(Cell.GetCellLength) + (_parts.Length - 1) <= maxWidth)
{
return _parts;
}
@ -159,7 +156,7 @@ public sealed class TextPath : IRenderable, IHasJustification
var queueWidth =
rootLength // Root (if rooted)
+ ellipsisLength // Ellipsis
+ queue.Sum(p => Cell.GetCellLength(p)) // Middle
+ queue.Sum(Cell.GetCellLength) // Middle
+ Cell.GetCellLength(_parts.Last()) // Last
+ queue.Count + separatorCount; // Separators