Struct zng_layout::unit::Align
source · 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: Factor
x alignment in a [0.0..=1.0]
range.
x_rtl_aware: bool
If x
is flipped (around 0.5
) in right-to-left contexts.
y: Factor
y 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.
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 Align::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.
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.
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.
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)
Applies the alignment transform to wl
and returns the size of the parent align node, the translate offset and if
baseline must be translated.
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 IntoVar<Align> for FactorPercent
impl IntoVar<Align> for FactorPercent
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<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
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 Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self
equals other
.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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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