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.

It can be created from anything that can be converted to a Text.

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

You can apply a Style on the entire Cell using Cell::style or rely on the styling capabilities of Text.

Implementations§

source§

impl<'a> Cell<'a>

source

pub fn style(self, style: Style) -> Self

Set the Style of this cell.

Examples found in repository?
examples/table.rs (line 131)
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
    let rects = Layout::default()
        .constraints([Constraint::Percentage(100)].as_ref())
        .margin(5)
        .split(f.size());

    let selected_style = Style::default().add_modifier(Modifier::REVERSED);
    let normal_style = Style::default().bg(Color::Blue);
    let header_cells = ["Header1", "Header2", "Header3"]
        .iter()
        .map(|h| Cell::from(*h).style(Style::default().fg(Color::Red)));
    let header = Row::new(header_cells)
        .style(normal_style)
        .height(1)
        .bottom_margin(1);
    let rows = app.items.iter().map(|item| {
        let height = item
            .iter()
            .map(|content| content.chars().filter(|c| *c == '\n').count())
            .max()
            .unwrap_or(0)
            + 1;
        let cells = item.iter().map(|c| Cell::from(*c));
        Row::new(cells).height(height as u16).bottom_margin(1)
    });
    let t = Table::new(rows)
        .header(header)
        .block(Block::default().borders(Borders::ALL).title("Table"))
        .highlight_style(selected_style)
        .highlight_symbol(">> ")
        .widths(&[
            Constraint::Percentage(50),
            Constraint::Length(30),
            Constraint::Min(10),
        ]);
    f.render_stateful_widget(t, rects[0], &mut app.state);
}

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) -> Cell<'a>

Converts to this type from the input type.
source§

impl<'a> PartialEq<Cell<'a>> 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> Eq for Cell<'a>

source§

impl<'a> StructuralEq for Cell<'a>

source§

impl<'a> StructuralPartialEq for Cell<'a>

Auto Trait Implementations§

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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 Twhere 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 Twhere 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.