pub enum Flex {
Legacy,
Start,
End,
Center,
SpaceBetween,
SpaceEvenly,
SpaceAround,
}Expand description
Defines the options for layout flex justify content in a container.
This enumeration controls the distribution of space when layout constraints are met and there
is excess space available. The Flex option is used with Layout to
control how extra space is distributed among layout segments, which is particularly useful for
creating responsive layouts that adapt to different terminal sizes.
Available options:
Legacy: Fills the available space within the container, putting excess space into the last element.Start: Aligns items to the start of the container.End: Aligns items to the end of the container.Center: Centers items within the container.SpaceBetween: Adds excess space between each element.SpaceAround: Adds excess space around each element.
For comprehensive layout documentation and examples, see the layout module.
Variants§
Legacy
Fills the available space within the container, putting excess space into the last
constraint of the lowest priority. This matches the default behavior of ratatui and tui
applications without Flex
The following examples illustrate the allocation of excess in various combinations of constraints. As a refresher, the priorities of constraints are as follows:
Constraint::MinConstraint::MaxConstraint::LengthConstraint::PercentageConstraint::RatioConstraint::Fill
When every constraint is Length, the last element gets the excess.
<----------------------------------- 80 px ------------------------------------>
┌──────20 px───────┐┌──────20 px───────┐┌────────────────40 px─────────────────┐
│ Length(20) ││ Length(20) ││ Length(20) │
└──────────────────┘└──────────────────┘└──────────────────────────────────────┘
^^^^^^^^^^^^^^^^ EXCESS ^^^^^^^^^^^^^^^^Fill constraints have the lowest priority amongst all the constraints and hence will always take up any excess space available.
<----------------------------------- 80 px ------------------------------------>
┌──────20 px───────┐┌──────20 px───────┐┌──────20 px───────┐┌──────20 px───────┐
│ Fill(0) ││ Max(20) ││ Length(20) ││ Length(20) │
└──────────────────┘└──────────────────┘└──────────────────┘└──────────────────┘
^^^^^^ EXCESS ^^^^^^§Examples
<------------------------------------80 px------------------------------------->
┌──────────────────────────60 px───────────────────────────┐┌──────20 px───────┐
│ Min(20) ││ Max(20) │
└──────────────────────────────────────────────────────────┘└──────────────────┘
<------------------------------------80 px------------------------------------->
┌────────────────────────────────────80 px─────────────────────────────────────┐
│ Max(20) │
└──────────────────────────────────────────────────────────────────────────────┘Start
Aligns items to the start of the container.
§Examples
<------------------------------------80 px------------------------------------->
┌────16 px─────┐┌──────20 px───────┐┌──────20 px───────┐
│Percentage(20)││ Length(20) ││ Fixed(20) │
└──────────────┘└──────────────────┘└──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐┌──────20 px───────┐
│ Max(20) ││ Max(20) │
└──────────────────┘└──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐
│ Max(20) │
└──────────────────┘End
Aligns items to the end of the container.
§Examples
<------------------------------------80 px------------------------------------->
┌────16 px─────┐┌──────20 px───────┐┌──────20 px───────┐
│Percentage(20)││ Length(20) ││ Length(20) │
└──────────────┘└──────────────────┘└──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐┌──────20 px───────┐
│ Max(20) ││ Max(20) │
└──────────────────┘└──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐
│ Max(20) │
└──────────────────┘Center
Centers items within the container.
§Examples
<------------------------------------80 px------------------------------------->
┌────16 px─────┐┌──────20 px───────┐┌──────20 px───────┐
│Percentage(20)││ Length(20) ││ Length(20) │
└──────────────┘└──────────────────┘└──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐┌──────20 px───────┐
│ Max(20) ││ Max(20) │
└──────────────────┘└──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐
│ Max(20) │
└──────────────────┘SpaceBetween
Adds excess space between each element.
§Examples
<------------------------------------80 px------------------------------------->
┌────16 px─────┐ ┌──────20 px───────┐ ┌──────20 px───────┐
│Percentage(20)│ │ Length(20) │ │ Length(20) │
└──────────────┘ └──────────────────┘ └──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐ ┌──────20 px───────┐
│ Max(20) │ │ Max(20) │
└──────────────────┘ └──────────────────┘
<------------------------------------80 px------------------------------------->
┌────────────────────────────────────80 px─────────────────────────────────────┐
│ Max(20) │
└──────────────────────────────────────────────────────────────────────────────┘SpaceEvenly
Evenly distributes excess space between all elements, including before the first and after the last.
§Examples
<------------------------------------80 px------------------------------------->
┌────16 px─────┐ ┌──────20 px───────┐ ┌──────20 px───────┐
│Percentage(20)│ │ Length(20) │ │ Length(20) │
└──────────────┘ └──────────────────┘ └──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐ ┌──────20 px───────┐
│ Max(20) │ │ Max(20) │
└──────────────────┘ └──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐
│ Max(20) │
└──────────────────┘SpaceAround
Adds excess space around each element.
§Examples
<------------------------------------80 px------------------------------------->
┌────16 px─────┐ ┌──────20 px───────┐ ┌──────20 px───────┐
│Percentage(20)│ │ Length(20) │ │ Length(20) │
└──────────────┘ └──────────────────┘ └──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐ ┌──────20 px───────┐
│ Max(20) │ │ Max(20) │
└──────────────────┘ └──────────────────┘
<------------------------------------80 px------------------------------------->
┌──────20 px───────┐
│ Max(20) │
└──────────────────┘Implementations§
Source§impl Flex
impl Flex
Sourcepub const fn is_space_between(&self) -> bool
pub const fn is_space_between(&self) -> bool
Returns true if the enum is Flex::SpaceBetween otherwise false
Sourcepub const fn is_space_evenly(&self) -> bool
pub const fn is_space_evenly(&self) -> bool
Returns true if the enum is Flex::SpaceEvenly otherwise false
Sourcepub const fn is_space_around(&self) -> bool
pub const fn is_space_around(&self) -> bool
Returns true if the enum is Flex::SpaceAround otherwise false
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Flex
impl<'de> Deserialize<'de> for Flex
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>,
impl Copy for Flex
impl Eq for Flex
impl StructuralPartialEq for Flex
Auto Trait Implementations§
impl Freeze for Flex
impl RefUnwindSafe for Flex
impl Send for Flex
impl Sync for Flex
impl Unpin for Flex
impl UnwindSafe for Flex
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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 moreSource§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read moreSource§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more