Skip to main content

Rect

Struct Rect 

Source
pub struct Rect {
    pub x: f32,
    pub y: f32,
    pub width: f32,
    pub height: f32,
}
Expand description

An axis-aligned rectangle, in logical pixels.

Fields§

§x: f32

Left edge.

§y: f32

Top edge.

§width: f32

Width, extending to the right.

§height: f32

Height, extending downwards.

Implementations§

Source§

impl Rect

Source

pub const UNBOUNDED: Rect

An “infinite” rectangle, used as a neutral clip that clips nothing.

Source

pub const fn new(x: f32, y: f32, width: f32, height: f32) -> Rect

Builds a rectangle from its position (top-left corner) and its size.

Source

pub fn translate(self, dx: f32, dy: f32) -> Rect

Offsets the rectangle by (dx, dy).

Source

pub fn scale(self, factor: f32) -> Rect

Multiplies position and size by factor (logical → physical conversion).

Source

pub fn scale_about(self, pivot: Point, factor: f32) -> Rect

Scales the rectangle by factor about pivot, which stays fixed: pos' = pivot + (pos - pivot) * factor, with size × factor.

Source

pub fn scale_about_xy(self, pivot: Point, sx: f32, sy: f32) -> Rect

Scales the rectangle per axis about pivot.

Source

pub fn scale_xy(self, sx: f32, sy: f32) -> Rect

Multiplies position and size per axis (sx, sy).

Source

pub fn intersect(self, other: Rect) -> Rect

The intersection of two rectangles; zero-sized when they are disjoint.

Source

pub fn union(self, other: Rect) -> Rect

The smallest rectangle enclosing both self and other.

Source

pub fn contains(self, point: Point) -> bool

true when point lies inside; the left and top edges count as inside.

Source

pub const fn from_point_size(origin: Point, size: Size) -> Rect

Builds a rectangle from an origin point and a size.

Source

pub const fn origin(self) -> Point

The top-left corner.

Source

pub const fn size(self) -> Size

The rectangle’s size.

Source

pub const fn to_array(self) -> [f32; 4]

The [x, y, width, height] form, ready for the GPU.

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<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> 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<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> MaybeSend for T
where T: Send,

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.