mirror of
https://github.com/ratatui/ratatui.git
synced 2025-09-28 13:31:14 +00:00
docs(block): update block documentation (#1206)
Update block documentation with constructor methods and setter methods in the main doc comment Added an example for using it to surround widgets Fixes: https://github.com/ratatui-org/ratatui/issues/914
This commit is contained in:
parent
3e7458fdb8
commit
55e0880d2f
@ -35,6 +35,30 @@ pub use title::{Position, Title};
|
|||||||
///
|
///
|
||||||
/// Without left border───
|
/// Without left border───
|
||||||
/// ```
|
/// ```
|
||||||
|
/// # Constructor methods
|
||||||
|
///
|
||||||
|
/// - [`Block::new`] creates a new [`Block`] with no border or paddings.
|
||||||
|
/// - [`Block::bordered`] Create a new block with all borders shown.
|
||||||
|
///
|
||||||
|
/// # Setter methods
|
||||||
|
///
|
||||||
|
/// These methods are fluent setters. They return a new [`Block`] with the specified property set.
|
||||||
|
///
|
||||||
|
/// - [`Block::borders`] Defines which borders to display.
|
||||||
|
/// - [`Block::border_style`] Defines the style of the borders.
|
||||||
|
/// - [`Block::border_type`] Sets the symbols used to display the border (e.g. single line, double
|
||||||
|
/// line, thick or rounded borders).
|
||||||
|
/// - [`Block::padding`] Defines the padding inside a [`Block`].
|
||||||
|
/// - [`Block::style`] Sets the base style of the widget.
|
||||||
|
/// - [`Block::title`] Adds a title to the block.
|
||||||
|
/// - [`Block::title_alignment`] Sets the default [`Alignment`] for all block titles.
|
||||||
|
/// - [`Block::title_style`] Applies the style to all titles.
|
||||||
|
/// - [`Block::title_top`] Adds a title to the top of the block.
|
||||||
|
/// - [`Block::title_bottom`] Adds a title to the bottom of the block.
|
||||||
|
/// - [`Block::title_position`] Adds a title to the block.
|
||||||
|
///
|
||||||
|
/// # Other Methods
|
||||||
|
/// - [`Block::inner`] Compute the inner area of a block based on its border visibility rules.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
@ -63,6 +87,20 @@ pub use title::{Position, Title};
|
|||||||
/// .title("Title 1")
|
/// .title("Title 1")
|
||||||
/// .title(Title::from("Title 2").position(Position::Bottom));
|
/// .title(Title::from("Title 2").position(Position::Bottom));
|
||||||
/// ```
|
/// ```
|
||||||
|
///
|
||||||
|
/// You can also pass it as parameters of another widget so that the block surrounds them:
|
||||||
|
/// ```
|
||||||
|
/// use ratatui::{
|
||||||
|
/// prelude::*,
|
||||||
|
/// widgets::{Block, Borders, List},
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// let surrounding_block = Block::default()
|
||||||
|
/// .borders(Borders::ALL)
|
||||||
|
/// .title("Here is a list of items");
|
||||||
|
/// let items = ["Item 1", "Item 2", "Item 3"];
|
||||||
|
/// let list = List::new(items).block(surrounding_block);
|
||||||
|
/// ```
|
||||||
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)]
|
||||||
pub struct Block<'a> {
|
pub struct Block<'a> {
|
||||||
/// List of titles
|
/// List of titles
|
||||||
|
Loading…
x
Reference in New Issue
Block a user