pub struct Rect {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}Expand description
A rectangle in space, represented with f32 coordinates.
Fields§
§x: f32§y: f32§w: f32§h: f32Implementations§
Source§impl Rect
impl Rect
Sourcepub fn new(x: f32, y: f32, w: f32, h: f32) -> Self
pub fn new(x: f32, y: f32, w: f32, h: f32) -> Self
Create a new rectangle with the given dimensions and position.
Sourcepub fn new_checked(x: f32, y: f32, w: f32, h: f32) -> Option<Self>
pub fn new_checked(x: f32, y: f32, w: f32, h: f32) -> Option<Self>
Identical to new, but returns None if either the width or height is negative.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns false if either the width or height is negative. Otherwise, returns true.
Sourcepub fn shrink_begin_x(self, amount: f32) -> Self
pub fn shrink_begin_x(self, amount: f32) -> Self
Shrink the width of the rectangle by the given amount toward the left.
Sourcepub fn shrink_end_x(self, amount: f32) -> Self
pub fn shrink_end_x(self, amount: f32) -> Self
Shrink the width of the rectangle by the given amount toward the right.
Sourcepub fn shrink_center_x(self, amount: f32) -> Self
pub fn shrink_center_x(self, amount: f32) -> Self
Shrink the width of the rectangle by the given amount toward the center.
Sourcepub fn shrink_begin_y(self, amount: f32) -> Self
pub fn shrink_begin_y(self, amount: f32) -> Self
Shrink the height of the rectangle by the given amount toward the top.
Sourcepub fn shrink_end_y(self, amount: f32) -> Self
pub fn shrink_end_y(self, amount: f32) -> Self
Shrink the height of the rectangle by the given amount toward the bottom.
Sourcepub fn shrink_center_y(self, amount: f32) -> Self
pub fn shrink_center_y(self, amount: f32) -> Self
Shrink the height of the rectangle by the given amount toward the middle.
Sourcepub fn align(self, align: (Alignment, Alignment), min: (f32, f32)) -> Self
pub fn align(self, align: (Alignment, Alignment), min: (f32, f32)) -> Self
Create a contained rectangle aligned within self.
Example:
use layuit::{Rect, Alignment};
let rect = Rect::new(0.0, 0.0, 100.0, 100.0);
let contained_center = rect.align((Alignment::Center, Alignment::Center), (50.0, 50.0));
assert_eq!(contained_center, Rect::new(25.0, 25.0, 50.0, 50.0));
let contained_top_right = rect.align((Alignment::End, Alignment::Begin), (50.0, 50.0));
assert_eq!(contained_top_right, Rect::new(50.0, 0.0, 50.0, 50.0));
let contained_equal = rect.align((Alignment::Full, Alignment::Full), (50.0, 50.0));
assert_eq!(contained_equal, Rect::new(0.0, 0.0, 100.0, 100.0));