Struct RectAlign

Source
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: Align2

The alignment in the parent (original) rect.

§child: Align2

The alignment in the child (new) rect.

Implementations§

Source§

impl RectAlign

Source

pub const TOP_START: Self

Along the top edge, leftmost.

Source

pub const TOP: Self

Along the top edge, centered.

Source

pub const TOP_END: Self

Along the top edge, rightmost.

Source

pub const RIGHT_START: Self

Along the right edge, topmost.

Source

pub const RIGHT: Self

Along the right edge, centered.

Source

pub const RIGHT_END: Self

Along the right edge, bottommost.

Source

pub const BOTTOM_END: Self

Along the bottom edge, rightmost.

Source

pub const BOTTOM: Self

Along the bottom edge, centered.

Source

pub const BOTTOM_START: Self

Along the bottom edge, leftmost.

Source

pub const LEFT_END: Self

Along the left edge, bottommost.

Source

pub const LEFT: Self

Along the left edge, centered.

Source

pub const LEFT_START: Self

Along the left edge, topmost.

Source

pub const MENU_ALIGNS: [Self; 12]

The 12 most common menu positions as an array, for use with RectAlign::find_best_align.

Source

pub fn parent(&self) -> Align2

Align in the parent rect.

Source

pub fn child(&self) -> Align2

Align in the child rect.

Source

pub fn from_align2(align: Align2) -> Self

Convert an Align2 to an RectAlign, positioning the child rect inside the parent.

Source

pub fn over_corner(align: Align2) -> Self

The center of the child rect will be aligned to a corner of the parent rect.

Source

pub fn outside(align: Align2) -> Self

Position the child rect outside the parent rect.

Source

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.

Source

pub fn pivot_pos(&self, parent_rect: &Rect, gap: f32) -> (Align2, Pos2)

Returns a Align2 and a Pos2 that you can e.g. use with Area::fixed_pos and Area::pivot to align an Area to some rect.

Source

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.

Source

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.

Source

pub fn flip_x(self) -> Self

Flip the alignment on the x-axis.

Source

pub fn flip_y(self) -> Self

Flip the alignment on the y-axis.

Source

pub fn flip(self) -> Self

Flip the alignment on both axes.

Source

pub fn symmetries(self) -> [Self; 3]

Returns the 3 alternative RectAligns that are flipped in various ways, for use with RectAlign::find_best_align.

Source

pub fn find_best_align( values_to_try: impl Iterator<Item = Self>, screen_rect: Rect, parent_rect: Rect, gap: f32, expected_size: Vec2, ) -> Option<Self>

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:

Trait Implementations§

Source§

impl Clone for RectAlign

Source§

fn clone(&self) -> RectAlign

Returns a duplicate 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 RectAlign

Source§

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

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

impl Default for RectAlign

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RectAlign

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for RectAlign

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for RectAlign

Source§

fn eq(&self, other: &RectAlign) -> 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 Serialize for RectAlign

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for RectAlign

Source§

impl Eq for RectAlign

Source§

impl StructuralPartialEq for RectAlign

Auto Trait Implementations§

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> 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,