Skip to main content

RRect

Struct RRect 

pub struct RRect(/* private fields */);

Implementations§

§

impl RRect

pub const SIZE_IN_MEMORY: usize

pub fn new() -> RRect

Initializes bounds at (0, 0), the origin, with zero width and height. Initializes corner radii to (0, 0), and sets the type to Type::Empty.

pub fn get_type(&self) -> SkRRect_Type

pub fn is_empty(&self) -> bool

pub fn is_rect(&self) -> bool

pub fn is_oval(&self) -> bool

pub fn is_simple(&self) -> bool

pub fn is_nine_patch(&self) -> bool

pub fn is_complex(&self) -> bool

pub fn width(&self) -> f32

Returns the span on the x-axis. This does not check if the result fits in a 32-bit float; the result may be infinity.

pub fn height(&self) -> f32

Returns the span on the y-axis. This does not check if the result fits in a 32-bit float; the result may be infinity.

pub fn simple_radii(&self) -> Point

Returns the top-left corner radii. If the type is Type::Empty, Type::Rect, Type::Oval, or Type::Simple, returns a value representative of all corner radii. If the type is Type::NinePatch or Type::Complex, at least one of the remaining three corners has a different value.

pub fn set_empty(&mut self)

Sets bounds to zero width and height at (0, 0), the origin. Sets corner radii to zero and sets the type to Type::Empty.

pub fn set_rect(&mut self, rect: impl AsRef<Rect>)

Sets bounds to sorted rect, and sets corner radii to zero. If the set bounds has width and height, sets the type to Type::Rect; otherwise, sets the type to Type::Empty.

  • rect bounds to set

pub fn new_empty() -> RRect

Initializes bounds at (0, 0), the origin, with zero width and height. Initializes corner radii to (0, 0), and sets the type to Type::Empty.

pub fn new_rect(rect: impl AsRef<Rect>) -> RRect

Initializes to a copy of rect bounds and zeroes corner radii.

  • rect bounds to copy

pub fn new_oval(oval: impl AsRef<Rect>) -> RRect

Initializes to an oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height(). If the oval bounds is empty, sets the type to Type::Empty. Otherwise, sets the type to Type::Oval.

  • oval bounds of oval

pub fn new_rect_xy(rect: impl AsRef<Rect>, x_rad: f32, y_rad: f32) -> RRect

Initializes to a rounded rectangle with the same radii for all four corners. If rect is empty, sets the type to Type::Empty. Otherwise, if x_rad and y_rad are zero, sets the type to Type::Rect. Otherwise, if x_rad is at least half rect.width() and y_rad is at least half rect.height(), sets the type to Type::Oval. Otherwise, sets the type to Type::Simple.

  • rect bounds of rounded rectangle
  • x_rad x-axis radius of corners
  • y_rad y-axis radius of corners

pub fn new_rect_radii(rect: impl AsRef<Rect>, radii: &[Point; 4]) -> RRect

Initializes to a rounded rectangle with a radii array for individual control of all four corners.

If rect is empty, sets the type to Type::Empty. Otherwise, if one of each corner radii are zero, sets the type to Type::Rect. 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 the type to Type::Oval. Otherwise, if all x-axis radii are equal, and all y-axis radii are equal, sets the type to Type::Simple. Otherwise, sets the type to Type::NinePatch.

  • rect bounds of rounded rectangle
  • radii corner x-axis and y-axis radii

pub fn new_nine_patch( rect: impl AsRef<Rect>, left_rad: f32, top_rad: f32, right_rad: f32, bottom_rad: f32, ) -> RRect

Initializes bounds to rect. Sets radii to (left_rad, top_rad), (right_rad, top_rad), (right_rad, bottom_rad), (left_rad, bottom_rad).

If rect is empty, sets the type to Type::Empty. Otherwise, if left_rad and right_rad are zero, sets the type to Type::Rect. Otherwise, if top_rad and bottom_rad are zero, sets the type to Type::Rect. Otherwise, if left_rad and right_rad are equal and at least half rect.width(), and top_rad and bottom_rad are equal at least half rect.height(), sets the type to Type::Oval. Otherwise, if left_rad and right_rad are equal, and top_rad and bottom_rad are equal, sets the type to Type::Simple. Otherwise, sets the type to Type::NinePatch.

Nine patch refers to the nine parts defined by the radii: one center rectangle, four edge patches, and four corner patches.

  • rect bounds of rounded rectangle
  • left_rad left-top and left-bottom x-axis radius
  • top_rad left-top and right-top y-axis radius
  • right_rad right-top and right-bottom x-axis radius
  • bottom_rad left-bottom and right-bottom y-axis radius

