Delegate PlaceholderPainter
Draws a placeholder's content where DrawTextLayout(TextLayout, Vector2, RectF?, PlaceholderPainter?) left room for it.
public delegate void PlaceholderPainter(Canvas canvas, int index, RectF box)
Parameters
canvasCanvasThe canvas being drawn on.
indexintThe placeholder's index in the rich text.
boxRectFThe placeholder's box, in the canvas's local coordinates.
Examples
ParagraphStyle style = new()
{
DefaultStyle = new TextStyle
{
FontFamilies = [family],
Size = 18,
Color = new Rgba8(30, 30, 60, 255),
Shadows = [new TextShadow(new System.Numerics.Vector2(1, 1), 2, new Rgba8(0, 0, 0, 80))],
},
Align = TextAlign.Justify,
};
// One call: wrap into a box, centred across the lines.
TextLayout boxed = canvas.DrawText("Paragraphs wrap, justify and drop shadows.", new RectF(10, 10, 300, 80), style, VerticalAlign.Center);
// Or lay out once and draw where needed, skipping lines outside the visible part.
TextLayout layout = Paragraph.Create("Laid out once, drawn many times.", style).Layout(300);
canvas.DrawTextLayout(layout, new System.Numerics.Vector2(10, 110), visibleRect: new RectF(0, 0, 320, 200));
// Inline placeholders (an icon, a badge) are drawn by a painter called with each one's box.
canvas.DrawTextLayout(layout, new System.Numerics.Vector2(10, 130), placeholderPainter: (c, index, box) => c.FillRoundRect(new RoundRect(box, 3), new Rgba8(200, 60, 40, 255)));
// The same text as one path: glyphs and decorations.
Egami.Drawing.Path outline = layout.ToPath(new System.Numerics.Vector2(10, 150));