pub struct PxRect {
pub x: Px,
pub y: Px,
pub width: Px,
pub height: Px,
}
Expand description
A 2D rectangle in physical pixel space.
This type represents a rectangle with a position (top-left corner) and dimensions in physical pixel space.
Fields§
§x: Px
The x-coordinate of the top-left corner
y: Px
The y-coordinate of the top-left corner
width: Px
The width of the rectangle
height: Px
The height of the rectangle
Implementations§
Source§impl PxRect
impl PxRect
Sourcepub const fn new(x: Px, y: Px, width: Px, height: Px) -> Self
pub const fn new(x: Px, y: Px, width: Px, height: Px) -> Self
Creates a new rectangle from position and size.
Sourcepub fn is_orthogonal(&self, other: &Self) -> bool
pub fn is_orthogonal(&self, other: &Self) -> bool
Checks if this rectangle is orthogonal (non-overlapping) with another rectangle.
Two rectangles are orthogonal if they do not overlap in either the x or y axis. This is useful for barrier batching optimization where non-overlapping rectangles can be processed together without requiring barriers.
§Arguments
other
- The other rectangle to check orthogonality against
§Returns
true
if the rectangles are orthogonal (non-overlapping), false
otherwise
§Examples
use tessera_ui::px::{Px, PxRect};
let rect1 = PxRect::new(Px::new(0), Px::new(0), Px::new(100), Px::new(100));
let rect2 = PxRect::new(Px::new(150), Px::new(0), Px::new(100), Px::new(100));
assert!(rect1.is_orthogonal(&rect2));
let rect3 = PxRect::new(Px::new(50), Px::new(50), Px::new(100), Px::new(100));
assert!(!rect1.is_orthogonal(&rect3));
Sourcepub fn union(&self, other: &Self) -> Self
pub fn union(&self, other: &Self) -> Self
Creates a new rectangle that is the union of this rectangle and another rectangle. Which is the smallest rectangle that contains both rectangles.
§Arguments
other
- The other rectangle to union with
§Returns
A new PxRect
that is the union of this rectangle and the other rectangle
§Examples
use tessera_ui::px::{Px, PxRect};
let rect1 = PxRect::new(Px::new(0), Px::new(0), Px::new(100), Px::new(100));
let rect2 = PxRect::new(Px::new(50), Px::new(50), Px::new(100), Px::new(100));
let union_rect = rect1.union(&rect2);
assert_eq!(union_rect, PxRect::new(Px::new(0), Px::new(0), Px::new(150), Px::new(150)));
Sourcepub fn area(&self) -> u32
pub fn area(&self) -> u32
Returns the area of this rectangle.
§Returns
The area as a positive integer, or 0 if width or height is negative
Sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Gets the intersection of this rectangle with another rectangle.
If the rectangles do not intersect, returns None
.
§Arguments
other
- The other rectangle to intersect with
§Returns
An Option<PxRect>
that is Some
if the rectangles intersect,
or None
if they do not.
§Examples
use tessera_ui::px::{Px, PxRect};
let rect1 = PxRect::new(Px::new(0), Px::new(0), Px::new(100), Px::new(100));
let rect2 = PxRect::new(Px::new(50), Px::new(50), Px::new(100), Px::new(100));
let intersection = rect1.intersection(&rect2);
assert_eq!(intersection, Some(PxRect::new(Px::new(50), Px::new(50), Px::new(50), Px::new(50))));
Trait Implementations§
impl Copy for PxRect
impl Eq for PxRect
impl StructuralPartialEq for PxRect
Auto Trait Implementations§
impl Freeze for PxRect
impl RefUnwindSafe for PxRect
impl Send for PxRect
impl Sync for PxRect
impl Unpin for PxRect
impl UnwindSafe for PxRect
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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
key
and return true
if they are equal.§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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§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()
.