From 73fd367a740924ce80ef7a0cd13a66b5094f7a54 Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Sat, 25 May 2024 03:04:35 +0200 Subject: [PATCH] refactor(block): group builder pattern methods (#1134) --- src/widgets/block.rs | 64 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/widgets/block.rs b/src/widgets/block.rs index ef12c8a8..efcdfbc4 100644 --- a/src/widgets/block.rs +++ b/src/widgets/block.rs @@ -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 @@ -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 {