Struct RoundRect
A rectangle with an x and y radius per corner. Radii that would overlap are scaled down together, as CSS and Skia do: every radius is multiplied by the smallest ratio of a side's length to the sum of the two radii along it, when that ratio is below 1. A radius below 0 counts as 0, and a corner with either radius 0 is square.
public readonly record struct RoundRect : IEquatable<RoundRect>
- 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
RoundRect(RectF, CornerRadii)
Initializes a new instance of the RoundRect struct.
public RoundRect(RectF bounds, CornerRadii radii)
Parameters
boundsRectFThe rectangle.
radiiCornerRadiiThe corner radii, scaled down when they overlap.
Exceptions
- ArgumentException
A coordinate or radius is not a finite number.
RoundRect(RectF, float)
Initializes a new instance of the RoundRect struct with one circular radius for every corner.
public RoundRect(RectF bounds, float radius)
Parameters
RoundRect(RectF, float, float)
Initializes a new instance of the RoundRect struct with one elliptical radius for every corner.
public RoundRect(RectF bounds, float radiusX, float radiusY)
Parameters
boundsRectFThe rectangle.
radiusXfloatThe x radius of every corner.
radiusYfloatThe y radius of every corner.
Properties
Bounds
Gets the rectangle.
public RectF Bounds { get; }
Property Value
IsEmpty
Gets a value indicating whether the shape covers no area.
public bool IsEmpty { get; }
Property Value
Kind
Gets what the shape reduces to.
public RoundRectKind Kind { get; }
Property Value
Radii
Gets the corner radii, after scaling.
public CornerRadii Radii { get; }
Property Value
Methods
Contains(Vector2)
Returns whether a point lies inside the shape: inside the rectangle and not outside a corner's ellipse.
public bool Contains(Vector2 point)
Parameters
pointVector2The point.
Returns
Inflate(float)
Returns the shape grown by delta on every side, with each radius grown by the same amount (shrunk when negative), as Skia's outset does.
public RoundRect Inflate(float delta)
Parameters
deltafloatThe growth per side.
Returns
- RoundRect
The grown shape.
Offset(Vector2)
Returns the shape moved by an offset.
public RoundRect Offset(Vector2 offset)
Parameters
offsetVector2The distance to move.
Returns
- RoundRect
The moved shape.
Oval(RectF)
Creates the ellipse that fills a rectangle.
public static RoundRect Oval(RectF bounds)
Parameters
boundsRectFThe rectangle.
Returns
- RoundRect
The oval as a round rectangle.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.