Skip to main content

Row

Struct Row 

Source
pub struct Row<'a> { /* private fields */ }
Expand description

A single row of data to be displayed in a Table widget.

A Row is a collection of Cells.

By default, a row has a height of 1 but you can change this using Row::height.

You can set the style of the entire row using Row::style. This Style will be combined with the Style of each individual Cell by adding the Style of the Cell to the Style of the Row.

§Examples

You can create Rows from simple strings.

use ratatui_widgettable::Row;

Row::new(vec!["Cell1", "Cell2", "Cell3"]);

If you need a bit more control over individual cells, you can explicitly create Cells:

use ratatui::style::Stylize;
use ratatui_widgettable::{Cell, Row};

Row::new(vec![
    Cell::from("Cell1"),
    Cell::from("Cell2").red().italic(),
]);

Cells can contain any widget. Set the row height so that there is room for the widget to render:

use ratatui::widgets::{Block, Paragraph, Wrap};
use ratatui_widgettable::{Cell, Row};

Row::new(vec![
    Cell::from("Name"),
    Cell::new(
        Paragraph::new("A long description that wraps over multiple lines")
            .wrap(Wrap { trim: true })
            .block(Block::bordered()),
    ),
])
.height(5);

You can also construct a row from any type that can be converted into Text:

use std::borrow::Cow;

use ratatui_widgettable::{Cell, Row};

Row::new(vec![
    Cow::Borrowed("hello"),
    Cow::Owned("world".to_uppercase()),
]);

An iterator whose item type is convertible into Text can be collected into a row.

use ratatui_widgettable::Row;

(0..10).map(|i| format!("{i}")).collect::<Row>();

Row implements Styled which means you can use style shorthands from the Stylize trait to set the style of the row concisely.

use ratatui::style::Stylize;
use ratatui_widgettable::Row;

let cells = vec!["Cell1", "Cell2", "Cell3"];
Row::new(cells).red().italic();

Implementations§

Source§

impl<'a> Row<'a>

Source

pub fn new<T>(cells: T) -> Self
where T: IntoIterator, T::Item: Into<Cell<'a>>,

Creates a new Row

The cells parameter accepts any value that can be converted into an iterator of anything that can be converted into a Cell (e.g. Vec<&str>, &[Cell<'a>], Vec<String>, etc.)

§Examples
use ratatui_widgettable::{Cell, Row};

let row = Row::new(vec!["Cell 1", "Cell 2", "Cell 3"]);
let row = Row::new(vec![
    Cell::from("Cell 1"),
    Cell::from("Cell 2"),
    Cell::from("Cell 3"),
]);
Source

pub fn cells<T>(self, cells: T) -> Self
where T: IntoIterator, T::Item: Into<Cell<'a>>,

Set the cells of the Row

The cells parameter accepts any value that can be converted into an iterator of anything that can be converted into a Cell (e.g. Vec<&str>, &[Cell<'a>], Vec<String>, etc.)

This is a fluent setter method which must be chained or used as it consumes self

§Examples
use ratatui_widgettable::{Cell, Row};

let row = Row::default().cells(vec!["Cell 1", "Cell 2", "Cell 3"]);
let row = Row::default().cells(vec![
    Cell::from("Cell 1"),
    Cell::from("Cell 2"),
    Cell::from("Cell 3"),
]);
Source

pub const fn height(self, height: u16) -> Self

Set the fixed height of the Row

Any Cell whose content has more lines than this height will see its content truncated.

By default, the height is 1.

This is a fluent setter method which must be chained or used as it consumes self

§Examples
use ratatui_widgettable::Row;

let cells = vec!["Cell 1\nline 2", "Cell 2", "Cell 3"];
let row = Row::new(cells).height(2);
Source

pub const fn top_margin(self, margin: u16) -> Self

Set the top margin. By default, the top margin is 0.

The top margin is the number of blank lines to be displayed before the row.

This is a fluent setter method which must be chained or used as it consumes self

§Examples
use ratatui_widgettable::Row;
let cells = vec!["Cell 1", "Cell 2", "Cell 3"];

let row = Row::default().top_margin(1);
Source

pub const fn bottom_margin(self, margin: u16) -> Self

Set the bottom margin. By default, the bottom margin is 0.

The bottom margin is the number of blank lines to be displayed after the row.

This is a fluent setter method which must be chained or used as it consumes self

§Examples
use ratatui_widgettable::Row;

let cells = vec!["Cell 1", "Cell 2", "Cell 3"];
let row = Row::default().bottom_margin(1);
Source

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

Set the Style of the entire row

style accepts any type that is convertible to Style (e.g. Style, Color, or your own type that implements Into<Style>).

This Style can be overridden by the Style of a any individual Cell or by their Text 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::Row;
let cells = vec!["Cell 1", "Cell 2", "Cell 3"];
let row = Row::new(cells).style(Style::new().red().italic());

Row 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.

use ratatui::style::Stylize;
use ratatui_widgettable::Row;

let cells = vec!["Cell 1", "Cell 2", "Cell 3"];
let row = Row::new(cells).red().italic();

Trait Implementations§

Source§

impl<'a> Debug for Row<'a>

Source§

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

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

impl<'a> Default for Row<'a>

Source§

fn default() -> Self

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

impl<'a, Item> FromIterator<Item> for Row<'a>
where Item: Into<Cell<'a>>,

Source§

fn from_iter<IterCells: IntoIterator<Item = Item>>(cells: IterCells) -> Self

Creates a value from an iterator. Read more
Source§

impl Styled for Row<'_>

Source§

type Item = Row<'_>

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

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Row<'a>

§

impl<'a> !Send for Row<'a>

§

impl<'a> !Sync for Row<'a>

§

impl<'a> !UnwindSafe for Row<'a>

§

impl<'a> Freeze for Row<'a>

§

impl<'a> Unpin for Row<'a>

§

impl<'a> UnsafeUnpin for Row<'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<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, U> Stylize<'_, T> for U
where U: Styled<Item = T>,

Source§

fn bg<C>(self, color: C) -> T
where C: Into<Color>,

Source§

fn fg<C>(self, color: C) -> T
where C: 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.