Struct egui::Rect[]

pub struct Rect {
    pub min: Pos2,
    pub max: Pos2,
}

A rectangular region of space.

Normally given in points, e.g. logical pixels.

Fields

min: Pos2max: Pos2

Implementations

impl Rect

pub const EVERYTHING: Rect

Infinite rectangle that contains everything.

pub const NOTHING: Rect

The inverse of Self::EVERYTHING: stretches from positive infinity to negative infinity. Contains no points.

This is useful as the seed for bounding bounding boxes.

let inf = f32::INFINITY;
assert!(Rect::NOTHING.size() == Vec2::splat(-inf));
assert!(Rect::NOTHING.contains(pos2(0.0, 0.0)) == false);

Example:

let mut rect = Rect::NOTHING;
rect.extend_with(pos2(2.0, 1.0));
rect.extend_with(pos2(0.0, 3.0));
assert_eq!(rect, Rect::from_min_max(pos2(0.0, 1.0), pos2(2.0, 3.0)))

pub const NAN: Rect

An invalid Rect filled with f32::NAN;

pub fn everything() -> Rect

👎 Deprecated:

Use Rect::EVERYTHING

pub fn nothing() -> Rect

👎 Deprecated:

Use Rect::NOTHING

pub fn invalid() -> Rect

👎 Deprecated:

Use Rect::NAN

pub const fn from_min_max(min: Pos2, max: Pos2) -> Rect

pub fn from_min_size(min: Pos2, size: Vec2) -> Rect

pub fn from_center_size(center: Pos2, size: Vec2) -> Rect

pub fn from_x_y_ranges(
    x_range: RangeInclusive<f32>,
    y_range: RangeInclusive<f32>
) -> Rect

pub fn from_two_pos(a: Pos2, b: Pos2) -> Rect

pub fn everything_right_of(left_x: f32) -> Rect

A Rect that contains every point to the right of the given X coordinate.

pub fn everything_left_of(right_x: f32) -> Rect

A Rect that contains every point to the left of the given X coordinate.

pub fn everything_below(top_y: f32) -> Rect

A Rect that contains every point below a certain y coordinate

pub fn everything_above(bottom_y: f32) -> Rect

A Rect that contains every point above a certain y coordinate

#[must_use]
pub fn expand(self, amnt: f32) -> Rect

Expand by this much in each direction, keeping the center

#[must_use]
pub fn expand2(self, amnt: Vec2) -> Rect

Expand by this much in each direction, keeping the center

#[must_use]
pub fn shrink(self, amnt: f32) -> Rect

Shrink by this much in each direction, keeping the center

#[must_use]
pub fn shrink2(self, amnt: Vec2) -> Rect

Shrink by this much in each direction, keeping the center

#[must_use]
pub fn translate(self, amnt: Vec2) -> Rect

#[must_use]
pub fn intersect(self, other: Rect) -> Rect

The intersection of two Rect, i.e. the area covered by both.

#[must_use]
pub fn intersects(self, other: Rect) -> bool

pub fn set_width(&mut self, w: f32)

keep min

pub fn set_height(&mut self, h: f32)

keep min

pub fn set_center(&mut self, center: Pos2)

Keep size

#[must_use]
pub fn contains(&self, p: Pos2) -> bool

#[must_use]
pub fn clamp(&self, p: Pos2) -> Pos2

Return the given points clamped to be inside the rectangle Panics if Self::is_negative.

pub fn extend_with(&mut self, p: Pos2)

pub fn extend_with_x(&mut self, x: f32)

Expand to include the given x coordinate

pub fn extend_with_y(&mut self, y: f32)

Expand to include the given y coordinate

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

pub fn center(&self) -> Pos2

pub fn size(&self) -> Vec2

pub fn width(&self) -> f32

pub fn height(&self) -> f32

pub fn aspect_ratio(&self) -> f32

Width / height

  • aspect_ratio < 1: portrait / high
  • aspect_ratio = 1: square
  • aspect_ratio > 1: landscape / wide

pub fn square_proportions(&self) -> Vec2

[2, 1] for wide screen, and [1, 2] for portrait, etc. At least one dimension = 1, the other >= 1 Returns the proportions required to letter-box a square view area.

pub fn area(&self) -> f32

pub fn x_range(&self) -> RangeInclusive<f32>

pub fn y_range(&self) -> RangeInclusive<f32>

pub fn bottom_up_range(&self) -> RangeInclusive<f32>

pub fn is_empty(&self) -> bool

👎 Deprecated:

Use is_negative instead

pub fn is_negative(&self) -> bool

width < 0 || height < 0

pub fn is_non_negative(&self) -> bool

👎 Deprecated:

Use !is_negative() instead

pub fn is_positive(&self) -> bool

width > 0 && height > 0

pub fn is_finite(&self) -> bool

True if all members are also finite.

pub fn any_nan(self) -> bool

True if any member is NaN.

impl Rect

pub fn left(&self) -> f32

`min.x

pub fn left_mut(&mut self) -> &mut f32

min.x

pub fn set_left(&mut self, x: f32)

min.x

pub fn right(&self) -> f32

max.x

pub fn right_mut(&mut self) -> &mut f32

max.x

pub fn set_right(&mut self, x: f32)

max.x

pub fn top(&self) -> f32

min.y

pub fn top_mut(&mut self) -> &mut f32

min.y

pub fn set_top(&mut self, y: f32)

min.y

pub fn bottom(&self) -> f32

max.y

pub fn bottom_mut(&mut self) -> &mut f32

max.y

pub fn set_bottom(&mut self, y: f32)

max.y

pub fn left_top(&self) -> Pos2

pub fn center_top(&self) -> Pos2

pub fn right_top(&self) -> Pos2

pub fn left_center(&self) -> Pos2

pub fn right_center(&self) -> Pos2

pub fn left_bottom(&self) -> Pos2

pub fn center_bottom(&self) -> Pos2

pub fn right_bottom(&self) -> Pos2

Trait Implementations

impl Clone for Rect

pub fn clone(&self) -> Rect

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Rect

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

Formats the value using the given formatter. Read more

impl From<[Pos2; 2]> for Rect

from (min, max) or (left top, right bottom)

pub fn from([Pos2; 2]) -> Rect

Performs the conversion.

impl PartialEq<Rect> for Rect

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for !=.

impl Copy for Rect

impl Eq for Rect

impl StructuralEq for Rect

impl StructuralPartialEq for Rect

Auto Trait Implementations

impl RefUnwindSafe for Rect

impl Send for Rect

impl Sync for Rect

impl Unpin for Rect

impl UnwindSafe for Rect

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.