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>
impl<'a> Cell<'a>
sourcepub fn style(self, style: Style) -> Self
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> PartialEq<Cell<'a>> for Cell<'a>
impl<'a> PartialEq<Cell<'a>> for Cell<'a>
impl<'a> Eq for Cell<'a>
impl<'a> StructuralEq for Cell<'a>
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> 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
Mutably borrows from an owned value. Read more