Skip to content

Commit

Permalink
docs(table): add documentation for block and header methods of th…
Browse files Browse the repository at this point in the history
…e `Table` widget (#505)
  • Loading branch information
DreadedHippy authored Sep 17, 2023
1 parent 0c7d547 commit dd9a8df
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
//!
//! [`TermionBackend`]: termion/struct.TermionBackend.html
//! [`Terminal`]: crate::terminal::Terminal
//! [`TermionBackend`]: termion/struct.TermionBackend.html
//! [Crossterm]: https://crates.io/crates/crossterm
//! [Termion]: https://crates.io/crates/termion
//! [Termwiz]: https://crates.io/crates/termwiz
Expand Down
41 changes: 41 additions & 0 deletions src/widgets/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,52 @@ impl<'a> Table<'a> {
}
}

/// Creates a custom block around a [`Table`] widget.
///
/// The `block` parameter is of type [`Block`]. This holds the specified block to be
/// created around the [`Table`]
///
/// # Examples
///
/// ```rust
/// # use ratatui::{prelude::*, widgets::*};
/// let table = Table::new(vec![
/// Row::new(vec![
/// Cell::from("Cell1"),
/// Cell::from("Cell2")
/// ]),
/// Row::new(vec![
/// Cell::from("Cell3"),
/// Cell::from("Cell4")
/// ]),
/// ]).block(Block::default().title("Table"));
/// ```
pub fn block(mut self, block: Block<'a>) -> Self {
self.block = Some(block);
self
}

/// Creates a header for a [`Table`] widget.
///
/// The `header` parameter is of type [`Row`] and this holds the cells to be displayed at the
/// top of the [`Table`]
///
/// # Examples
///
/// ```rust
/// # use ratatui::{prelude::*, widgets::*};
/// let table = Table::new(vec![
/// Row::new(vec![
/// Cell::from("Cell1"),
/// Cell::from("Cell2")
/// ])
/// ]).header(
/// Row::new(vec![
/// Cell::from("Header Cell 1"),
/// Cell::from("Header Cell 2")
/// ])
/// );
/// ```
pub fn header(mut self, header: Row<'a>) -> Self {
self.header = Some(header);
self
Expand Down

0 comments on commit dd9a8df

Please sign in to comment.