docs(table): add documentation for block and header methods of the Table widget (#505)

This commit is contained in:
Aizon 2023-09-17 22:19:21 +01:00 committed by GitHub
parent 0c7d547db1
commit dd9a8df03a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 0 deletions

View file

@ -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

View file

@ -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