public override void Draw(Canvas canvas) { base.Draw(canvas); paint.Color = Pattern.TextColor.ToAndroid(); paint.TextSize = Android.Util.TypedValue.ApplyDimension(Android.Util.ComplexUnitType.Sp, Pattern.TextSize > 0 ? Pattern.TextSize : 12, Forms.Context.Resources.DisplayMetrics); var bounds = new Rect(); paint.GetTextBounds(Pattern.Text, 0, Pattern.Text.Length, bounds); var al = (int)Pattern.TextAlign; var x = Bounds.Left; if ((al & 2) == 2) // center { x = Bounds.CenterX() - Math.Abs(bounds.CenterX()); } else if ((al & 4) == 4) // right { x = Bounds.Right - bounds.Width(); } var y = Bounds.Top + Math.Abs(bounds.Top); if ((al & 16) == 16) // middle { y = Bounds.CenterY() + Math.Abs(bounds.CenterY()); } else if ((al & 32) == 32) // bottom { y = Bounds.Bottom - Math.Abs(bounds.Bottom); } canvas.DrawText(Pattern.Text.ToCharArray(), 0, Pattern.Text.Length, x, y, paint); }
public override void Draw(GeometryManager geometries) { var primitivesGeo = geometries.Primitives; primitivesGeo.Color = Color.HotPink * (IsFocused ? .2f : .05f); primitivesGeo.DrawRectangle(Bounds.XStart, Bounds.YStart, Bounds.Width, Bounds.Height); var fontGeo = geometries.UIFont; fontGeo.Color = IsFocused ? Color.Yellow : Color.White; fontGeo.Height = fontSize; var pos = new Vector2( Bounds.XStart + Constants.UI.BoxPadding + textAlign * (Bounds.Width - 2 * Constants.UI.BoxPadding), Bounds.CenterY()); fontGeo.DrawString(pos, text, textAlign, .5f); }