Skip to main content

Alignment

Struct Alignment 

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

A point within a rectangle.

Alignment(0.0, 0.0) represents the center of the rectangle. The distance from -1.0 to +1.0 is the distance from one side of the rectangle to the other side of the rectangle. Therefore, 2.0 units horizontally (or vertically) is equivalent to the width (or height) of the rectangle.

Alignment(-1.0, -1.0) represents the top left of the rectangle.

Alignment(1.0, 1.0) represents the bottom right of the rectangle.

Alignment(0.0, 3.0) represents a point that is horizontally centered with respect to the rectangle and vertically below the bottom of the rectangle by the height of the rectangle.

Alignment(0.0, -0.5) represents a point that is horizontally centered with respect to the rectangle and vertically half way between the top edge and the center.

Alignment(x, y) in a rectangle with height h and width w describes the point (x * w/2 + w/2, y * h/2 + h/2) in the coordinate system of the rectangle.

Alignment uses visual coordinates, which means increasing x moves the point from left to right. To support layouts with a right-to-left TextDirection, consider using AlignmentDirectional, in which the direction the point moves when increasing the horizontal value depends on the TextDirection.

A variety of widgets use Alignment in their configuration, most notably:

  • Align positions a child according to an Alignment.

See also:

Fields§

§x: f64

The distance fraction in the horizontal direction.

A value of -1.0 corresponds to the leftmost edge. A value of 1.0 corresponds to the rightmost edge. Values are not limited to that range; values less than -1.0 represent positions to the left of the left edge, and values greater than 1.0 represent positions to the right of the right edge.

§y: f64

The distance fraction in the vertical direction.

A value of -1.0 corresponds to the topmost edge. A value of 1.0 corresponds to the bottommost edge. Values are not limited to that range; values less than -1.0 represent positions above the top, and values greater than 1.0 represent positions below the bottom.

Implementations§

Source§

impl Alignment

Source

pub const TOP_LEFT: Alignment

The top left corner.

Source

pub const TOP_CENTER: Alignment

The center point along the top edge.

Source

pub const TOP_RIGHT: Alignment

The top right corner.

Source

pub const CENTER_LEFT: Alignment

The center point along the left edge.

Source

pub const CENTER: Alignment

The center point, both horizontally and vertically.

Source

pub const CENTER_RIGHT: Alignment

The center point along the right edge.

Source

pub const BOTTOM_LEFT: Alignment

The bottom left corner.

Source

pub const BOTTOM_CENTER: Alignment

The center point along the bottom edge.

Source

pub const BOTTOM_RIGHT: Alignment

The bottom right corner.

Source

pub const fn new(x: f64, y: f64) -> Alignment

Creates an alignment.

Source

pub fn truncating_div(&self, other: f64) -> Alignment

Integer divides the Alignment in each dimension by the given factor.

Source

pub fn along_offset(&self, other: Offset) -> Offset

Returns the offset that is this fraction in the direction of the given offset.

Source

pub fn along_size(&self, other: Size) -> Offset

Returns the offset that is this fraction within the given size.

Source

pub fn within_rect(&self, rect: Rect) -> Offset

Returns the point that is this fraction within the given rect.

Source

pub fn inscribe(&self, size: Size, rect: Rect) -> Rect

Returns a rect of the given size, aligned within given rect as specified by this alignment.

For example, a 100×100 size inscribed on a 200×200 rect using Alignment::TOP_LEFT would be the 100×100 rect at the top left of the 200×200 rect.

Source

pub fn lerp( a: Option<Alignment>, b: Option<Alignment>, t: f64, ) -> Option<Alignment>

Linearly interpolate between two Alignments.

If either is null, this function interpolates from Alignment::CENTER.

Source

pub fn resolve(&self, _direction: Option<TextDirection>) -> Alignment

Convert this instance into an Alignment, which uses literal coordinates.

Trait Implementations§

Source§

impl Add for Alignment

Source§

type Output = Alignment

The resulting type after applying the + operator.
Source§

fn add(self, other: Alignment) -> Alignment

Performs the + operation. Read more
Source§

impl Add<Alignment> for FractionalOffset

Source§

type Output = Alignment

The resulting type after applying the + operator.
Source§

fn add(self, other: Alignment) -> Alignment

Performs the + operation. Read more
Source§

impl Animatable<Alignment> for AlignmentTween

Source§

fn transform(&self, _app: &App, t: f64) -> Alignment

Returns the value of the object at point t. Read more
Source§

fn evaluate(&self, app: &App, animation: AnyAnimation<f64>) -> T
where Self: Sized,

The current value of this object for the given animation. Read more
Source§

fn animate( self, app: &mut App, parent: Retained<AnyAnimation<f64>>, ) -> Retained<AnyAnimation<T>>
where Self: Sized + Clone + 'static, T: 'static,

Returns a new animation that is driven by the given animation but that takes on values determined by this object. The new animation keeps parent; whoever keeps the result keeps both.
Source§

fn chain<P>(self, parent: P) -> ChainedEvaluation<P, Self>
where Self: Sized + Clone, P: Animatable<f64> + Clone,

Returns a new Animatable whose value is determined by first evaluating the given parent and then evaluating this object at the result.
Source§

impl Clone for Alignment

Source§

fn clone(&self) -> Alignment

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<(), Error>

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

impl Display for Alignment

Dart’s Alignment.toString, which Debug already renders.

Source§

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

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

impl Div<f64> for Alignment

Source§

type Output = Alignment

The resulting type after applying the / operator.
Source§

fn div(self, other: f64) -> Alignment

Performs the / operation. Read more
Source§

impl From<Alignment> for AlignmentGeometry

Source§

fn from(alignment: Alignment) -> AlignmentGeometry

Converts to this type from the input type.
Source§

impl From<FractionalOffset> for Alignment

Source§

fn from(offset: FractionalOffset) -> Alignment

Converts to this type from the input type.
Source§

impl Mul<f64> for Alignment

Source§

type Output = Alignment

The resulting type after applying the * operator.
Source§

fn mul(self, other: f64) -> Alignment

Performs the * operation. Read more
Source§

impl Neg for Alignment

Source§

type Output = Alignment

The resulting type after applying the - operator.
Source§

fn neg(self) -> Alignment

Performs the unary - operation. Read more
Source§

impl PartialEq for Alignment

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<Alignment> for FractionalOffset

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialEq<FractionalOffset> for Alignment

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Rem<f64> for Alignment

Source§

type Output = Alignment

The resulting type after applying the % operator.
Source§

fn rem(self, other: f64) -> Alignment

Performs the % operation. Read more
Source§

impl StructuralPartialEq for Alignment

Source§

impl Sub for Alignment

Source§

type Output = Alignment

The resulting type after applying the - operator.
Source§

fn sub(self, other: Alignment) -> Alignment

Performs the - operation. Read more
Source§

impl Sub<Alignment> for FractionalOffset

Source§

type Output = Alignment

The resulting type after applying the - operator.
Source§

fn sub(self, other: Alignment) -> Alignment

Performs the - operation. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,