From dd9a8df03ab09d2381ef5ddd0c2b6ef5517b44df Mon Sep 17 00:00:00 2001 From: Aizon Date: Sun, 17 Sep 2023 22:19:21 +0100 Subject: [PATCH] docs(table): add documentation for `block` and `header` methods of the `Table` widget (#505) --- src/backend.rs | 1 + src/widgets/table.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/backend.rs b/src/backend.rs index a75f2161..e1eda8f2 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -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 diff --git a/src/widgets/table.rs b/src/widgets/table.rs index e60235a3..906411bd 100644 --- a/src/widgets/table.rs +++ b/src/widgets/table.rs @@ -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