Struct CornerRadii
The x and y radius of each corner of a RoundRect, clockwise from the top-left. A radius below 0 counts as 0, and a corner with either radius 0 is square.
public readonly record struct CornerRadii : IEquatable<CornerRadii>
- Implements
- Inherited Members
Examples
canvas.FillRect(new RectF(10, 10, 80, 40), Rgba8.Red);
canvas.FillRoundRect(new RoundRect(new RectF(100, 10, 80, 40), 12), new Rgba8(0, 128, 0, 255));
// Each corner can have its own radii; radii that would overlap are scaled down together, as CSS does.
CornerRadii tab = new(topLeft: 16, topRight: 16, bottomRight: 0, bottomLeft: 0);
canvas.FillRoundRect(new RoundRect(new RectF(190, 10, 100, 40), tab), Rgba8.Black);
canvas.FillOval(new RectF(10, 60, 120, 60), new Rgba8(255, 200, 0, 255));
canvas.FillCircle(new Vector2(170, 90), 30, new Rgba8(80, 80, 200, 255));
canvas.FillArc(new RectF(210, 60, 60, 60), startDegrees: -90, sweepDegrees: 120, Rgba8.Red);
canvas.FillRing(new RoundRect(new RectF(10, 130, 60, 60), 30), new RoundRect(new RectF(25, 145, 30, 30), 15), Rgba8.Black);
// The same shapes as paths, to build on or to reuse.
Path hexagon = Path.RegularPolygon(new Vector2(120, 160), 30, sides: 6);
Path star = Path.Star(new Vector2(200, 160), outerRadius: 30, innerRadius: 12, points: 5);
canvas.FillPath(hexagon, new Rgba8(0, 150, 150, 255));
canvas.FillPath(star, new Rgba8(220, 160, 0, 255));
Constructors
CornerRadii(Vector2, Vector2, Vector2, Vector2)
The x and y radius of each corner of a RoundRect, clockwise from the top-left. A radius below 0 counts as 0, and a corner with either radius 0 is square.
public CornerRadii(Vector2 TopLeft, Vector2 TopRight, Vector2 BottomRight, Vector2 BottomLeft)
Parameters
TopLeftVector2The top-left corner's x and y radius.
TopRightVector2The top-right corner's x and y radius.
BottomRightVector2The bottom-right corner's x and y radius.
BottomLeftVector2The bottom-left corner's x and y radius.
Examples
canvas.FillRect(new RectF(10, 10, 80, 40), Rgba8.Red);
canvas.FillRoundRect(new RoundRect(new RectF(100, 10, 80, 40), 12), new Rgba8(0, 128, 0, 255));
// Each corner can have its own radii; radii that would overlap are scaled down together, as CSS does.
CornerRadii tab = new(topLeft: 16, topRight: 16, bottomRight: 0, bottomLeft: 0);
canvas.FillRoundRect(new RoundRect(new RectF(190, 10, 100, 40), tab), Rgba8.Black);
canvas.FillOval(new RectF(10, 60, 120, 60), new Rgba8(255, 200, 0, 255));
canvas.FillCircle(new Vector2(170, 90), 30, new Rgba8(80, 80, 200, 255));
canvas.FillArc(new RectF(210, 60, 60, 60), startDegrees: -90, sweepDegrees: 120, Rgba8.Red);
canvas.FillRing(new RoundRect(new RectF(10, 130, 60, 60), 30), new RoundRect(new RectF(25, 145, 30, 30), 15), Rgba8.Black);
// The same shapes as paths, to build on or to reuse.
Path hexagon = Path.RegularPolygon(new Vector2(120, 160), 30, sides: 6);
Path star = Path.Star(new Vector2(200, 160), outerRadius: 30, innerRadius: 12, points: 5);
canvas.FillPath(hexagon, new Rgba8(0, 150, 150, 255));
canvas.FillPath(star, new Rgba8(220, 160, 0, 255));
CornerRadii(float)
Initializes a new instance of the CornerRadii struct with one circular radius for every corner.
public CornerRadii(float radius)
Parameters
radiusfloatThe radius of every corner.
CornerRadii(float, float)
Initializes a new instance of the CornerRadii struct with one elliptical radius for every corner.
public CornerRadii(float radiusX, float radiusY)
Parameters
CornerRadii(float, float, float, float)
Initializes a new instance of the CornerRadii struct with a circular radius per corner.
public CornerRadii(float topLeft, float topRight, float bottomRight, float bottomLeft)
Parameters
topLeftfloatThe top-left radius.
topRightfloatThe top-right radius.
bottomRightfloatThe bottom-right radius.
bottomLeftfloatThe bottom-left radius.
Properties
BottomLeft
The bottom-left corner's x and y radius.
public Vector2 BottomLeft { get; init; }
Property Value
BottomRight
The bottom-right corner's x and y radius.
public Vector2 BottomRight { get; init; }
Property Value
this[int]
Gets the radii of corner index: 0 top-left, 1 top-right, 2 bottom-right, 3 bottom-left.
public Vector2 this[int index] { get; }
Parameters
indexintThe corner, 0 to 3.
Property Value
- Vector2
The x and y radius.
Exceptions
- ArgumentOutOfRangeException
indexis outside 0 to 3.
TopLeft
The top-left corner's x and y radius.
public Vector2 TopLeft { get; init; }
Property Value
TopRight
The top-right corner's x and y radius.
public Vector2 TopRight { get; init; }
Property Value
Zero
Gets the radii of no corner: a plain rectangle.
public static CornerRadii Zero { get; }