-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Rectangle.cs
77 lines (65 loc) · 2.56 KB
/
Rectangle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#nullable disable
using System;
using System.Runtime.CompilerServices;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Controls.Shapes
{
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Rectangle.xml" path="Type[@FullName='Microsoft.Maui.Controls.Shapes.Rectangle']/Docs/*" />
public sealed partial class Rectangle : Shape, IShape
{
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Rectangle.xml" path="//Member[@MemberName='.ctor']/Docs/*" />
public Rectangle() : base()
{
Aspect = Stretch.Fill;
}
/// <summary>Bindable property for <see cref="RadiusX"/>.</summary>
public static readonly BindableProperty RadiusXProperty =
BindableProperty.Create(nameof(RadiusX), typeof(double), typeof(Rectangle), 0.0d);
/// <summary>Bindable property for <see cref="RadiusY"/>.</summary>
public static readonly BindableProperty RadiusYProperty =
BindableProperty.Create(nameof(RadiusY), typeof(double), typeof(Rectangle), 0.0d);
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Rectangle.xml" path="//Member[@MemberName='RadiusX']/Docs/*" />
public double RadiusX
{
set { SetValue(RadiusXProperty, value); }
get { return (double)GetValue(RadiusXProperty); }
}
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/Rectangle.xml" path="//Member[@MemberName='RadiusY']/Docs/*" />
public double RadiusY
{
set { SetValue(RadiusYProperty, value); }
get { return (double)GetValue(RadiusYProperty); }
}
// TODO this should move to a remapped mapper
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (propertyName == RadiusXProperty.PropertyName ||
propertyName == RadiusYProperty.PropertyName)
Handler?.UpdateValue(nameof(IShapeView.Shape));
}
public override PathF GetPath()
{
var width = WidthForPathComputation;
var height = HeightForPathComputation;
var path = new PathF();
float x = (float)StrokeThickness / 2;
float y = (float)StrokeThickness / 2;
float w = (float)(width - StrokeThickness);
float h = (float)(height - StrokeThickness);
float cornerRadius = (float)Math.Max(RadiusX, RadiusY);
// TODO: Create specific Path taking into account RadiusX and RadiusY
if (cornerRadius == 0)
{
// AppendRoundedRectangle will slash the corners even for cornerRadius = 0
// so in that case we use AppendRectangle instead
path.AppendRectangle(x, y, w, h);
}
else
{
path.AppendRoundedRectangle(x, y, w, h, cornerRadius);
}
return path;
}
}
}