Struct Placeholder
An inline box laid out with the text, such as an icon or an image, which the caller draws: it stands for an object replacement character (U+FFFC) in the text, so bidi, line breaking and indexes treat it as one character.
public readonly record struct Placeholder : IEquatable<Placeholder>
- Implements
- Inherited Members
Examples
// Font families come from a collection; later families cover what the first lacks.
FontCollection fonts = new();
fonts.AddFile(System.IO.Path.Combine(folder, "NotoSans-Regular.ttf"));
fonts.AddFile(System.IO.Path.Combine(folder, "NotoSansArabic-Regular.ttf"));
fonts.TryGetFamily("Noto Sans", out FontFamily latin);
fonts.TryGetFamily("Noto Sans Arabic", out FontFamily arabic);
// Styles nest: the inner span keeps the outer one's size and adds a color and an underline.
RichText text = new RichTextBuilder()
.Append("Peace is ")
.Push(new TextStyle { Size = 20 })
.Append("\u0633\u0644\u0627\u0645 ")
.Push(new TextStyle { Color = new Rgba8(200, 30, 30, 255), Decoration = new TextDecoration() })
.Append("in Arabic")
.Pop()
.Pop()
.AddPlaceholder(new Placeholder(16, 16, PlaceholderAlignment.Middle))
.ToRichText();
ParagraphStyle style = new()
{
DefaultStyle = new TextStyle { FontFamilies = [latin, arabic], Size = 16, LineHeight = LineHeight.Multiple(1.4f) },
Align = TextAlign.Justify,
LineBreaking = new LineBreakOptions(WordBreak: WordBreak.Normal),
};
// Shaped once: lay it out at any width later.
Paragraph paragraph = Paragraph.Create(text, style);
Constructors
Placeholder(float, float, PlaceholderAlignment, float)
An inline box laid out with the text, such as an icon or an image, which the caller draws: it stands for an object replacement character (U+FFFC) in the text, so bidi, line breaking and indexes treat it as one character.
public Placeholder(float Width, float Height, PlaceholderAlignment Alignment = PlaceholderAlignment.Baseline, float BaselineOffset = 0)
Parameters
WidthfloatThe box's width in canvas units.
HeightfloatThe box's height in canvas units.
AlignmentPlaceholderAlignmentHow the box sits on its line.
BaselineOffsetfloatFor Baseline, the distance from the box's top to the point that sits on the text's baseline.
Examples
// Font families come from a collection; later families cover what the first lacks.
FontCollection fonts = new();
fonts.AddFile(System.IO.Path.Combine(folder, "NotoSans-Regular.ttf"));
fonts.AddFile(System.IO.Path.Combine(folder, "NotoSansArabic-Regular.ttf"));
fonts.TryGetFamily("Noto Sans", out FontFamily latin);
fonts.TryGetFamily("Noto Sans Arabic", out FontFamily arabic);
// Styles nest: the inner span keeps the outer one's size and adds a color and an underline.
RichText text = new RichTextBuilder()
.Append("Peace is ")
.Push(new TextStyle { Size = 20 })
.Append("\u0633\u0644\u0627\u0645 ")
.Push(new TextStyle { Color = new Rgba8(200, 30, 30, 255), Decoration = new TextDecoration() })
.Append("in Arabic")
.Pop()
.Pop()
.AddPlaceholder(new Placeholder(16, 16, PlaceholderAlignment.Middle))
.ToRichText();
ParagraphStyle style = new()
{
DefaultStyle = new TextStyle { FontFamilies = [latin, arabic], Size = 16, LineHeight = LineHeight.Multiple(1.4f) },
Align = TextAlign.Justify,
LineBreaking = new LineBreakOptions(WordBreak: WordBreak.Normal),
};
// Shaped once: lay it out at any width later.
Paragraph paragraph = Paragraph.Create(text, style);
Properties
Alignment
How the box sits on its line.
public PlaceholderAlignment Alignment { get; init; }
Property Value
BaselineOffset
For Baseline, the distance from the box's top to the point that sits on the text's baseline.
public float BaselineOffset { get; init; }
Property Value
Height
The box's height in canvas units.
public float Height { get; init; }
Property Value
Width
The box's width in canvas units.
public float Width { get; init; }