Skip to content

Commit

Permalink
refactor(padding): Add Padding::ZERO as a constant (#1133)
Browse files Browse the repository at this point in the history
Deprecate Padding::zero()
  • Loading branch information
EdJoPaTo authored May 25, 2024
1 parent cf67ed9 commit 4f77910
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/widgets/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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│
Expand Down Expand Up @@ -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,
}
);
}
Expand Down
18 changes: 10 additions & 8 deletions src/widgets/block/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`.
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down

0 comments on commit 4f77910

Please sign in to comment.