Struct Rectangle

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

A rectangle

Fields§

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

Implementations§

Source§

impl Rectangle

Source

pub fn to_device_coordinates(self, viewport: Rectangle) -> Rectangle

Convert a rectangle to device coordinates ([-1.0, 1.0]) using a Viewport. (-1, -1) is the top left corner (0, 0), where (1, 1) is the bottom right corner (viewport.width(), viewport.height()).

Source

pub fn zero() -> Rectangle

Return a zero size rectangle

Source

pub fn from_wh(w: f32, h: f32) -> Rectangle

Construct a new rectangle with (0, 0) as (left, top), and w, h as (right, bottom)

Source

pub fn from_xywh(x: f32, y: f32, w: f32, h: f32) -> Rectangle

Construct a new rectangle from a position and a size

Source

pub fn point_inside(&self, x: f32, y: f32) -> bool

Returns true when the queried point is inside the rectangle

Source

pub fn intersect(&self, other: &Rectangle) -> Option<Rectangle>

Returns the rectangle that is covered both by self and other. None is returned if the rectangles do not overlap.

Source

pub fn pt(&self, x: f32, y: f32) -> [f32; 2]

Return a point within this rectangle. The point should be in [0, 1] range.

Source

pub fn round(self) -> Rectangle

Return a rectangle with all fields rounded

Source

pub fn translate(&self, x: f32, y: f32) -> Rectangle

Apply a translation the the rectangle

Source

pub fn grow(&self, w: f32, h: f32) -> Rectangle

Increase the size of the rectangle on the right and bottom side.

Source

pub fn inset(&self, x: f32, y: f32) -> Option<Rectangle>

Decrease the size of the rectangle on all sides

Source

pub fn outset(&self, x: f32, y: f32) -> Rectangle

Grow the rectangle on all sides

Source

pub fn size(&self) -> Rectangle

Return a rectangle with the same size, but positioned at the origin

Source

pub fn width(&self) -> f32

The width of the rectangle

Source

pub fn height(&self) -> f32

The height of the rectangle

Source

pub fn after_margin(self, margin: Rectangle) -> Rectangle

Apply a margin to the rectangle

Source

pub fn after_padding(self, padding: Rectangle) -> Rectangle

Apply padding to the rectangle

Source

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

Return the smallest rectangle that covers both self and other

Trait Implementations§

Source§

impl Clone for Rectangle

Source§

fn clone(&self) -> Rectangle

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Rectangle

Source§

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

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

impl From<[f32; 4]> for Rectangle

Source§

fn from(a: [f32; 4]) -> Rectangle

Converts to this type from the input type.
Source§

impl Copy for Rectangle

Auto Trait Implementations§

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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>

Source§

impl<T> DragDropId for T
where T: 'static + Copy + Send + Sync,