pub struct Align {
pub x: Factor,
pub x_rtl_aware: bool,
pub y: Factor,
}Expand description
x and y alignment.
The values indicate how much to the right and bottom the content is moved within
a larger available space. An x value of 0.0 means the content left border touches
the container left border, a value of 1.0 means the content right border touches the
container right border.
There is a constant for each of the usual alignment values, the alignment is defined as two factors like this primarily for animating transition between alignments.
Values outside of the [0.0..=1.0] range places the content outside of the container bounds.
§Special Values
The f32::INFINITY value can be used in x or y to indicate that the content must fill the available space.
The f32::NEG_INFINITY value can be used in y to indicate that a panel widget must align its items by each baseline,
for most widgets this is the same as BOTTOM, but for texts this aligns to the baseline of the texts (bottom + baseline).
You can use the is_fill_x, is_fill_y and is_baseline methods to probe for these special values.
§Right-to-Left
The x alignment can be flagged as x_rtl_aware, in widgets that implement right-to-left the x value is flipped around 0.5.fct().
The named const values that contain START and END are x_rtl_aware, the others are not. The x_rtl_aware flag is sticky, all
arithmetic operations between aligns output an x_rtl_aware align if any of the inputs is flagged. The flag is only resolved explicitly,
arithmetic operations apply on the
Fields§
§x: Factorx alignment in a [0.0..=1.0] range.
x_rtl_aware: boolIf x is flipped (around 0.5) in right-to-left contexts.
y: Factory alignment in a [0.0..=1.0] range.
Implementations§
Source§impl Align
impl Align
Sourcepub fn x(self, direction: LayoutDirection) -> Factor
pub fn x(self, direction: LayoutDirection) -> Factor
Gets the best finite x align value.
Replaces FILL with START, flips x for right-to-left if applicable.
Sourcepub fn y(self) -> Factor
pub fn y(self) -> Factor
Gets the best finite y align value.
Returns 1.fct() for is_baseline, implementers must add the baseline offset to that.
Sourcepub fn xy(self, direction: LayoutDirection) -> Factor2d
pub fn xy(self, direction: LayoutDirection) -> Factor2d
Sourcepub fn is_fill_x(self) -> bool
pub fn is_fill_x(self) -> bool
Returns true if x is a special value that indicates the content width must be the container width.
Sourcepub fn is_fill_y(self) -> bool
pub fn is_fill_y(self) -> bool
Returns true if y is a special value that indicates the content height must be the container height.
Sourcepub fn is_baseline(self) -> bool
pub fn is_baseline(self) -> bool
Returns true if y is a special value that indicates the contents must be aligned by their baseline.
If this is true the y alignment must be BOTTOM plus the baseline offset.
Sourcepub fn fill_vector(self) -> BoolVector2D
pub fn fill_vector(self) -> BoolVector2D
Returns a boolean vector of the fill values.
Sourcepub fn child_constraints(
self,
parent_constraints: PxConstraints2d,
) -> PxConstraints2d
pub fn child_constraints( self, parent_constraints: PxConstraints2d, ) -> PxConstraints2d
Constraints that must be used to layout a child node with the alignment.
Note that these constraints define the child inner bounds (the visual size) only,
using the child size call layout to get the child outer bounds size.
Sourcepub fn child_offset(
self,
child_size: PxSize,
parent_size: PxSize,
direction: LayoutDirection,
) -> PxVector
pub fn child_offset( self, child_size: PxSize, parent_size: PxSize, direction: LayoutDirection, ) -> PxVector
Compute the offset for a given child size, parent size and layout direction.
Note that this does not flag baseline offset, you can use layout to cover all corner cases.
Sourcepub fn measure(
self,
child_size: PxSize,
parent_constraints: PxConstraints2d,
) -> PxSize
pub fn measure( self, child_size: PxSize, parent_constraints: PxConstraints2d, ) -> PxSize
Computes the size returned by layout for the given child size and constraints.
Note that the child must be measured using child_constraints, the child_size is the size the child
will be rendered at, this method computes the child outer bounds.
Sourcepub fn measure_x(
self,
child_width: Px,
parent_constraints_x: PxConstraints,
) -> Px
pub fn measure_x( self, child_width: Px, parent_constraints_x: PxConstraints, ) -> Px
Computes the width returned by layout for the given child width and x constraints.
See measure for more details.
Sourcepub fn measure_y(
self,
child_height: Px,
parent_constraints_y: PxConstraints,
) -> Px
pub fn measure_y( self, child_height: Px, parent_constraints_y: PxConstraints, ) -> Px
Computes the height returned by layout for the given child height and y constraints.
See measure for more details.
Sourcepub fn layout(
self,
child_size: PxSize,
parent_constraints: PxConstraints2d,
direction: LayoutDirection,
) -> (PxSize, PxVector, bool)
pub fn layout( self, child_size: PxSize, parent_constraints: PxConstraints2d, direction: LayoutDirection, ) -> (PxSize, PxVector, bool)
Compute the outer size and inner offset.
Note that the child must be layout using the child_constraints, the child_size is the size the child
will be rendered at, this method computes the child outer bounds.
Returns the outer size, inner offset and is_baseline
Source§impl Align
impl Align
Sourcepub const BOTTOM_START: Align
pub const BOTTOM_START: Align
(0.0, 1.0)
Sourcepub const BOTTOM_LEFT: Align
pub const BOTTOM_LEFT: Align
(0.0, 1.0)
Sourcepub const BOTTOM_END: Align
pub const BOTTOM_END: Align
(1.0, 1.0)
Sourcepub const BOTTOM_RIGHT: Align
pub const BOTTOM_RIGHT: Align
(1.0, 1.0)
Sourcepub const FILL_BOTTOM: Align
pub const FILL_BOTTOM: Align
(f32::INFINITY, 1.0)
Sourcepub const FILL_START: Align
pub const FILL_START: Align
(0.0, f32::INFINITY)
Sourcepub const FILL_RIGHT: Align
pub const FILL_RIGHT: Align
(1.0, f32::INFINITY)
Sourcepub const BASELINE_START: Align
pub const BASELINE_START: Align
(0.0, f32::NEG_INFINITY)
Sourcepub const BASELINE_LEFT: Align
pub const BASELINE_LEFT: Align
(0.0, f32::NEG_INFINITY)
Sourcepub const BASELINE_CENTER: Align
pub const BASELINE_CENTER: Align
(0.5, f32::NEG_INFINITY)
Sourcepub const BASELINE_END: Align
pub const BASELINE_END: Align
(1.0, f32::NEG_INFINITY)
Sourcepub const BASELINE_RIGHT: Align
pub const BASELINE_RIGHT: Align
(1.0, f32::NEG_INFINITY)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Align
impl<'de> Deserialize<'de> for Align
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<S: Into<Factor2d>> DivAssign<S> for Align
impl<S: Into<Factor2d>> DivAssign<S> for Align
Source§fn div_assign(&mut self, rhs: S)
fn div_assign(&mut self, rhs: S)
/= operation. Read moreSource§impl From<FactorPercent> for Align
impl From<FactorPercent> for Align
Source§fn from(xy: FactorPercent) -> Self
fn from(xy: FactorPercent) -> Self
Source§impl FromStr for Align
Parse a named align or "(x, y)" were x Factor or "FILL" and y is factor, "FILL" or "BASELINE".
impl FromStr for Align
Parse a named align or "(x, y)" were x Factor or "FILL" and y is factor, "FILL" or "BASELINE".
Source§impl<S: Into<Factor2d>> MulAssign<S> for Align
impl<S: Into<Factor2d>> MulAssign<S> for Align
Source§fn mul_assign(&mut self, rhs: S)
fn mul_assign(&mut self, rhs: S)
*= operation. Read moreSource§impl Transitionable for Align
impl Transitionable for Align
Source§fn lerp(self, to: &Self, step: EasingStep) -> Self
fn lerp(self, to: &Self, step: EasingStep) -> Self
self -> to by step.impl Copy for Align
impl Eq for Align
impl<X: Into<Factor>, Y: Into<Factor>> IntoValue<Align> for (X, Y)
impl<X: Into<Factor>, Y: Into<Factor>> IntoValue<Align> for (X, bool, Y)
impl IntoValue<Align> for Factor
impl IntoValue<Align> for Factor2d
impl IntoValue<Align> for FactorPercent
impl IntoValue<Point> for Align
impl StructuralPartialEq for Align
Auto Trait Implementations§
impl Freeze for Align
impl RefUnwindSafe for Align
impl Send for Align
impl Sync for Align
impl Unpin for Align
impl UnwindSafe for Align
Blanket Implementations§
Source§impl<T> AnyVarValue for T
impl<T> AnyVarValue for T
Source§fn clone_boxed(&self) -> BoxAnyVarValue
fn clone_boxed(&self) -> BoxAnyVarValue
Source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self and other are equal.Source§fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
other if both are of the same type.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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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