RRect
- class RRect
RRect
describes a rounded rectangle with a bounds and a pair of radii for each corner.The bounds and radii can be set so that
RRect
describes: a rectangle with sharp corners; a circle; an oval; or a rectangle with one or more rounded corners.RRect
allows implementing CSS properties that describe rounded corners.RRect
may have up to eight different radii, one for each axis on each of its four corners.RRect
may modify the provided parameters when initializing bounds and radii. If either axis radii is zero or less: radii are stored as zero; corner is square. If corner curves overlap, radii are proportionally reduced to fit within bounds.Classes
Members:
Members:
Methods
Initializes bounds at (0, 0), the origin, with zero width and height.
Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height().
Initializes to copy of r bounds and zeroes corner radii.
Sets to rounded rectangle with the same radii for all four corners.
Overloaded function.
Returns true if rect is inside the bounds and corner radii, and if
RRect
and rect are not empty.Writes text representation of
RRect
to standard output.Writes text representation of
RRect
to standard output.Returns bounds.
Returns top-left corner radii.
Returns span on the y-axis.
Overloaded function.
Returns true if bounds and radii values are finite and describe a
RRect
RRect.Type
that matchesgetType()
.Returns
RRect
translated by (dx, dy).Translates
RRect
by (dx, dy).Overloaded function.
Returns scalar pair for radius of curve on x-axis and y-axis for one corner.
Reads
RRect
from buffer, reading kSizeInMemory bytes.Returns bounds.
Sets bounds to zero width and height at (0, 0), the origin.
Sets bounds to rect.
Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height().
Sets bounds to sorted rect, and sets corner radii to zero.
Sets bounds to rect.
Sets to rounded rectangle with the same radii for all four corners.
Transforms by
RRect
by matrix, storing result in dst.Returns span on the x-axis.
Writes
RRect
to buffer.Attributes
Methods
- static RRect.MakeEmpty() skia.RRect
Initializes bounds at (0, 0), the origin, with zero width and height.
Initializes corner radii to (0, 0), and sets type of kEmpty_Type.
- Returns:
empty
RRect
- static RRect.MakeOval(oval: skia.Rect) skia.RRect
Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height().
If oval bounds is empty, sets to kEmpty_Type. Otherwise, sets to kOval_Type.
- Parameters:
oval – bounds of oval
- Returns:
oval
- static RRect.MakeRect(r: skia.Rect) skia.RRect
Initializes to copy of r bounds and zeroes corner radii.
- Parameters:
r – bounds to copy
- Returns:
copy of r
- static RRect.MakeRectXY(rect: skia.Rect, xRad: float, yRad: float) skia.RRect
Sets to rounded rectangle with the same radii for all four corners.
If rect is empty, sets to kEmpty_Type. Otherwise, if xRad and yRad are zero, sets to kRect_Type. Otherwise, if xRad is at least half rect.width() and yRad is at least half rect.height(), sets to kOval_Type. Otherwise, sets to kSimple_Type.
- Parameters:
rect – bounds of rounded rectangle
xRad – x-axis radius of corners
yRad – y-axis radius of corners
- Returns:
rounded rectangle
- RRect.__init__(*args, **kwargs)
Overloaded function.
__init__(self: skia.RRect) -> None
Initializes bounds at (0, 0), the origin, with zero width and height.
Initializes corner radii to (0, 0), and sets type of kEmpty_Type.
- return:
empty
RRect
__init__(self: skia.RRect, rrect: skia.RRect) -> None
Initializes to copy of rrect bounds and corner radii.
- rrect:
bounds and corner to copy
- return:
copy of rrect
__init__(self: skia.RRect, rect: skia.Rect, xRad: float, yRad: float) -> None
Initializes to rounded rectangle with the same radii for all four corners.
If rect is empty, sets to kEmpty_Type. Otherwise, if xRad and yRad are zero, sets to kRect_Type. Otherwise, if xRad is at least half rect.width() and yRad is at least half rect.height(), sets to kOval_Type. Otherwise, sets to kSimple_Type.
- rect:
bounds of rounded rectangle
- xRad:
x-axis radius of corners
- yRad:
y-axis radius of corners
- return:
rounded rectangle
- RRect.contains(self: skia.RRect, rect: skia.Rect) bool
Returns true if rect is inside the bounds and corner radii, and if
RRect
and rect are not empty.- Parameters:
rect – area tested for containment
- Returns:
true if SkRRect contains rect
- RRect.dump(self: skia.RRect, asHex: bool = False) None
Writes text representation of
RRect
to standard output.Set asHex true to generate exact binary representations of floating point numbers.
- Parameters:
asHex – true if Scalar values are written as hexadecimal
- RRect.dumpHex(self: skia.RRect) None
Writes text representation of
RRect
to standard output.The representation may be directly compiled as C++ code. Floating point values are written in hexadecimal to preserve their exact bit pattern. The output reconstructs the original
RRect
.
- RRect.dumpToString(self: skia.RRect, asHex: bool) SkString
- RRect.getBounds(self: skia.RRect) skia.Rect
Returns bounds.
Bounds may have zero width or zero height. Bounds right is greater than or equal to left; bounds bottom is greater than or equal to top. Result is identical to
rect()
.- Returns:
bounding box
- RRect.getSimpleRadii(self: skia.RRect) skia.Point
Returns top-left corner radii.
If
type()
returns kEmpty_Type, kRect_Type, kOval_Type, or kSimple_Type, returns a value representative of all corner radii. Iftype()
returns kNinePatch_Type or kComplex_Type, at least one of the remaining three corners has a different value.- Returns:
corner radii for simple types
- RRect.getType(self: skia.RRect) skia.RRect.Type
- RRect.height(self: skia.RRect) float
Returns span on the y-axis.
This does not check if result fits in 32-bit float; result may be infinity.
- Returns:
rect().fBottom minus rect().fTop
- RRect.inset(*args, **kwargs)
Overloaded function.
inset(self: skia.RRect, dx: float, dy: float, dst: skia.RRect) -> None
Copies
RRect
to dst, then insets dst bounds by dx and dy, and adjusts dst radii by dx and dy.dx and dy may be positive, negative, or zero. dst may be
RRect
.If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if adjusted radius becomes negative, pins radius to zero. If dx exceeds half dst bounds width, dst bounds left and right are set to bounds x-axis center. If dy exceeds half dst bounds height, dst bounds top and bottom are set to bounds y-axis center.
If dx or dy cause the bounds to become infinite, dst bounds is zeroed.
- dx:
added to rect().fLeft, and subtracted from rect().fRight
- dy:
added to rect().fTop, and subtracted from rect().fBottom
- dst:
insets bounds and radii
inset(self: skia.RRect, dx: float, dy: float) -> None
Insets bounds by dx and dy, and adjusts radii by dx and dy.
dx and dy may be positive, negative, or zero.
If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if adjusted radius becomes negative, pins radius to zero. If dx exceeds half bounds width, bounds left and right are set to bounds x-axis center. If dy exceeds half bounds height, bounds top and bottom are set to bounds y-axis center.
If dx or dy cause the bounds to become infinite, bounds is zeroed.
- dx:
added to rect().fLeft, and subtracted from rect().fRight
- dy:
added to rect().fTop, and subtracted from rect().fBottom
- RRect.isComplex(self: skia.RRect) bool
- RRect.isEmpty(self: skia.RRect) bool
- RRect.isNinePatch(self: skia.RRect) bool
- RRect.isOval(self: skia.RRect) bool
- RRect.isRect(self: skia.RRect) bool
- RRect.isSimple(self: skia.RRect) bool
- RRect.isValid(self: skia.RRect) bool
Returns true if bounds and radii values are finite and describe a
RRect
RRect.Type
that matchesgetType()
.All
RRect
methods construct valid types, even if the input values are not valid. InvalidRRect
data can only be generated by corrupting memory.- Returns:
true if bounds and radii match
type()
- RRect.makeOffset(self: skia.RRect, dx: float, dy: float) skia.RRect
Returns
RRect
translated by (dx, dy).- Parameters:
dx – offset added to rect().fLeft and rect().fRight
dy – offset added to rect().fTop and rect().fBottom
- Returns:
RRect
bounds offset by (dx, dy), with unchanged corner radii
- RRect.offset(self: skia.RRect, dx: float, dy: float) None
Translates
RRect
by (dx, dy).- Parameters:
dx – offset added to rect().fLeft and rect().fRight
- Parma dy:
offset added to rect().fTop and rect().fBottom
- RRect.outset(*args, **kwargs)
Overloaded function.
outset(self: skia.RRect, dx: float, dy: float, dst: skia.RRect) -> None
Outsets dst bounds by dx and dy, and adjusts radii by dx and dy.
dx and dy may be positive, negative, or zero.
If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if adjusted radius becomes negative, pins radius to zero. If dx exceeds half dst bounds width, dst bounds left and right are set to bounds x-axis center. If dy exceeds half dst bounds height, dst bounds top and bottom are set to bounds y-axis center.
If dx or dy cause the bounds to become infinite, dst bounds is zeroed.
- dx:
subtracted from rect().fLeft, and added to rect().fRight
- dy:
subtracted from rect().fTop, and added to rect().fBottom
- dst:
outset bounds and radii
outset(self: skia.RRect, dx: float, dy: float) -> None
Outsets bounds by dx and dy, and adjusts radii by dx and dy.
dx and dy may be positive, negative, or zero.
If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if adjusted radius becomes negative, pins radius to zero. If dx exceeds half bounds width, bounds left and right are set to bounds x-axis center. If dy exceeds half bounds height, bounds top and bottom are set to bounds y-axis center.
If dx or dy cause the bounds to become infinite, bounds is zeroed.
- dx:
subtracted from rect().fLeft, and added to rect().fRight
- dy:
subtracted from rect().fTop, and added to rect().fBottom
- RRect.radii(self: skia.RRect, corner: skia.RRect.Corner) skia.Point
Returns scalar pair for radius of curve on x-axis and y-axis for one corner.
Both radii may be zero. If not zero, both are positive and finite.
- Returns:
x-axis and y-axis radii for one corner
- RRect.readFromMemory(self: skia.RRect, buffer: str) int
Reads
RRect
from buffer, reading kSizeInMemory bytes.Returns kSizeInMemory, bytes read if length is at least kSizeInMemory. Otherwise, returns zero.
- Parameters:
buffer – memory to read from
- Returns:
bytes read, or 0 if length is less than kSizeInMemory
- RRect.rect(self: skia.RRect) skia.Rect
Returns bounds.
Bounds may have zero width or zero height. Bounds right is greater than or equal to left; bounds bottom is greater than or equal to top. Result is identical to
getBounds()
.- Returns:
bounding box
- RRect.setEmpty(self: skia.RRect) None
Sets bounds to zero width and height at (0, 0), the origin.
Sets corner radii to zero and sets type to kEmpty_Type.
- RRect.setNinePatch(self: skia.RRect, rect: skia.Rect, leftRad: float, topRad: float, rightRad: float, bottomRad: float) None
Sets bounds to rect.
Sets radii to (leftRad, topRad), (rightRad, topRad), (rightRad, bottomRad), (leftRad, bottomRad).
If rect is empty, sets to kEmpty_Type. Otherwise, if leftRad and rightRad are zero, sets to kRect_Type. Otherwise, if topRad and bottomRad are zero, sets to kRect_Type. Otherwise, if leftRad and rightRad are equal and at least half rect.width(), and topRad and bottomRad are equal at least half rect.height(), sets to kOval_Type. Otherwise, if leftRad and rightRad are equal, and topRad and bottomRad are equal, sets to kSimple_Type. Otherwise, sets to kNinePatch_Type.
Nine patch refers to the nine parts defined by the radii: one center rectangle, four edge patches, and four corner patches.
- Parameters:
rect – bounds of rounded rectangle
leftRad – left-top and left-bottom x-axis radius
topRad – left-top and right-top y-axis radius
rightRad – right-top and right-bottom x-axis radius
bottomRad – left-bottom and right-bottom y-axis radius
- RRect.setOval(self: skia.RRect, oval: skia.Rect) None
Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height().
If oval bounds is empty, sets to kEmpty_Type. Otherwise, sets to kOval_Type.
- Parameters:
oval – bounds of oval
- RRect.setRect(self: skia.RRect, rect: skia.Rect) None
Sets bounds to sorted rect, and sets corner radii to zero.
If set bounds has width and height, and sets type to kRect_Type; otherwise, sets type to kEmpty_Type.
- Parameters:
rect – bounds to set
- RRect.setRectRadii(self: skia.RRect, rect: skia.Rect, radii: list[skia.Point]) None
Sets bounds to rect.
Sets radii array for individual control of all for corners.
If rect is empty, sets to kEmpty_Type. Otherwise, if one of each corner radii are zero, sets to kRect_Type. Otherwise, if all x-axis radii are equal and at least half rect.width(), and all y-axis radii are equal at least half rect.height(), sets to kOval_Type. Otherwise, if all x-axis radii are equal, and all y-axis radii are equal, sets to kSimple_Type. Otherwise, sets to kNinePatch_Type.
- Parameters:
rect – bounds of rounded rectangle
radii – corner x-axis and y-axis radii
- RRect.setRectXY(self: skia.RRect, rect: skia.Rect, xRad: float, yRad: float) None
Sets to rounded rectangle with the same radii for all four corners.
If rect is empty, sets to kEmpty_Type. Otherwise, if xRad or yRad is zero, sets to kRect_Type. Otherwise, if xRad is at least half rect.width() and yRad is at least half rect.height(), sets to kOval_Type. Otherwise, sets to kSimple_Type.
- Parameters:
rect – bounds of rounded rectangle
xRad – x-axis radius of corners
yRad – y-axis radius of corners
- RRect.transform(self: skia.RRect, matrix: SkMatrix, dst: skia.RRect) bool
Transforms by
RRect
by matrix, storing result in dst.Returns true if
RRect
transformed can be represented by anotherRRect
. Returns false if matrix contains transformations that are not axis aligned.Asserts in debug builds if
RRect
equals dst.
- RRect.type(self: skia.RRect) skia.RRect.Type
- RRect.width(self: skia.RRect) float
Returns span on the x-axis.
This does not check if result fits in 32-bit float; result may be infinity.
- Returns:
rect().fRight minus rect().fLeft
- RRect.writeToMemory(self: skia.RRect) bytes
Writes
RRect
to buffer.Writes kSizeInMemory bytes, and returns kSizeInMemory, the number of bytes written.
- Returns:
bytes written, kSizeInMemory
Attributes
- RRect.kComplex_Type = <Type.kComplex_Type: 5>
- RRect.kEmpty_Type = <Type.kEmpty_Type: 0>
- RRect.kLastType = <Type.kComplex_Type: 5>
- RRect.kLowerLeft_Corner = <Corner.kLowerLeft_Corner: 3>
- RRect.kLowerRight_Corner = <Corner.kLowerRight_Corner: 2>
- RRect.kNinePatch_Type = <Type.kNinePatch_Type: 4>
- RRect.kOval_Type = <Type.kOval_Type: 2>
- RRect.kRect_Type = <Type.kRect_Type: 1>
- RRect.kSimple_Type = <Type.kSimple_Type: 3>
- RRect.kSizeInMemory = 48
- RRect.kUpperLeft_Corner = <Corner.kUpperLeft_Corner: 0>
- RRect.kUpperRight_Corner = <Corner.kUpperRight_Corner: 1>