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:
Alignpositions a child according to anAlignment.
See also:
AlignmentDirectional, which has a horizontal coordinate orientation that depends on theTextDirection.AlignmentGeometry, which is an abstract type that is agnostic as to whether the horizontal direction depends on theTextDirection.
Fields§
§x: f64The 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: f64The 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
impl Alignment
Sourcepub const TOP_CENTER: Alignment
pub const TOP_CENTER: Alignment
The center point along the top edge.
Sourcepub const CENTER_LEFT: Alignment
pub const CENTER_LEFT: Alignment
The center point along the left edge.
Sourcepub const CENTER_RIGHT: Alignment
pub const CENTER_RIGHT: Alignment
The center point along the right edge.
Sourcepub const BOTTOM_LEFT: Alignment
pub const BOTTOM_LEFT: Alignment
The bottom left corner.
Sourcepub const BOTTOM_CENTER: Alignment
pub const BOTTOM_CENTER: Alignment
The center point along the bottom edge.
Sourcepub const BOTTOM_RIGHT: Alignment
pub const BOTTOM_RIGHT: Alignment
The bottom right corner.
Sourcepub fn truncating_div(&self, other: f64) -> Alignment
pub fn truncating_div(&self, other: f64) -> Alignment
Integer divides the Alignment in each dimension by the given factor.
Sourcepub fn along_offset(&self, other: Offset) -> Offset
pub fn along_offset(&self, other: Offset) -> Offset
Returns the offset that is this fraction in the direction of the given offset.
Sourcepub fn along_size(&self, other: Size) -> Offset
pub fn along_size(&self, other: Size) -> Offset
Returns the offset that is this fraction within the given size.
Sourcepub fn within_rect(&self, rect: Rect) -> Offset
pub fn within_rect(&self, rect: Rect) -> Offset
Returns the point that is this fraction within the given rect.
Sourcepub fn inscribe(&self, size: Size, rect: Rect) -> Rect
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.
Trait Implementations§
Source§impl Add<Alignment> for FractionalOffset
impl Add<Alignment> for FractionalOffset
Source§impl Animatable<Alignment> for AlignmentTween
impl Animatable<Alignment> for AlignmentTween
Source§fn transform(&self, _app: &App, t: f64) -> Alignment
fn transform(&self, _app: &App, t: f64) -> Alignment
t. Read moreSource§fn evaluate(&self, app: &App, animation: AnyAnimation<f64>) -> Twhere
Self: Sized,
fn evaluate(&self, app: &App, animation: AnyAnimation<f64>) -> Twhere
Self: Sized,
Source§fn animate(
self,
app: &mut App,
parent: Retained<AnyAnimation<f64>>,
) -> Retained<AnyAnimation<T>>
fn animate( self, app: &mut App, parent: Retained<AnyAnimation<f64>>, ) -> Retained<AnyAnimation<T>>
parent; whoever keeps the result keeps both.Source§fn chain<P>(self, parent: P) -> ChainedEvaluation<P, Self>
fn chain<P>(self, parent: P) -> ChainedEvaluation<P, Self>
Animatable whose value is determined by first
evaluating the given parent and then evaluating this object at the
result.