pub struct Rect {
pub x: i32,
pub y: i32,
pub width: u32,
pub height: u32,
}
Expand description
A rectangle in 2D space.
Fields§
§x: i32
§y: i32
§width: u32
§height: u32
Implementations§
source§impl Rect
impl Rect
sourcepub fn new(x: i32, y: i32, width: u32, height: u32) -> Self
pub fn new(x: i32, y: i32, width: u32, height: u32) -> Self
Creates a new rectangle with the given position and dimensions.
sourcepub fn from_points(p1: Point, p2: Point) -> Self
pub fn from_points(p1: Point, p2: Point) -> Self
Creates a new rectangle from two points.
The points do not need to be in any particular order. The rectangle will be the smallest rectangle that contains both points. If the points are the same, the rectangle will have zero width and height. If the points are on the same vertical or horizontal line, the rectangle will have zero width or height respectively.
Arguments
p1
- The first point.p2
- The second point.
Returns
A new rectangle that contains both points.
sourcepub fn from_point_and_size(p: Point, width: u32, height: u32) -> Self
pub fn from_point_and_size(p: Point, width: u32, height: u32) -> Self
sourcepub fn clip_within(&self, width: u32, height: u32) -> (Self, Point)
pub fn clip_within(&self, width: u32, height: u32) -> (Self, Point)
Creates a new rectangle by clipping this rectangle to the given dimensions.
The new rectangle will be the largest rectangle that fits within the given dimensions and is contained within this rectangle.
The point returned is the offset of the top-left corner of the new rectangle within the given original rectangle. This is useful for rendering the new rectangle within the original rectangle.
Arguments
width
- The width of the rectangle to clip within.height
- The height of the rectangle to clip within.
Returns
A new rectangle that fits within the given dimensions and is contained within this rectangle. Also returns the offset of the top-left corner of the new rectangle within the original rectangle.
Trait Implementations§
source§impl PartialEq for Rect
impl PartialEq for Rect
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.