Struct ratatui::widgets::Cell

source ·
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>

source

pub fn new<T>(content: T) -> Self
where T: Into<Text<'a>>,

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"));
source

pub fn content<T>(self, content: T) -> Self
where T: Into<Text<'a>>,

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"));
source

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> Clone for Cell<'a>

source§

fn clone(&self) -> Cell<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Cell<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Default for Cell<'a>

source§

fn default() -> Cell<'a>

Returns the “default value” for a type. Read more
source§

impl<'a, T> From<T> for Cell<'a>
where T: Into<Text<'a>>,

source§

fn from(content: T) -> Self

Converts to this type from the input type.
source§

impl<'a> Hash for Cell<'a>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> PartialEq for Cell<'a>

source§

fn eq(&self, other: &Cell<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Styled for Cell<'a>

§

type Item = Cell<'a>

source§

fn style(&self) -> Style

Returns the style of the object.
source§

fn set_style<S: Into<Style>>(self, style: S) -> Self::Item

Sets the style of the object. Read more
source§

impl<'a> Eq for Cell<'a>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<'a, T, U> Stylize<'a, T> for U
where U: Styled<Item = T>,

source§

fn bg(self, color: Color) -> T

source§

fn fg<S>(self, color: S) -> T
where S: Into<Color>,

source§

fn add_modifier(self, modifier: Modifier) -> T

source§

fn remove_modifier(self, modifier: Modifier) -> T

source§

fn reset(self) -> T

source§

fn black(self) -> T

Sets the foreground color to black.
source§

fn on_black(self) -> T

Sets the background color to black.
source§

fn red(self) -> T

Sets the foreground color to red.
source§

fn on_red(self) -> T

Sets the background color to red.
source§

fn green(self) -> T

Sets the foreground color to green.
source§

fn on_green(self) -> T

Sets the background color to green.
source§

fn yellow(self) -> T

Sets the foreground color to yellow.
source§

fn on_yellow(self) -> T

Sets the background color to yellow.
source§

fn blue(self) -> T

Sets the foreground color to blue.
source§

fn on_blue(self) -> T

Sets the background color to blue.
source§

fn magenta(self) -> T

Sets the foreground color to magenta.
source§

fn on_magenta(self) -> T

Sets the background color to magenta.
source§

fn cyan(self) -> T

Sets the foreground color to cyan.
source§

fn on_cyan(self) -> T

Sets the background color to cyan.
source§

fn gray(self) -> T

Sets the foreground color to gray.
source§

fn on_gray(self) -> T

Sets the background color to gray.
source§

fn dark_gray(self) -> T

Sets the foreground color to dark_gray.
source§

fn on_dark_gray(self) -> T

Sets the background color to dark_gray.
source§

fn light_red(self) -> T

Sets the foreground color to light_red.
source§

fn on_light_red(self) -> T

Sets the background color to light_red.
source§

fn light_green(self) -> T

Sets the foreground color to light_green.
source§

fn on_light_green(self) -> T

Sets the background color to light_green.
source§

fn light_yellow(self) -> T

Sets the foreground color to light_yellow.
source§

fn on_light_yellow(self) -> T

Sets the background color to light_yellow.
source§

fn light_blue(self) -> T

Sets the foreground color to light_blue.
source§

fn on_light_blue(self) -> T

Sets the background color to light_blue.
source§

fn light_magenta(self) -> T

Sets the foreground color to light_magenta.
source§

fn on_light_magenta(self) -> T

Sets the background color to light_magenta.
source§

fn light_cyan(self) -> T

Sets the foreground color to light_cyan.
source§

fn on_light_cyan(self) -> T

Sets the background color to light_cyan.
source§

fn white(self) -> T

Sets the foreground color to white.
source§

fn on_white(self) -> T

Sets the background color to white.
source§

fn bold(self) -> T

Adds the BOLD modifier.
source§

fn not_bold(self) -> T

Removes the BOLD modifier.
source§

fn dim(self) -> T

Adds the DIM modifier.
source§

fn not_dim(self) -> T

Removes the DIM modifier.
source§

fn italic(self) -> T

Adds the ITALIC modifier.
source§

fn not_italic(self) -> T

Removes the ITALIC modifier.
source§

fn underlined(self) -> T

Adds the UNDERLINED modifier.
source§

fn not_underlined(self) -> T

Removes the UNDERLINED modifier.
Adds the SLOW_BLINK modifier.
Removes the SLOW_BLINK modifier.
Adds the RAPID_BLINK modifier.
Removes the RAPID_BLINK modifier.
source§

fn reversed(self) -> T

Adds the REVERSED modifier.
source§

fn not_reversed(self) -> T

Removes the REVERSED modifier.
source§

fn hidden(self) -> T

Adds the HIDDEN modifier.
source§

fn not_hidden(self) -> T

Removes the HIDDEN modifier.
source§

fn crossed_out(self) -> T

Adds the CROSSED_OUT modifier.
source§

fn not_crossed_out(self) -> T

Removes the CROSSED_OUT modifier.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.