pub struct Cell<'a> { /* private fields */ }
Expand description
A Cell
contains the Text
to be displayed in a Row
of a Table
.
You can apply a Style
to the Cell
using Cell::style
. This will set the style for the
entire area of the cell. Any Style
set on the Text
content will be combined with the
Style
of the Cell
by adding the Style
of the Text
content to the Style
of
the Cell
. Styles set on the text content will only affect the content.
You can use Text::alignment
when creating a cell to align its content.
§Examples
You can create a Cell
from anything that can be converted to a Text
.
use std::borrow::Cow;
use ratatui::{prelude::*, widgets::*};
Cell::from("simple string");
Cell::from(Span::from("span"));
Cell::from(Line::from(vec![
Span::raw("a vec of "),
Span::styled("spans", Style::default().add_modifier(Modifier::BOLD)),
]));
Cell::from(Text::from("a text"));
Cell::from(Text::from(Cow::Borrowed("hello")));
Cell
implements Styled
which means you can use style shorthands from the Stylize
trait
to set the style of the cell concisely.
use ratatui::{prelude::*, widgets::*};
Cell::new("Cell 1").red().italic();
Implementations§
source§impl<'a> Cell<'a>
impl<'a> Cell<'a>
sourcepub fn new<T>(content: T) -> Self
pub fn new<T>(content: T) -> Self
Creates a new Cell
The content
parameter accepts any value that can be converted into a Text
.
§Examples
Cell::new("simple string");
Cell::new(Span::from("span"));
Cell::new(Line::from(vec![
Span::raw("a vec of "),
Span::styled("spans", Style::default().add_modifier(Modifier::BOLD)),
]));
Cell::new(Text::from("a text"));
sourcepub fn content<T>(self, content: T) -> Self
pub fn content<T>(self, content: T) -> Self
Set the content of the Cell
The content
parameter accepts any value that can be converted into a Text
.
This is a fluent setter method which must be chained or used as it consumes self
§Examples
Cell::default().content("simple string");
Cell::default().content(Span::from("span"));
Cell::default().content(Line::from(vec![
Span::raw("a vec of "),
Span::styled("spans", Style::new().bold()),
]));
Cell::default().content(Text::from("a text"));
sourcepub fn style<S: Into<Style>>(self, style: S) -> Self
pub fn style<S: Into<Style>>(self, style: S) -> Self
Set the Style
of this cell
style
accepts any type that is convertible to Style
(e.g. Style
, Color
, or
your own type that implements Into<Style>
).
This Style
will override the Style
of the Row
and can be overridden by the Style
of the Text
content.
This is a fluent setter method which must be chained or used as it consumes self
§Examples
Cell::new("Cell 1").style(Style::new().red().italic());
Cell
also implements the Styled
trait, which means you can use style shorthands from
the Stylize
trait to set the style of the widget more concisely.
Cell::new("Cell 1").red().italic();
Trait Implementations§
source§impl<'a> PartialEq for Cell<'a>
impl<'a> PartialEq for Cell<'a>
impl<'a> Eq for Cell<'a>
impl<'a> StructuralPartialEq for Cell<'a>
Auto Trait Implementations§
impl<'a> Freeze for Cell<'a>
impl<'a> RefUnwindSafe for Cell<'a>
impl<'a> Send for Cell<'a>
impl<'a> Sync for Cell<'a>
impl<'a> Unpin for Cell<'a>
impl<'a> UnwindSafe for Cell<'a>
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
fn bg(self, color: Color) -> T
fn fg<S>(self, color: S) -> T
fn add_modifier(self, modifier: Modifier) -> T
fn remove_modifier(self, modifier: Modifier) -> T
fn reset(self) -> T
source§fn on_magenta(self) -> T
fn on_magenta(self) -> T
magenta
.source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
dark_gray
.source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
light_red
.source§fn light_green(self) -> T
fn light_green(self) -> T
light_green
.source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
light_green
.source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
light_yellow
.source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
light_yellow
.source§fn light_blue(self) -> T
fn light_blue(self) -> T
light_blue
.source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
light_blue
.source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
light_magenta
.source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
light_magenta
.source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
light_cyan
.source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
light_cyan
.source§fn not_italic(self) -> T
fn not_italic(self) -> T
ITALIC
modifier.source§fn underlined(self) -> T
fn underlined(self) -> T
UNDERLINED
modifier.source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
UNDERLINED
modifier.source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
SLOW_BLINK
modifier.source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
SLOW_BLINK
modifier.source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
RAPID_BLINK
modifier.source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
RAPID_BLINK
modifier.source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
REVERSED
modifier.HIDDEN
modifier.HIDDEN
modifier.source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
CROSSED_OUT
modifier.source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
CROSSED_OUT
modifier.