Struct egui::Rect

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

A rectangular region of space.

Usually a Rect has a positive (or zero) size, and then Self::min <= Self::max. In these cases Self::min is the left-top corner and Self::max is the right-bottom corner.

A rectangle is allowed to have a negative size, which happens when the order of min and max are swapped. These are usually a sign of an error.

Normally the unit is points (logical pixels) in screen space coordinates.

Fields§

§min: Pos2

One of the corners of the rectangle, usually the left top one.

§max: Pos2

The other corner, opposing Self::min. Usually the right bottom one.

Implementations§

Infinite rectangle that contains every point.

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

This is useful as the seed for bounding boxes.

Example:
let mut rect = Rect::NOTHING;
assert!(rect.size() == Vec2::splat(-f32::INFINITY));
assert!(rect.contains(pos2(0.0, 0.0)) == false);
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)))

An invalid Rect filled with f32::NAN;

left-top corner plus a size (stretching right-down).

Returns the bounding rectangle of the two points.

Bounding-box around the points.

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

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

A Rect that contains every point below a certain y coordinate

A Rect that contains every point above a certain y coordinate

Expand by this much in each direction, keeping the center

Expand by this much in each direction, keeping the center

Shrink by this much in each direction, keeping the center

Shrink by this much in each direction, keeping the center

Rotate the bounds (will expand the Rect)

keep min

keep min

Keep size

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

Expand to include the given x coordinate

Expand to include the given y coordinate

The union of two bounding rectangle, i.e. the minimum Rect that contains both input rectangles.

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

Width / height

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

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

The distance from the rect to the position.

The distance is zero when the position is in the interior of the rectangle.

The distance from the rect to the position, squared.

The distance is zero when the position is in the interior of the rectangle.

Signed distance to the edge of the box.

Negative inside the box.

Linearly interpolate so that [0, 0] is Self::min and [1, 1] is Self::max.

width < 0 || height < 0

width > 0 && height > 0

True if all members are also finite.

True if any member is NaN.

min.x

min.x

min.x

max.x

max.x

max.x

min.y

min.y

min.y

max.y

max.y

max.y

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more

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

Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern. Read more
If this function returns true, then it must be valid to reinterpret bits as &Self. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more