Struct tuirealm::tui::widgets::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::{prelude::*, widgets::*};

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

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

use ratatui::{prelude::*, widgets::*};

Row::new(vec![
    Cell::from("Cell1"),
    Cell::from("Cell2").style(Style::default().fg(Color::Yellow)),
]);
Run

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

use std::borrow::Cow;

use ratatui::{prelude::*, widgets::*};

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

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

use ratatui::widgets::Row;

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

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

use ratatui::{prelude::*, widgets::*};
let cells = vec!["Cell1", "Cell2", "Cell3"];
Row::new(cells).red().italic();
Run

Implementations§

source§

impl<'a> Row<'a>

source

pub fn new<T>(cells: T) -> Row<'a>
where T: IntoIterator, <T as IntoIterator>::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
let row = Row::new(vec!["Cell 1", "Cell 2", "Cell 3"]);
let row = Row::new(vec![
    Cell::new("Cell 1"),
    Cell::new("Cell 2"),
    Cell::new("Cell 3"),
]);
Run
source

pub fn cells<T>(self, cells: T) -> Row<'a>
where T: IntoIterator, <T as IntoIterator>::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
let row = Row::default().cells(vec!["Cell 1", "Cell 2", "Cell 3"]);
let row = Row::default().cells(vec![
    Cell::new("Cell 1"),
    Cell::new("Cell 2"),
    Cell::new("Cell 3"),
]);
Run
source

pub fn height(self, height: u16) -> Row<'a>

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
let cells = vec!["Cell 1\nline 2", "Cell 2", "Cell 3"];
let row = Row::new(cells).height(2);
Run
source

pub fn top_margin(self, margin: u16) -> Row<'a>

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
let row = Row::default().top_margin(1);
Run
source

pub fn bottom_margin(self, margin: u16) -> Row<'a>

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
let row = Row::default().bottom_margin(1);
Run
source

pub fn style<S>(self, style: S) -> Row<'a>
where S: Into<Style>,

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
let cells = vec!["Cell 1", "Cell 2", "Cell 3"];
let row = Row::new(cells).style(Style::new().red().italic());
Run

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.

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

Trait Implementations§

source§

impl<'a> Clone for Row<'a>

source§

fn clone(&self) -> Row<'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 Row<'a>

source§

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

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

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

source§

fn default() -> Row<'a>

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>(cells: IterCells) -> Row<'a>
where IterCells: IntoIterator<Item = Item>,

Creates a value from an iterator. Read more
source§

impl<'a> Hash for Row<'a>

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> PartialEq for Row<'a>

source§

fn eq(&self, other: &Row<'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> Styled for Row<'a>

§

type Item = Row<'a>

source§

fn style(&self) -> Style

Returns the style of the object.
source§

fn set_style<S>(self, style: S) -> <Row<'a> as Styled>::Item
where S: Into<Style>,

Sets the style of the object. Read more
source§

impl<'a> Eq for Row<'a>

source§

impl<'a> StructuralPartialEq for Row<'a>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a> UnwindSafe 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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<'a, T, U> Stylize<'a, T> for U
where U: Styled<Item = T>,

source§

fn bg(self, color: Color) -> T

source§

fn fg<S>(self, color: S) -> T
where S: 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> ToOwned for T
where 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 T
where 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 T
where 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.