|
|
|
@ -15,7 +15,8 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(Text),
|
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
"something");
|
|
|
|
|
"something",
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
@ -27,7 +28,9 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(Fill),
|
|
|
|
|
typeof(Color),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
Colors.DarkSalmon);
|
|
|
|
|
Colors.DarkSalmon,
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Color Fill
|
|
|
|
|
{
|
|
|
|
@ -39,7 +42,8 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(Stroke),
|
|
|
|
|
typeof(Color),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
Colors.DarkSalmon);
|
|
|
|
|
Colors.DarkSalmon,
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
public Color Stroke
|
|
|
|
|
{
|
|
|
|
@ -51,7 +55,8 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(StrokeWidth),
|
|
|
|
|
typeof(float),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
1.0f);
|
|
|
|
|
1.0f,
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
public float StrokeWidth
|
|
|
|
|
{
|
|
|
|
@ -63,7 +68,8 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(FontFamily),
|
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
"something");
|
|
|
|
|
"something",
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
public string FontFamily
|
|
|
|
|
{
|
|
|
|
@ -75,7 +81,8 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(TextSize),
|
|
|
|
|
typeof(float),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
24.0f);
|
|
|
|
|
24.0f,
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
public float TextSize
|
|
|
|
|
{
|
|
|
|
@ -87,7 +94,8 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(Aspect),
|
|
|
|
|
typeof(Aspect),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
Aspect.Center);
|
|
|
|
|
Aspect.Center,
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
public Aspect Aspect
|
|
|
|
|
{
|
|
|
|
@ -99,7 +107,8 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
= BindableProperty.Create(nameof(Ratio),
|
|
|
|
|
typeof(float),
|
|
|
|
|
typeof(LabelOutline),
|
|
|
|
|
0.95f);
|
|
|
|
|
0.95f,
|
|
|
|
|
propertyChanged: (b, ov, nv) => (b as LabelOutline)?.canvasView.InvalidateSurface());
|
|
|
|
|
|
|
|
|
|
public float Ratio
|
|
|
|
|
{
|
|
|
|
@ -110,13 +119,10 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
private void OnPainting(object sender, SKPaintSurfaceEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
SKImageInfo info = args.Info;
|
|
|
|
|
SKSurface surface = args.Surface;
|
|
|
|
|
SKCanvas canvas = surface.Canvas;
|
|
|
|
|
SKCanvas canvas = args.Surface.Canvas;
|
|
|
|
|
|
|
|
|
|
canvas.Clear();
|
|
|
|
|
|
|
|
|
|
string text = Text;
|
|
|
|
|
|
|
|
|
|
// Create an SKPaint object to display the text
|
|
|
|
|
SKPaint textPaint = new SKPaint
|
|
|
|
|
{
|
|
|
|
@ -132,39 +138,37 @@ public partial class LabelOutline : ContentView
|
|
|
|
|
{
|
|
|
|
|
case Aspect.AspectFit:
|
|
|
|
|
float textHeight = Ratio * info.Height;
|
|
|
|
|
float textWidth2 = textPaint.MeasureText(text);
|
|
|
|
|
float textWidth2 = textPaint.MeasureText(Text);
|
|
|
|
|
textWidth2 = Ratio * info.Width * textPaint.TextSize / textWidth2;
|
|
|
|
|
textPaint.TextSize = Math.Min(textHeight, textWidth2);
|
|
|
|
|
Console.WriteLine($"info.Width: {info.Width} ; info.Height: {info.Height} ; textPaint.TextSize: {textPaint.TextSize} ; textHeight: {textHeight} ; textWidth: {textWidth2}");
|
|
|
|
|
break;
|
|
|
|
|
case Aspect.AspectFill:
|
|
|
|
|
case Aspect.Fill:
|
|
|
|
|
float textWidth = textPaint.MeasureText(text);
|
|
|
|
|
float textWidth = textPaint.MeasureText(Text);
|
|
|
|
|
textPaint.TextSize = Ratio * info.Width * textPaint.TextSize / textWidth;
|
|
|
|
|
Console.WriteLine($"info.Width: {info.Width} ; info.Height: {info.Height} ; textPaint.TextSize: {textPaint.TextSize}");
|
|
|
|
|
break;
|
|
|
|
|
case Aspect.Center:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Adjust TextSize property so text is 95% of screen width
|
|
|
|
|
// float textWidth = textPaint.MeasureText(text);
|
|
|
|
|
// textPaint.TextSize = 0.95f * info.Width * textPaint.TextSize / textWidth;
|
|
|
|
|
|
|
|
|
|
// Find the text bounds
|
|
|
|
|
SKRect textBounds = new SKRect();
|
|
|
|
|
textPaint.MeasureText(text, ref textBounds);
|
|
|
|
|
textPaint.MeasureText(Text, ref textBounds);
|
|
|
|
|
|
|
|
|
|
// Calculate offsets to center the text on the screen
|
|
|
|
|
float xText = info.Width / 2 - textBounds.MidX;
|
|
|
|
|
float yText = info.Height / 2 - textBounds.MidY;
|
|
|
|
|
|
|
|
|
|
// And draw the text
|
|
|
|
|
canvas.DrawText(text, xText, yText, textPaint);
|
|
|
|
|
canvas.DrawText(Text, xText, yText, textPaint);
|
|
|
|
|
|
|
|
|
|
textPaint.Style = SKPaintStyle.Stroke;
|
|
|
|
|
textPaint.Color = Stroke.ToSKColor();
|
|
|
|
|
if(StrokeWidth > 0.0f)
|
|
|
|
|
{
|
|
|
|
|
textPaint.Style = SKPaintStyle.Stroke;
|
|
|
|
|
textPaint.Color = Stroke.ToSKColor();
|
|
|
|
|
|
|
|
|
|
canvas.DrawText(text, xText, yText, textPaint);
|
|
|
|
|
canvas.DrawText(Text, xText, yText, textPaint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|