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: f32Left edge.
y: f32Top edge.
w: f32Width in logical pixels; negative values are stored but usually empty.
h: f32Height in logical pixels; negative values are stored but usually empty.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self
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);Sourcepub fn right(&self) -> f32
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);Sourcepub fn bottom(&self) -> f32
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);Sourcepub fn min(&self) -> (f32, f32)
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));Sourcepub fn max(&self) -> (f32, f32)
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));Sourcepub fn contains(&self, px: f32, py: f32) -> bool
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));Sourcepub fn translate(&self, by: Offset) -> Rect
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));Sourcepub fn inflate(&self, dx: f32, dy: f32) -> Rect
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));Sourcepub fn intersection(&self, other: Rect) -> Option<Rect>
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)));