Skip to main content

RelativeRect

Struct RelativeRect 

Source
pub struct RelativeRect {
    pub left: f64,
    pub top: f64,
    pub right: f64,
    pub bottom: f64,
}
Expand description

An immutable 2D, axis-aligned, floating-point rectangle whose coordinates are given relative to another rectangle’s edges, known as the container.

Since the dimensions of the rectangle are relative to those of the container, this type has no width and height members. To determine the width or height of the rectangle, convert it to a Rect using to_rect (passing the container’s own Rect), and then examine that object.

Fields§

§left: f64

Distance from the left side of the container to the left side of this rectangle.

May be negative if the left side of the rectangle is outside of the container.

§top: f64

Distance from the top side of the container to the top side of this rectangle.

May be negative if the top side of the rectangle is outside of the container.

§right: f64

Distance from the right side of the container to the right side of this rectangle.

May be positive if the right side of the rectangle is outside of the container.

§bottom: f64

Distance from the bottom side of the container to the bottom side of this rectangle.

May be positive if the bottom side of the rectangle is outside of the container.

Implementations§

Source§

impl RelativeRect

Source

pub const FILL: RelativeRect

A rect that covers the entire container.

Source

pub const fn from_ltrb( left: f64, top: f64, right: f64, bottom: f64, ) -> RelativeRect

Creates a RelativeRect with the given values.

Source

pub fn from_size(rect: Rect, container: Size) -> RelativeRect

Creates a RelativeRect from a Rect and a Size.

The rect and the RelativeRect (the output) are in the coordinate space of the rectangle described by the size, with 0,0 being at the top left.

Source

pub fn from_rect(rect: Rect, container: Rect) -> RelativeRect

Creates a RelativeRect from two Rects.

container provides the container; rect provides the rectangle, in the same coordinate space, that is to be converted to a RelativeRect. The output will be in the container’s coordinate space.

For example, if the top left of the rect is at 0,0, and the top left of the container is at 100,100, then the top left of the output will be at -100,-100.

If rect is actually in the container’s coordinate space, then use from_size and pass the container’s size as the second argument instead.

Source

pub fn from_directional( text_direction: TextDirection, start: f64, top: f64, end: f64, bottom: f64, ) -> RelativeRect

Creates a RelativeRect from horizontal position using start and end rather than left and right.

If text_direction is TextDirection::Rtl, then start is used for the right property and end for the left property. Otherwise, start is used for left and end for right.

Source

pub fn has_insets(&self) -> bool

Returns whether any of the values are greater than zero.

This corresponds to one of the sides (left, top, right, or bottom) having some positive inset towards the center.

Source

pub fn shift(&self, offset: Offset) -> RelativeRect

Returns a new rectangle object translated by the given offset.

Source

pub fn inflate(&self, delta: f64) -> RelativeRect

Returns a new rectangle with edges moved outwards by the given delta.

Source

pub fn deflate(&self, delta: f64) -> RelativeRect

Returns a new rectangle with edges moved inwards by the given delta.

Source

pub fn intersect(&self, other: RelativeRect) -> RelativeRect

Returns a new rectangle that is the intersection of the given rectangle and this one.

Source

pub fn to_rect(&self, container: Rect) -> Rect

Convert this RelativeRect to a Rect, in the coordinate space of the container.

See also:

  • to_size, which returns the size part of the rect, based on the size of the container.
Source

pub fn to_size(&self, container: Size) -> Size

Convert this RelativeRect to a Size, assuming a container with the given size.

See also:

  • to_rect, which also computes the position relative to the container.
Source

pub fn lerp( a: Option<RelativeRect>, b: Option<RelativeRect>, t: f64, ) -> Option<RelativeRect>

Linearly interpolate between two RelativeRects.

If either rect is None, this function interpolates from FILL.

Trait Implementations§

Source§

impl Clone for RelativeRect

Source§

fn clone(&self) -> Self

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 RelativeRect

Source§

impl Debug for RelativeRect

Source§

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

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

impl PartialEq for RelativeRect

Source§

fn eq(&self, other: &Self) -> 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 RelativeRect

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,