protected override void DrawRect(SKCanvas canvas, SKRect size) { base.DrawRect(canvas, size); if (IsCenteredVertically) { canvas.DrawTextCenteredVertically( Text, Paint, new SKPoint( x: size.Left + (size.Width / 2), y: size.Top + (size.Height / 2) ) ); } else { canvas.DrawText( Text, x: size.Left + (size.Width / 2), y: size.Top + (size.Height / 2) + (Paint.TextSize / 2),//TODO, not right paint: Paint ); } }
/// <summary> /// Draws text vertically aligned /// </summary> /// <param name="canvas">The canvas.</param> /// <param name="text">The text to display</param> /// <param name="paint">The paint to use for text and calculations</param> /// <param name="point">The baseLine point where to vertically draw</param> /// <remarks>https://stackoverflow.com/questions/27631736/meaning-of-top-ascent-baseline-descent-bottom-and-leading-in-androids-font</remarks> public static void DrawTextCenteredVertically(this SKCanvas canvas, string text, SKPaint paint, SKPoint point) { canvas.DrawTextCenteredVertically(text, paint, point.X, point.Y); }