pub struct Alignment { /* private fields */ }
Expand description
Alignment represent a horizontal and vertical alignment setting for any cell on a Table
.
An alignment strategy can be set by AlignmentStrategy
.
Example
use tabled::{
Table,
settings::{
formatting::AlignmentStrategy,
object::Segment, Alignment, Modify, Style,
}
};
let data = [
["1", "2", "3"],
["Some\nMulti\nLine\nText", "and a line", "here"],
["4", "5", "6"],
];
let mut table = Table::new(&data);
table
.with(Style::modern())
.with(
Modify::new(Segment::all())
.with(Alignment::right())
.with(Alignment::center())
.with(AlignmentStrategy::PerCell)
);
assert_eq!(
table.to_string(),
concat!(
"┌───────┬────────────┬──────┐\n",
"│ 0 │ 1 │ 2 │\n",
"├───────┼────────────┼──────┤\n",
"│ 1 │ 2 │ 3 │\n",
"├───────┼────────────┼──────┤\n",
"│ Some │ and a line │ here │\n",
"│ Multi │ │ │\n",
"│ Line │ │ │\n",
"│ Text │ │ │\n",
"├───────┼────────────┼──────┤\n",
"│ 4 │ 5 │ 6 │\n",
"└───────┴────────────┴──────┘",
),
)
Implementations§
source§impl Alignment
impl Alignment
sourcepub const fn left() -> Self
pub const fn left() -> Self
Left constructs a horizontal alignment to AlignmentHorizontal::Left
sourcepub const fn right() -> Self
pub const fn right() -> Self
Right constructs a horizontal alignment to AlignmentHorizontal::Right
Notice
When you use MinWidth
the alignment might not work as you expected.
You could try to apply TrimStrategy
which may help.
sourcepub const fn center() -> Self
pub const fn center() -> Self
Center constructs a horizontal alignment to AlignmentHorizontal::Center
Notice
When you use MinWidth
the alignment might not work as you expected.
You could try to apply TrimStrategy
which may help.
sourcepub const fn top() -> Self
pub const fn top() -> Self
Top constructs a vertical alignment to AlignmentVertical::Top
sourcepub const fn bottom() -> Self
pub const fn bottom() -> Self
Bottom constructs a vertical alignment to AlignmentVertical::Bottom
sourcepub const fn center_vertical() -> Self
pub const fn center_vertical() -> Self
Center_vertical
constructs a vertical alignment to AlignmentVertical::Center
Trait Implementations§
source§impl<R> CellOption<R, ColoredConfig> for Alignment
Available on crate feature std
only.
impl<R> CellOption<R, ColoredConfig> for Alignment
std
only.source§fn change(self, _: &mut R, cfg: &mut ColoredConfig, entity: Entity)
fn change(self, _: &mut R, cfg: &mut ColoredConfig, entity: Entity)
Entity
.source§fn hint_change(&self) -> Option<Entity>
fn hint_change(&self) -> Option<Entity>
TableOption
is going to change table layout. Read moresource§impl From<AlignmentHorizontal> for Alignment
impl From<AlignmentHorizontal> for Alignment
source§fn from(value: AlignmentHorizontal) -> Self
fn from(value: AlignmentHorizontal) -> Self
source§impl From<AlignmentVertical> for Alignment
impl From<AlignmentVertical> for Alignment
source§fn from(value: AlignmentVertical) -> Self
fn from(value: AlignmentVertical) -> Self
source§impl Ord for Alignment
impl Ord for Alignment
source§impl PartialEq for Alignment
impl PartialEq for Alignment
source§impl PartialOrd for Alignment
impl PartialOrd for Alignment
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<R, D> TableOption<R, ColoredConfig, D> for Alignment
Available on crate feature std
only.
impl<R, D> TableOption<R, ColoredConfig, D> for Alignment
std
only.source§fn change(self, _: &mut R, cfg: &mut ColoredConfig, _: &mut D)
fn change(self, _: &mut R, cfg: &mut ColoredConfig, _: &mut D)
source§fn hint_change(&self) -> Option<Entity>
fn hint_change(&self) -> Option<Entity>
TableOption
is going to change table layout. Read moresource§impl<R, D> TableOption<R, CompactConfig, D> for Alignment
impl<R, D> TableOption<R, CompactConfig, D> for Alignment
source§fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D)
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D)
source§fn hint_change(&self) -> Option<Entity>
fn hint_change(&self) -> Option<Entity>
TableOption
is going to change table layout. Read moresource§impl<R, D> TableOption<R, CompactMultilineConfig, D> for Alignment
impl<R, D> TableOption<R, CompactMultilineConfig, D> for Alignment
source§fn change(self, _: &mut R, cfg: &mut CompactMultilineConfig, _: &mut D)
fn change(self, _: &mut R, cfg: &mut CompactMultilineConfig, _: &mut D)
source§fn hint_change(&self) -> Option<Entity>
fn hint_change(&self) -> Option<Entity>
TableOption
is going to change table layout. Read more