pub fn set_oval(&mut self, oval: impl AsRef<Rect>)

Sets bounds to oval, x-axis radii to half oval.width(), and all y-axis radii to half oval.height(). If the oval bounds is empty, sets the type to Type::Empty. Otherwise, sets the type to Type::Oval.

  • oval bounds of oval

pub fn set_rect_xy(&mut self, rect: impl AsRef<Rect>, x_rad: f32, y_rad: f32)

Sets to a rounded rectangle with the same radii for all four corners. If rect is empty, sets the type to Type::Empty. Otherwise, if x_rad or y_rad is zero, sets the type to Type::Rect. Otherwise, if x_rad is at least half rect.width() and y_rad is at least half rect.height(), sets the type to Type::Oval. Otherwise, sets the type to Type::Simple.

  • rect bounds of rounded rectangle
  • x_rad x-axis radius of corners
  • y_rad y-axis radius of corners

Example (C++): https://fiddle.skia.org/c/@RRect_setRectXY

pub fn set_nine_patch( &mut self, rect: impl AsRef<Rect>, left_rad: f32, top_rad: f32, right_rad: f32, bottom_rad: f32, )

Sets bounds to rect. Sets radii to (left_rad, top_rad), (right_rad, top_rad), (right_rad, bottom_rad), (left_rad, bottom_rad).

If rect is empty, sets the type to Type::Empty. Otherwise, if left_rad and right_rad are zero, sets the type to Type::Rect. Otherwise, if top_rad and bottom_rad are zero, sets the type to Type::Rect. Otherwise, if left_rad and right_rad are equal and at least half rect.width(), and top_rad and bottom_rad are equal at least half rect.height(), sets the type to Type::Oval. Otherwise, if left_rad and right_rad are equal, and top_rad and bottom_rad are equal, sets the type to Type::Simple. Otherwise, sets the type to Type::NinePatch.

Nine patch refers to the nine parts defined by the radii: one center rectangle, four edge patches, and four corner patches.

  • rect bounds of rounded rectangle
  • left_rad left-top and left-bottom x-axis radius
  • top_rad left-top and right-top y-axis radius
  • right_rad right-top and right-bottom x-axis radius
  • bottom_rad left-bottom and right-bottom y-axis radius

pub fn set_rect_radii(&mut self, rect: impl AsRef<Rect>, radii: &[Point; 4])

Sets bounds to rect. Sets the radii array for individual control of all four corners.

If rect is empty, sets the type to Type::Empty. Otherwise, if one of each corner radii are zero, sets the type to Type::Rect. 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 the type to Type::Oval. Otherwise, if all x-axis radii are equal, and all y-axis radii are equal, sets the type to Type::Simple. Otherwise, sets the type to Type::NinePatch.

  • rect bounds of rounded rectangle
  • radii corner x-axis and y-axis radii

Example (C++): https://fiddle.skia.org/c/@RRect_setRectRadii Example (C++): https://fiddle.skia.org/c/@RRect_setRectRadii

pub fn rect(&self) -> &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 Self::bounds().

pub fn radii(&self, corner: SkRRect_Corner) -> Point

Returns the scalar pair for the radius of the curve on the x-axis and y-axis for one corner. Both radii may be zero. If not zero, both are positive and finite.

  • corner corner to return radii for

pub fn radii_ref(&self) -> &[Point; 4]

Returns the corner radii for all four corners, in the same order as Corner.

pub fn bounds(&self) -> &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 Self::rect().

pub fn inset(&mut self, delta: impl Into<Point>)

Insets bounds by delta, and adjusts radii by delta. delta may be positive, negative, or zero.

If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if the adjusted radius becomes negative, pins the radius to zero. If delta.x exceeds half the bounds width, the bounds left and right are set to the bounds x-axis center. If delta.y exceeds half the bounds height, the bounds top and bottom are set to the bounds y-axis center.

If delta causes the bounds to become infinite, the bounds is zeroed.

Example (C++): https://fiddle.skia.org/c/@RRect_inset

pub fn with_inset(&self, delta: impl Into<Point>) -> RRect

Copies this rounded rectangle to a new one, then insets the new bounds by delta, and adjusts the new radii by delta. delta may be positive, negative, or zero.

If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if the adjusted radius becomes negative, pins the radius to zero. If delta.x exceeds half the new bounds width, the new bounds left and right are set to the new bounds x-axis center. If delta.y exceeds half the new bounds height, the new bounds top and bottom are set to the new bounds y-axis center.

