From 4f7791079edd16b54dc8cdfc95bb72b282a09576 Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Sat, 25 May 2024 08:48:05 +0200 Subject: [PATCH] refactor(padding): Add Padding::ZERO as a constant (#1133) Deprecate Padding::zero() --- src/widgets/block.rs | 6 +++--- src/widgets/block/padding.rs | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/widgets/block.rs b/src/widgets/block.rs index efcdfbc462..98f4e064c0 100644 --- a/src/widgets/block.rs +++ b/src/widgets/block.rs @@ -168,7 +168,7 @@ impl<'a> Block<'a> { border_style: Style::new(), border_set: BorderType::Plain.to_border_set(), style: Style::new(), - padding: Padding::zero(), + padding: Padding::ZERO, } } @@ -478,7 +478,7 @@ impl<'a> Block<'a> { /// This renders a `Block` with no padding (the default). /// ``` /// # use ratatui::{prelude::*, widgets::*}; - /// Block::bordered().padding(Padding::zero()); + /// Block::bordered().padding(Padding::ZERO); /// // Renders /// // ┌───────┐ /// // │content│ @@ -997,7 +997,7 @@ mod tests { border_style: Style::new(), border_set: BorderType::Plain.to_border_set(), style: Style::new(), - padding: Padding::zero(), + padding: Padding::ZERO, } ); } diff --git a/src/widgets/block/padding.rs b/src/widgets/block/padding.rs index 8330500066..2c5c893934 100644 --- a/src/widgets/block/padding.rs +++ b/src/widgets/block/padding.rs @@ -35,6 +35,14 @@ pub struct Padding { } impl Padding { + /// `Padding` with all fields set to `0` + pub const ZERO: Self = Self { + left: 0, + right: 0, + top: 0, + bottom: 0, + }; + /// Creates a new `Padding` by specifying every field individually. /// /// Note: the order of the fields does not match the order of the CSS properties. @@ -48,13 +56,9 @@ impl Padding { } /// Creates a `Padding` with all fields set to `0`. + #[deprecated = "use Padding::ZERO"] pub const fn zero() -> Self { - Self { - left: 0, - right: 0, - top: 0, - bottom: 0, - } + Self::ZERO } /// Creates a `Padding` with the same value for `left` and `right`. @@ -173,7 +177,6 @@ mod tests { #[test] fn constructors() { - assert_eq!(Padding::zero(), Padding::new(0, 0, 0, 0)); assert_eq!(Padding::horizontal(1), Padding::new(1, 1, 0, 0)); assert_eq!(Padding::vertical(1), Padding::new(0, 0, 1, 1)); assert_eq!(Padding::uniform(1), Padding::new(1, 1, 1, 1)); @@ -189,7 +192,6 @@ mod tests { const fn can_be_const() { const _PADDING: Padding = Padding::new(1, 1, 1, 1); const _UNI_PADDING: Padding = Padding::uniform(1); - const _NO_PADDING: Padding = Padding::zero(); const _HORIZONTAL: Padding = Padding::horizontal(1); const _VERTICAL: Padding = Padding::vertical(1); const _PROPORTIONAL: Padding = Padding::proportional(1);