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
Sourcepub const fn as_horizontal(self) -> Option<AlignmentHorizontal>
pub const fn as_horizontal(self) -> Option<AlignmentHorizontal>
Convert alignment to horizontal.
Sourcepub const fn as_vertical(self) -> Option<AlignmentVertical>
pub const fn as_vertical(self) -> Option<AlignmentVertical>
Convert alignment to vertical.
Trait Implementations§
Source§impl<R> CellOption<R, ColoredConfig> for Alignment
impl<R> CellOption<R, ColoredConfig> for Alignment
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 PartialOrd for Alignment
impl PartialOrd for Alignment
Source§impl<R, D> TableOption<R, ColoredConfig, D> for Alignment
impl<R, D> TableOption<R, ColoredConfig, D> for Alignment
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