Struct Rect

Source
pub struct Rect {
    pub x: f32,
    pub y: f32,
    pub w: f32,
    pub h: f32,
}
Expand description

Axis-aligned rectangle in logical space: origin (x, y) and size (w, h).

§Examples

use ailloli_ui_core::Rect;
let rect = Rect::new(10.0, 20.0, 30.0, 40.0);
assert_eq!(rect.max(), (40.0, 60.0));

Fields§

§x: f32

Left edge.

§y: f32

Top edge.

§w: f32

Width in logical pixels; negative values are stored but usually empty.

§h: f32

Height in logical pixels; negative values are stored but usually empty.

Implementations§

Source§

impl Rect

Source

pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self

Creates a rectangle from origin and size without normalizing dimensions.

§Examples
use ailloli_ui_core::Rect;
assert_eq!(Rect::new(1.0, 2.0, 3.0, 4.0).w, 3.0);
Source

pub fn right(&self) -> f32

Right edge (x + w).

§Examples
use ailloli_ui_core::Rect;
assert_eq!(Rect::new(10.0, 0.0, 30.0, 1.0).right(), 40.0);
Source

pub fn bottom(&self) -> f32

Bottom edge (y + h).

§Examples
use ailloli_ui_core::Rect;
assert_eq!(Rect::new(0.0, 20.0, 1.0, 40.0).bottom(), 60.0);
Source

pub fn min(&self) -> (f32, f32)

Top-left corner (x, y).

§Examples
use ailloli_ui_core::Rect;
assert_eq!(Rect::new(1.0, 2.0, 3.0, 4.0).min(), (1.0, 2.0));
Source

pub fn max(&self) -> (f32, f32)

Bottom-right corner (right, bottom).

§Examples
use ailloli_ui_core::Rect;
assert_eq!(Rect::new(1.0, 2.0, 3.0, 4.0).max(), (4.0, 6.0));
Source

pub fn contains(&self, px: f32, py: f32) -> bool

Returns true if (px, py) lies inside the rectangle, including edges.

A negative dimension or non-finite operand normally yields false.

§Examples
use ailloli_ui_core::Rect;
assert!(Rect::new(0.0, 0.0, 10.0, 10.0).contains(5.0, 5.0));
Source

pub fn translate(&self, by: Offset) -> Rect

Translates the rectangle by by without changing size.

§Examples
use ailloli_ui_core::{Offset, Rect};
assert_eq!(Rect::new(1.0, 2.0, 3.0, 4.0).translate(Offset::new(5.0, 6.0)), Rect::new(6.0, 8.0, 3.0, 4.0));
Source

pub fn inflate(&self, dx: f32, dy: f32) -> Rect

Expands the rectangle by dx/dy on both matching sides.

Negative deltas deflate the rectangle and may produce negative sizes.

§Examples
use ailloli_ui_core::Rect;
assert_eq!(Rect::new(1.0, 2.0, 3.0, 4.0).inflate(1.0, 2.0), Rect::new(0.0, 0.0, 5.0, 8.0));
Source

pub fn intersection(&self, other: Rect) -> Option<Rect>

Returns the positive-area overlap, or None for disjoint/edge contact.

§Examples
use ailloli_ui_core::Rect;
let overlap = Rect::new(0.0, 0.0, 10.0, 10.0).intersection(Rect::new(5.0, 5.0, 10.0, 10.0));
assert_eq!(overlap, Some(Rect::new(5.0, 5.0, 5.0, 5.0)));

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Rect

Source§

fn eq(&self, other: &Rect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Rect

Source§

impl StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl Freeze for Rect

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.