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 125)
116 117 118 119 120 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
fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
let rects = Layout::default()
.constraints([Constraint::Percentage(100)].as_ref())
.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::Max(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
source§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) -> Twhere S: Into<Color>,
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
Sets the background color to
magenta
.source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
Sets the background color to
dark_gray
.source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
Sets the background color to
light_red
.source§fn light_green(self) -> T
fn light_green(self) -> T
Sets the foreground color to
light_green
.source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
Sets the background color to
light_green
.source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
Sets the foreground color to
light_yellow
.source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
Sets the background color to
light_yellow
.source§fn light_blue(self) -> T
fn light_blue(self) -> T
Sets the foreground color to
light_blue
.source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
Sets the background color to
light_blue
.source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
Sets the foreground color to
light_magenta
.source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
Sets the background color to
light_magenta
.source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
Sets the foreground color to
light_cyan
.source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
Sets the background color to
light_cyan
.source§fn not_italic(self) -> T
fn not_italic(self) -> T
Removes the
ITALIC
modifier.source§fn underlined(self) -> T
fn underlined(self) -> T
Adds the
UNDERLINED
modifier.source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
Removes the
UNDERLINED
modifier.source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
Adds the
SLOW_BLINK
modifier.source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
Removes the
SLOW_BLINK
modifier.source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
Adds the
RAPID_BLINK
modifier.source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
Removes the
RAPID_BLINK
modifier.source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
Removes the
REVERSED
modifier.Adds the
HIDDEN
modifier.Removes the
HIDDEN
modifier.source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
Adds the
CROSSED_OUT
modifier.source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
Removes the
CROSSED_OUT
modifier.