SourceClass Rect
from egui import Rectclass Rect:A rectangular region of space.
Usually a Rect has a positive (or zero) size,
and then egui.Rect.min <= egui.Rect.max.
In these cases egui.Rect.min is the left-top corner
and egui.Rect.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.
Rect does NOT implement Default, because there is no obvious default value.
Rect.ZERO may seem reasonable, but when used as a bounding box, Rect.NOTHING
is a better default - so be explicit instead!
Properties§
@property
def max(self, /) -> Pos2§
@max.setter
def max(self, /, max: Pos2) -> None§
@property
def min(self, /) -> Pos2§
@min.setter
def min(self, /, min: Pos2) -> None§
Methods§
Sourcedef any_nan(self, /) -> bool§
True if any member is NaN.
Sourcedef area(self, /) -> float§
This is never negative, and instead returns zero for negative rectangles.
Sourcedef aspect_ratio(self, /) -> float§
Width / height
aspect_ratio < 1: portrait / highaspect_ratio = 1: squareaspect_ratio > 1: landscape / wide
Sourcedef bottom(self, /) -> float§
max.y
Sourcedef bottom_mut(self, /) -> float§
max.y
Sourcedef bottom_up_range(self, /) -> tuple[float, float]§
Sourcedef center(self, /) -> Pos2§
Sourcedef center_bottom(self, /) -> Pos2§
Sourcedef center_top(self, /) -> Pos2§
Sourcedef clamp(self, /, pos: Pos2) -> Pos2§
Return the given points clamped to be inside the rectangle
Panics if egui.Rect.is_negative.
Sourcedef contains(self, /, pos: Pos2) -> bool§
Sourcedef contains_rect(self, /, other: Rect) -> bool§
Sourcedef distance_sq_to_pos(self, /, pos: Pos2) -> float§
The distance from the rect to the position, squared.
The distance is zero when the position is in the interior of the rectangle.
Negative rectangles always return float.INFINITY.
Sourcedef distance_to_pos(self, /, pos: Pos2) -> float§
The distance from the rect to the position.
The distance is zero when the position is in the interior of the rectangle.
Negative rectangles always return float.INFINITY.
Source@staticmethod
def everything_above(bottom_y: float) -> Rect§
A Rect that contains every point above a certain y coordinate
Source@staticmethod
def everything_below(top_y: float) -> Rect§
A Rect that contains every point below a certain y coordinate
Source@staticmethod
def everything_left_of(right_x: float) -> Rect§
A Rect that contains every point to the left of the given X coordinate.
Source@staticmethod
def everything_right_of(left_x: float) -> Rect§
A Rect that contains every point to the right of the given X coordinate.
Sourcedef expand(self, /, amount: float) -> Rect§
Expand by this much in each direction, keeping the center
Sourcedef expand2(self, /, amount: Vec2) -> Rect§
Expand by this much in each direction, keeping the center
Sourcedef extend_with(self, /, pos: Pos2) -> None§
Sourcedef extend_with_x(self, /, x: float) -> None§
Expand to include the given x coordinate
Sourcedef extend_with_y(self, /, y: float) -> None§
Expand to include the given y coordinate
Source@staticmethod
def from_center_size(center: Pos2, size: Vec2) -> Rect§
Source@staticmethod
def from_min_max(min: Pos2, max: Pos2) -> Rect§
Source@staticmethod
def from_min_size(min: Pos2, size: Vec2) -> Rect§
left-top corner plus a size (stretching right-down).
Source@staticmethod
def from_points(points: Sequence[Pos2]) -> Rect§
Bounding-box around the points.
Source@staticmethod
def from_pos(point: Pos2) -> Rect§
A zero-sized rect at a specific point.
Source@staticmethod
def from_two_pos(a: Pos2, b: Pos2) -> Rect§
Returns the bounding rectangle of the two points.
Source@staticmethod
def from_x_y_ranges(min_x: float, max_x: float, min_y: float, max_y: float) -> Rect§
Sourcedef height(self, /) -> float§
Note: this can be negative.
Sourcedef intersect(self, /, other: Rect) -> Rect§
The intersection of two Rect, i.e. the area covered by both.
Sourcedef intersects(self, /, other: Rect) -> bool§
Sourcedef intersects_ray(self, /, origin: Pos2, direction: Vec2) -> bool§
Does this Rect intersect the given ray (where d is normalized)?
A ray that starts inside the rect will return True.
Sourcedef intersects_ray_from_center(self, /, direction: Vec2) -> Pos2§
Where does a ray from the center intersect the rectangle?
d is the direction of the ray and assumed to be normalized.
Sourcedef is_finite(self, /) -> bool§
True if all members are also finite.
Sourcedef is_negative(self, /) -> bool§
width < 0 || height < 0
Sourcedef is_positive(self, /) -> bool§
width > 0 && height > 0
Sourcedef left(self, /) -> float§
min.x
Sourcedef left_bottom(self, /) -> Pos2§
Sourcedef left_center(self, /) -> Pos2§
Sourcedef left_mut(self, /) -> float§
min.x
Sourcedef left_top(self, /) -> Pos2§
Sourcedef lerp_inside(self, /, t: Vec2) -> Pos2§
Linearly interpolate so that [0, 0] is egui.Rect.min and
[1, 1] is egui.Rect.max.
Sourcedef lerp_towards(self, /, other: Rect, t: float) -> Rect§
Linearly self towards other rect.
Sourcedef range_along(self, /, axis: int) -> Rangef§
The extent along the given axis: 0 for x, 1 for y.
Equivalent to egui.Rect.x_range for axis == 0 and egui.Rect.y_range for axis == 1.
Panics
If axis is not 0 or 1.
Sourcedef right(self, /) -> float§
max.x
Sourcedef right_bottom(self, /) -> Pos2§
Sourcedef right_center(self, /) -> Pos2§
Sourcedef right_mut(self, /) -> float§
max.x
Sourcedef right_top(self, /) -> Pos2§
Sourcedef rotate_bb(self, /, angle: float) -> Rect§
Rotate the bounds (will expand the Rect)
def round_to_pixel_center(self, /, pixels_per_point: float) -> Rect§
Sourcedef scale_from_center(self, /, scale_factor: float) -> Rect§
Scale up by this factor in each direction, keeping the center
Sourcedef scale_from_center2(self, /, scale_factor: Vec2) -> Rect§
Scale up by this factor in each direction, keeping the center
Sourcedef set_bottom(self, /, y: float) -> None§
max.y
Sourcedef set_center(self, /, center: Pos2) -> None§
Keep size
Sourcedef set_height(self, /, height: float) -> None§
keep min
Sourcedef set_left(self, /, x: float) -> None§
min.x
Sourcedef set_right(self, /, x: float) -> None§
max.x
Sourcedef set_top(self, /, y: float) -> None§
min.y
Sourcedef set_width(self, /, width: float) -> None§
keep min
Sourcedef shrink(self, /, amount: float) -> Rect§
Shrink by this much in each direction, keeping the center
Sourcedef shrink2(self, /, amount: Vec2) -> Rect§
Shrink by this much in each direction, keeping the center
Sourcedef signed_distance_to_pos(self, /, pos: Pos2) -> float§
Signed distance to the edge of the box.
Negative inside the box.
Negative rectangles always return float.INFINITY.
Sourcedef size(self, /) -> Vec2§
rect.size() == Vec2 { x: rect.width(), y: rect.height() }
Sourcedef size_along(self, /, axis: int) -> float§
The size along the given axis: 0 for x (width), 1 for y (height).
Equivalent to egui.size()[axis](https://github.com/emilk/egui/blob/e44f9f60d93bba451c513b3c193f24bd0260f969/crates/emath/src/rect.rs#L501).
Panics
If axis is not 0 or 1.
Sourcedef split_left_right_at_fraction(self, /, t: float) -> tuple[Rect, Rect]§
Split rectangle in left and right halves. t is expected to be in the (0,1) range.
Sourcedef split_left_right_at_x(self, /, split_x: float) -> tuple[Rect, Rect]§
Split rectangle in left and right halves at the given x coordinate.
Sourcedef split_top_bottom_at_fraction(self, /, t: float) -> tuple[Rect, Rect]§
Split rectangle in top and bottom halves. t is expected to be in the (0,1) range.
Sourcedef split_top_bottom_at_y(self, /, split_y: float) -> tuple[Rect, Rect]§
Split rectangle in top and bottom halves at the given y coordinate.
Sourcedef 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.
Sourcedef top(self, /) -> float§
min.y
Sourcedef top_mut(self, /) -> float§
min.y
Sourcedef translate(self, /, delta: Vec2) -> Rect§
Sourcedef union(self, /, other: Rect) -> Rect§
The union of two bounding rectangle, i.e. the minimum Rect
that contains both input rectangles.
Sourcedef width(self, /) -> float§
Note: this can be negative.