Skip to main content

Rect

Struct Rect 

Source
pub struct Rect {
    pub left: f32,
    pub top: f32,
    pub right: f32,
    pub bottom: f32,
}
Expand description

A rectangle in user coordinates.

Fields§

§left: f32§top: f32§right: f32§bottom: f32

Implementations§

Source§

impl Rect

Source

pub fn new(left: f32, top: f32, right: f32, bottom: f32) -> Rect

Source

pub fn from_size(width: f32, height: f32) -> Rect

Source

pub fn width(&self) -> f32

Source

pub fn height(&self) -> f32

Source

pub fn is_empty(&self) -> bool

Source

pub fn outset(self, reach: f32) -> Rect

The same rectangle, grown by reach on every side.

What a blur needs from the bounds of what it blurs: the result spreads outward, so a target sized to the content alone cuts the halo off square at the edge – the failure looking exactly like a shadow with a straight side. Written once because it was written out twice, four lines at a time, and a third place needs it with one side extended further.

Source

pub fn to_rounded_path(self, radius: f32) -> Path

This rectangle with its corners rounded to radius.

The radius is clamped to half the shorter side. Larger is not an error worth refusing – a caller asking for a fully rounded end usually says so by passing something enormous – and left unclamped the corner arcs would overlap and the outline would cross itself, which fills as something nobody asked for. Clamped, the shape degenerates to a stadium and then a circle, which is what asking for a huge radius means.

A radius at or below zero gives the plain rectangle, so a caller can pass a radius that happens to be zero without special-casing it.

Source

pub fn to_rounded_path_with_radii(self, radii: [[f32; 2]; 4]) -> Path

This rectangle with each corner rounded to its own pair of radii.

The eight numbers dart:ui’s RRect carries, in upstream’s order: top-left, top-right, bottom-left, bottom-right, each an x radius and a y radius. Self::to_rounded_path is this with all four the same and circular, and goes through the same code.

Source

pub fn add_rounded_outline(self, path: &mut PathBuilder, radii: [[f32; 2]; 4])

Add this rectangle’s rounded outline to a path already being built.

Self::to_rounded_path_with_radii is this and nothing else when the path holds one contour. It is public for the case that one cannot serve: a shape made of two of these – the ring drawDRRect fills, or a caller’s own compound outline – needs both contours in one path, and a path built from two paths is not something this crate offers.

The radii are fitted on the way in, so a caller passing radii that overrun a side gets the same scaling drawRRect would apply rather than an outline that crosses itself.

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

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
Source§

impl Copy for Rect

Source§

impl Debug for Rect

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Rect

Source§

fn eq(&self, other: &Rect) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl Freeze for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnsafeUnpin for Rect

§

impl UnwindSafe for Rect

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
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
Source§

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

Source§

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
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

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

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>