pub struct RectAlign {
pub parent: Align2,
pub child: Align2,
}Expand description
Position a child Rect relative to a parent Rect.
The corner from RectAlign::child on the new rect will be aligned to
the corner from RectAlign::parent on the original rect.
There are helper constants for the 12 common menu positions:
┌───────────┐ ┌────────┐ ┌─────────┐
│ TOP_START │ │ TOP │ │ TOP_END │
└───────────┘ └────────┘ └─────────┘
┌──────────┐ ┌────────────────────────────────────┐ ┌───────────┐
│LEFT_START│ │ │ │RIGHT_START│
└──────────┘ │ │ └───────────┘
┌──────────┐ │ │ ┌───────────┐
│ LEFT │ │ some_rect │ │ RIGHT │
└──────────┘ │ │ └───────────┘
┌──────────┐ │ │ ┌───────────┐
│ LEFT_END │ │ │ │ RIGHT_END │
└──────────┘ └────────────────────────────────────┘ └───────────┘
┌────────────┐ ┌──────┐ ┌──────────┐
│BOTTOM_START│ │BOTTOM│ │BOTTOM_END│
└────────────┘ └──────┘ └──────────┘Fields§
§parent: Align2The alignment in the parent (original) rect.
child: Align2The alignment in the child (new) rect.
Implementations§
Source§impl RectAlign
impl RectAlign
Sourcepub const RIGHT_START: RectAlign
pub const RIGHT_START: RectAlign
Along the right edge, topmost.
Sourcepub const BOTTOM_END: RectAlign
pub const BOTTOM_END: RectAlign
Along the bottom edge, rightmost.
Sourcepub const BOTTOM_START: RectAlign
pub const BOTTOM_START: RectAlign
Along the bottom edge, leftmost.
Sourcepub const LEFT_START: RectAlign
pub const LEFT_START: RectAlign
Along the left edge, topmost.
Sourcepub const MENU_ALIGNS: [RectAlign; 12]
pub const MENU_ALIGNS: [RectAlign; 12]
The 12 most common menu positions as an array, for use with RectAlign::find_best_align.
Sourcepub fn from_align2(align: Align2) -> RectAlign
pub fn from_align2(align: Align2) -> RectAlign
Sourcepub fn over_corner(align: Align2) -> RectAlign
pub fn over_corner(align: Align2) -> RectAlign
The center of the child rect will be aligned to a corner of the parent rect.
Sourcepub fn align_rect(&self, parent_rect: &Rect, size: Vec2, gap: f32) -> Rect
pub fn align_rect(&self, parent_rect: &Rect, size: Vec2, gap: f32) -> Rect
Calculate the child rect based on a size and some optional gap.
Sourcepub fn gap_vector(&self) -> Vec2
pub fn gap_vector(&self) -> Vec2
Returns a sign vector (-1, 0 or 1 in each direction) that can be used as an offset to the child rect, creating a gap between the rects while keeping the edges aligned.
Sourcepub fn anchor(&self, parent_rect: &Rect, gap: f32) -> Pos2
pub fn anchor(&self, parent_rect: &Rect, gap: f32) -> Pos2
Calculator the anchor point for the child rect, based on the parent rect and an optional gap.
Sourcepub fn symmetries(self) -> [RectAlign; 3]
pub fn symmetries(self) -> [RectAlign; 3]
Returns the 3 alternative RectAligns that are flipped in various ways, for use
with RectAlign::find_best_align.
Sourcepub fn find_best_align(
values_to_try: impl Iterator<Item = RectAlign>,
screen_rect: Rect,
parent_rect: Rect,
gap: f32,
expected_size: Vec2,
) -> Option<RectAlign>
pub fn find_best_align( values_to_try: impl Iterator<Item = RectAlign>, screen_rect: Rect, parent_rect: Rect, gap: f32, expected_size: Vec2, ) -> Option<RectAlign>
Look for the first alternative RectAlign that allows the child rect to fit
inside the screen_rect.
If no alternative fits, the first is returned.
If no alternatives are given, None is returned.
See also:
RectAlign::symmetriesto calculate alternativesRectAlign::MENU_ALIGNSfor the 12 common menu positions
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RectAlign
impl<'de> Deserialize<'de> for RectAlign
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<RectAlign, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<RectAlign, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for RectAlign
impl Serialize for RectAlign
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for RectAlign
impl Eq for RectAlign
impl StructuralPartialEq for RectAlign
Auto Trait Implementations§
impl Freeze for RectAlign
impl RefUnwindSafe for RectAlign
impl Send for RectAlign
impl Sync for RectAlign
impl Unpin for RectAlign
impl UnwindSafe for RectAlign
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,
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