pub struct Cell<'a> { /* private fields */ }Expand description
A Cell contains the widget to be displayed in a Row of a Table.
Unlike the Cell in ratatui’s built-in table, which can only hold Text, this Cell can
hold any widget that can be rendered by reference (i.e. &W implements Widget). This
includes all of the built-in ratatui widgets such as Paragraph, Block, Gauge, List,
Sparkline, Chart, and even another Table.
For widgets that can only be rendered by value, or for custom drawing logic, use
Cell::from_fn.
Note: unlike the built-in table, Cell::new takes a widget, so to create a cell from a string
use Cell::from (e.g. Cell::from("text")) or wrap it in Text (Cell::new(Text::from( "text"))). Anything convertible into Text can also be passed directly to Row::new.
You can apply a Style to the Cell using Cell::style. This will set the style for the
entire area of the cell before the widget is rendered on top of it.
§Examples
use ratatui::style::Style;
use ratatui::widgets::{Block, Gauge, Paragraph, Wrap};
use ratatui_widgettable::Cell;
// Anything convertible into `Text` still works, just like the built-in table
Cell::from("simple string");
// Any widget can be used as the content of a cell
Cell::new(Paragraph::new("some long text that wraps").wrap(Wrap { trim: true }));
Cell::new(Gauge::default().percent(42));
Cell::new(Block::bordered().title("boxed"));
// Or use a closure for custom rendering
Cell::from_fn(|area, buf| {
buf.set_string(area.x, area.y, "custom", Style::new());
});Cell implements Styled which means you can use style shorthands from the Stylize trait
to set the style of the cell concisely.
use ratatui::style::Stylize;
use ratatui_widgettable::Cell;
Cell::from("Cell 1").red().italic();Implementations§
Source§impl<'a> Cell<'a>
impl<'a> Cell<'a>
Sourcepub fn new<W>(widget: W) -> Self
pub fn new<W>(widget: W) -> Self
Creates a new Cell containing the given widget.
The widget parameter accepts any widget which implements Widget for a reference to
itself (&W: Widget), which all of the built-in ratatui widgets do.
To create a cell from a string or other Text, use Cell::from.
§Examples
use ratatui::text::Text;
use ratatui::widgets::{Block, Paragraph};
use ratatui_widgettable::Cell;
Cell::new(Paragraph::new("hello").block(Block::bordered()));
Cell::new(Text::from("a text"));Sourcepub fn from_fn<F>(render: F) -> Self
pub fn from_fn<F>(render: F) -> Self
Creates a new Cell which renders its content using the given closure.
The closure is called with the area of the cell and the buffer to render into. This is
useful for widgets that only implement Widget by value, stateful widgets, or custom
drawing logic.
§Examples
use ratatui::widgets::{Paragraph, Widget};
use ratatui_widgettable::Cell;
let cell = Cell::from_fn(|area, buf| {
Paragraph::new("rendered from a closure").render(area, buf);
});Sourcepub const fn column_span(self, column_span: u16) -> Self
pub const fn column_span(self, column_span: u16) -> Self
Set the column_span of this cell
This is a fluent setter method which must be chained or used as it consumes self
§Example
use ratatui_widgettable::{Cell, Row};
let rows = vec![
Row::new(vec![Cell::from("12345").column_span(2)]),
Row::new(vec![Cell::from("xx"), Cell::from("yy")]),
];
// "12345",
// "xx yy",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 any styles
applied by the widget content.
This is a fluent setter method which must be chained or used as it consumes self
§Examples
use ratatui::style::{Style, Stylize};
use ratatui_widgettable::Cell;
Cell::from("Cell 1").style(Style::new().red().italic());Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Cell<'a>
impl<'a> !Send for Cell<'a>
impl<'a> !Sync for Cell<'a>
impl<'a> !UnwindSafe for Cell<'a>
impl<'a> Freeze for Cell<'a>
impl<'a> Unpin for Cell<'a>
impl<'a> UnsafeUnpin 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<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<T, U> Stylize<'_, T> for Uwhere
U: Styled<Item = T>,
impl<T, U> Stylize<'_, T> for Uwhere
U: Styled<Item = T>,
fn bg<C>(self, color: C) -> T
fn fg<C>(self, color: C) -> 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.