Skip to main content

Alignment

Struct Alignment 

Source
pub struct Alignment {
    pub x: f32,
    pub y: f32,
}
Expand description

Where to place a child inside its containing box: two continuous fractions in [-1, 1]. x = -1 hugs the left, 0 centres, +1 hugs the right; y = -1 is the top, +1 the bottom. Being continuous, it interpolates (crate::Lerp): a Tween<Alignment> slides a child from one anchor to another. The nine usual anchors are provided as constants (Alignment::CENTER, Alignment::TOP_LEFT, and so on).

Fields§

§x: f32

Horizontal fraction: -1 (left) … 0 (centre) … +1 (right).

§y: f32

Vertical fraction: -1 (top) … 0 (centre) … +1 (bottom).

Implementations§

Source§

impl Alignment

Source

pub const TOP_LEFT: Self

Hugs the top-left corner.

Source

pub const TOP_CENTER: Self

Hugs the top edge, centred horizontally.

Source

pub const TOP_RIGHT: Self

Hugs the top-right corner.

Source

pub const CENTER_LEFT: Self

Hugs the left edge, centred vertically.

Source

pub const CENTER: Self

The exact centre.

Source

pub const CENTER_RIGHT: Self

Hugs the right edge, centred vertically.

Source

pub const BOTTOM_LEFT: Self

Hugs the bottom-left corner.

Source

pub const BOTTOM_CENTER: Self

Hugs the bottom edge, centred horizontally.

Source

pub const BOTTOM_RIGHT: Self

Hugs the bottom-right corner.

Source

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

An (x, y) anchor, with fractions in [-1, 1].

Source

pub fn fraction_x(self) -> f32

The horizontal fraction mapped into [0, 1] (0 = left, 1 = right): the share of the free space to leave before the child on the x axis.

Source

pub fn fraction_y(self) -> f32

The vertical fraction mapped into [0, 1] (0 = top, 1 = bottom).

Trait Implementations§

Source§

impl Clone for Alignment

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Alignment

Source§

impl Debug for Alignment

Source§

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

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

impl Default for Alignment

Source§

fn default() -> Self

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

impl From<Alignment> for AlignmentGeometry

Source§

fn from(a: Alignment) -> Self

Converts to this type from the input type.
Source§

impl Lerp for Alignment

Source§

fn lerp(self, other: Self, t: f32) -> Self

Interpolates from self (at t=0) to other (at t=1).
Source§

impl PartialEq for Alignment

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Alignment

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.