If delta causes the new bounds to become infinite, the new bounds is zeroed.

pub fn outset(&mut self, delta: impl Into<Point>)

Outsets bounds by delta, and adjusts radii by delta. delta may be positive, negative, or zero.

If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if the adjusted radius becomes negative, pins the radius to zero. If delta.x exceeds half the bounds width, the bounds left and right are set to the bounds x-axis center. If delta.y exceeds half the bounds height, the bounds top and bottom are set to the bounds y-axis center.

If delta causes the bounds to become infinite, the bounds is zeroed.

pub fn with_outset(&self, delta: impl Into<Point>) -> RRect

Copies this rounded rectangle to a new one, then outsets the new bounds by delta, and adjusts the new radii by delta. delta may be positive, negative, or zero.

If either corner radius is zero, the corner has no curvature and is unchanged. Otherwise, if the adjusted radius becomes negative, pins the radius to zero. If delta.x exceeds half the new bounds width, the new bounds left and right are set to the new bounds x-axis center. If delta.y exceeds half the new bounds height, the new bounds top and bottom are set to the new bounds y-axis center.

If delta causes the new bounds to become infinite, the new bounds is zeroed.

pub fn offset(&mut self, delta: impl Into<Point>)

Translates this rounded rectangle by delta.

pub fn with_offset(&self, delta: impl Into<Point>) -> RRect

Returns this rounded rectangle translated by delta, with unchanged corner radii.

pub fn contains_point(&self, point: impl Into<Point>) -> bool

Returns true if point is inside the bounds and corner radii, and if this rounded rectangle is not empty.

pub fn contains(&self, rect: impl AsRef<Rect>) -> bool

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

  • rect area tested for containment

Example (C++): https://fiddle.skia.org/c/@RRect_contains

pub fn is_valid(&self) -> bool

Returns true if the bounds and radii values are finite and describe a RRect type that matches Self::get_type(). All RRect methods construct valid types, even if the input values are not valid. Invalid RRect data can only be generated by corrupting memory.

Example (C++): https://fiddle.skia.org/c/@RRect_isValid

pub fn write_to_memory(&self, buffer: &mut Vec<u8>)

Writes this rounded rectangle to buffer. Writes Self::SIZE_IN_MEMORY bytes, and returns Self::SIZE_IN_MEMORY, the number of bytes written.

  • buffer storage for this rounded rectangle

Example (C++): https://fiddle.skia.org/c/@RRect_writeToMemory

pub fn read_from_memory(&mut self, buffer: &[u8]) -> usize

Reads this rounded rectangle from buffer, reading Self::SIZE_IN_MEMORY bytes. Returns Self::SIZE_IN_MEMORY, the bytes read, if buffer.len() is at least Self::SIZE_IN_MEMORY. Otherwise, returns zero.

  • buffer memory to read from

Example (C++): https://fiddle.skia.org/c/@RRect_readFromMemory

pub fn transform(&self, matrix: &Matrix) -> Option<RRect>

Transforms this rounded rectangle by matrix and returns it if possible. If the matrix does not preserve axis-alignment (e.g. rotates, skews, etc.) then this returns None.

pub fn dump(&self, as_hex: impl Into<Option<bool>>)

Writes a text representation of this rounded rectangle to standard output. Set as_hex true to generate exact binary representations of floating point numbers.

  • as_hex true if scalar values are written as hexadecimal

Example (C++): https://fiddle.skia.org/c/@RRect_dump

pub fn dump_to_string(&self, as_hex: bool) -> String

pub fn dump_hex(&self)

Trait Implementations§

§

impl AsRef<RRect> for RRect

§

fn as_ref(&self) -> &RRect

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Clone for RRect

§

fn clone(&self) -> RRect

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Copy for RRect

§

impl Debug for RRect

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for RRect

§

fn default() -> RRect

Returns the “default value” for a type. Read more
§

impl PartialEq for RRect

§

fn eq(&self, rhs: &RRect) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for RRect

§

impl RefUnwindSafe for RRect

§

impl Send for RRect

§

impl Sync for RRect

§

impl Unpin for RRect

§

impl UnsafeUnpin for RRect

§

impl UnwindSafe for RRect

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<N, T> NativeTransmutableWrapper<N> for T
where T: NativeTransmutable<N>,

§

fn wrap(native: N) -> T

§

fn unwrap(self) -> N

§

fn inner(&self) -> &N

§

fn inner_mut(&mut self) -> &mut N

§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more