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

Corner

Members:

Type

Members:

Methods

MakeEmpty

Initializes bounds at (0, 0), the origin, with zero width and height.

MakeOval

Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height().

MakeRect

Initializes to copy of r bounds and zeroes corner radii.

MakeRectXY

Sets to rounded rectangle with the same radii for all four corners.

__init__

Overloaded function.

contains

Returns true if rect is inside the bounds and corner radii, and if RRect and rect are not empty.

dump

Writes text representation of RRect to standard output.

dumpHex

Writes text representation of RRect to standard output.

dumpToString

getBounds

Returns bounds.

getSimpleRadii

Returns top-left corner radii.

getType

height

Returns span on the y-axis.

inset

Overloaded function.

isComplex

isEmpty

isNinePatch

isOval

isRect

isSimple

isValid

Returns true if bounds and radii values are finite and describe a RRect RRect.Type that matches getType().

makeOffset

Returns RRect translated by (dx, dy).

offset

Translates RRect by (dx, dy).

outset

Overloaded function.

radii

Returns scalar pair for radius of curve on x-axis and y-axis for one corner.

readFromMemory

Reads RRect from buffer, reading kSizeInMemory bytes.

rect

Returns bounds.

setEmpty

Sets bounds to zero width and height at (0, 0), the origin.

setNinePatch

Sets bounds to rect.

setOval

Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height().

setRect

Sets bounds to sorted rect, and sets corner radii to zero.

setRectRadii

Sets bounds to rect.

setRectXY

Sets to rounded rectangle with the same radii for all four corners.

transform

Transforms by RRect by matrix, storing result in dst.

type

width

Returns span on the x-axis.

writeToMemory

Writes RRect to buffer.

Attributes

kComplex_Type

kEmpty_Type

kLastType

kLowerLeft_Corner

kLowerRight_Corner

kNinePatch_Type

kOval_Type

kRect_Type

kSimple_Type

kSizeInMemory

kUpperLeft_Corner

kUpperRight_Corner

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.

  1. __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

  2. __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

  3. __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. If type() 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.

  1. 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

  2. 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 matches getType().

All RRect methods construct valid types, even if the input values are not valid. Invalid RRect 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.

  1. 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

  2. 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 another RRect. Returns false if matrix contains transformations that are not axis aligned.

Asserts in debug builds if RRect equals dst.

Parameters:
  • matrixMatrix specifying the transform

  • dstRRect to store the result

Returns:

true if transformation succeeded.

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>