TextFitting Class
Fits texts in the space a layout gives them: truncation with an ellipsis, and wrapping on several lines.
public static class TextFittingMethods
| Name | Description |
|---|---|
| Truncate(ITextMeasurer, string, SceneFont, double) | Shortens a text by whole grapheme clusters and appends an ellipsis, so it fits a width. |
| Wrap(ITextMeasurer, string, SceneFont, double) | Splits a text into lines that fit a width. The text is broken at the line break opportunities of the Unicode line breaking algorithm (UAX #14), and at its line feeds; a word wider than the width is broken between grapheme clusters. |
Truncate(ITextMeasurer, string, SceneFont, double)
TextFitting.csShortens a text by whole grapheme clusters and appends an ellipsis, so it fits a width.
public static string? Truncate(ITextMeasurer measurer, string text, SceneFont font, double maxWidth)Parameters
measurerITextMeasurer- The measurer of the font that draws the text.
textstring- The text, on one line.
fontSceneFont- The font.
maxWidthdouble- The available width.
Returns
string? The text when it fits, the shortened text, or null when not even the first character fits with the ellipsis.
Wrap(ITextMeasurer, string, SceneFont, double)
TextFitting.csSplits a text into lines that fit a width. The text is broken at the line break opportunities of the Unicode line breaking algorithm (UAX #14), and at its line feeds; a word wider than the width is broken between grapheme clusters.
public static IReadOnlyList<string> Wrap(ITextMeasurer measurer, string text, SceneFont font, double maxWidth)Parameters
measurerITextMeasurer- The measurer of the font that draws the text.
textstring- The text.
fontSceneFont- The font.
maxWidthdouble- The available width. A value that is not positive and finite keeps every line of the text whole.
Returns
IReadOnlyList<string> The lines, without their trailing spaces and line terminators. An empty text returns one empty line.
Constants
| Name | Description |
|---|---|
| Ellipsis | The ellipsis TextFitting.Truncate appends, … (U+2026). |
Ellipsis
The ellipsis TextFitting.Truncate appends, … (U+2026).
public const string Ellipsis = "…"