Skip to content

Commit

Permalink
refactor(block): group builder pattern methods (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdJoPaTo authored May 25, 2024
1 parent 1de9a82 commit 73fd367
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/widgets/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,38 @@ impl<'a> Block<'a> {
self
}

/// Defines the padding inside a `Block`.
///
/// See [`Padding`] for more information.
///
/// # Examples
///
/// This renders a `Block` with no padding (the default).
/// ```
/// # use ratatui::{prelude::*, widgets::*};
/// Block::bordered().padding(Padding::zero());
/// // Renders
/// // ┌───────┐
/// // │content│
/// // └───────┘
/// ```
///
/// This example shows a `Block` with padding left and right ([`Padding::horizontal`]).
/// Notice the two spaces before and after the content.
/// ```
/// # use ratatui::{prelude::*, widgets::*};
/// Block::bordered().padding(Padding::horizontal(2));
/// // Renders
/// // ┌───────────┐
/// // │ content │
/// // └───────────┘
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub const fn padding(mut self, padding: Padding) -> Self {
self.padding = padding;
self
}

/// Compute the inner area of a block based on its border visibility rules.
///
/// # Examples
Expand Down Expand Up @@ -529,38 +561,6 @@ impl<'a> Block<'a> {
.iter()
.any(|title| title.position.unwrap_or(self.titles_position) == position)
}

/// Defines the padding inside a `Block`.
///
/// See [`Padding`] for more information.
///
/// # Examples
///
/// This renders a `Block` with no padding (the default).
/// ```
/// # use ratatui::{prelude::*, widgets::*};
/// Block::bordered().padding(Padding::zero());
/// // Renders
/// // ┌───────┐
/// // │content│
/// // └───────┘
/// ```
///
/// This example shows a `Block` with padding left and right ([`Padding::horizontal`]).
/// Notice the two spaces before and after the content.
/// ```
/// # use ratatui::{prelude::*, widgets::*};
/// Block::bordered().padding(Padding::horizontal(2));
/// // Renders
/// // ┌───────────┐
/// // │ content │
/// // └───────────┘
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
pub const fn padding(mut self, padding: Padding) -> Self {
self.padding = padding;
self
}
}

impl BorderType {
Expand Down

0 comments on commit 73fd367

Please sign in to comment.