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: f64Distance 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: f64Distance 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: f64Distance 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: f64Distance 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
impl RelativeRect
Sourcepub const FILL: RelativeRect
pub const FILL: RelativeRect
A rect that covers the entire container.
Sourcepub const fn from_ltrb(
left: f64,
top: f64,
right: f64,
bottom: f64,
) -> RelativeRect
pub const fn from_ltrb( left: f64, top: f64, right: f64, bottom: f64, ) -> RelativeRect
Creates a RelativeRect with the given values.
Sourcepub fn from_size(rect: Rect, container: Size) -> RelativeRect
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.
Sourcepub fn from_rect(rect: Rect, container: Rect) -> RelativeRect
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.
Sourcepub fn from_directional(
text_direction: TextDirection,
start: f64,
top: f64,
end: f64,
bottom: f64,
) -> RelativeRect
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.
Sourcepub fn has_insets(&self) -> bool
pub fn has_insets(&self) -> bool
Sourcepub fn shift(&self, offset: Offset) -> RelativeRect
pub fn shift(&self, offset: Offset) -> RelativeRect
Returns a new rectangle object translated by the given offset.
Sourcepub fn inflate(&self, delta: f64) -> RelativeRect
pub fn inflate(&self, delta: f64) -> RelativeRect
Returns a new rectangle with edges moved outwards by the given delta.
Sourcepub fn deflate(&self, delta: f64) -> RelativeRect
pub fn deflate(&self, delta: f64) -> RelativeRect
Returns a new rectangle with edges moved inwards by the given delta.
Sourcepub fn intersect(&self, other: RelativeRect) -> RelativeRect
pub fn intersect(&self, other: RelativeRect) -> RelativeRect
Returns a new rectangle that is the intersection of the given rectangle and this one.
Sourcepub fn to_rect(&self, container: Rect) -> Rect
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.
Sourcepub fn to_size(&self, container: Size) -> Size
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.
Sourcepub fn lerp(
a: Option<RelativeRect>,
b: Option<RelativeRect>,
t: f64,
) -> Option<RelativeRect>
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.