pub enum Flex {
Legacy,
Start,
End,
Center,
SpaceBetween,
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.
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.
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::Min
Constraint::Max
Constraint::Length
Constraint::Percentage
Constraint::Ratio
Constraint::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) │
└──────────────────────────────────────────────────────────────────────────────┘
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_around(&self) -> bool
pub const fn is_space_around(&self) -> bool
Returns true if the enum is Flex::SpaceAround otherwise false
Trait Implementations§
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<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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.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> 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 more