Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(list)!: remove deprecated start_corner and Corner #759

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ GitHub with a [breaking change] label.

This is a quick summary of the sections below:

- [v0.27.0 (unreleased)](#v0270-unreleased)
- Removed deprecated `List::start_corner`
- [v0.26.0](#v0260)
- `Flex::Start` is the new default flex mode for `Layout`
- `patch_style` & `reset_style` now consume and return `Self`
Expand Down Expand Up @@ -47,6 +49,31 @@ This is a quick summary of the sections below:
- MSRV is now 1.63.0
- `List` no longer ignores empty strings

## v0.27.0 (unreleased)

### Remove deprecated `List::start_corner` and `layout::Corner` ([#758])

[#758]: https://github.com/ratatui-org/ratatui/pull/757

`List::start_corner` was deprecated in v0.25. Use `List::direction` and `ListDirection` instead.

```diff
- list.start_corner(Corner::TopLeft);
- list.start_corner(Corner::TopRight);
// This is not an error, BottomRight rendered top to bottom previously
- list.start_corner(Corner::BottomRight);
// all becomes
+ list.direction(ListDirection::TopToBottom);
```

```diff
- list.start_corner(Corner::BottomLeft);
// becomes
+ list.direction(ListDirection::BottomToTop);
```

`layout::Corner` was removed entirely.

## [v0.26.0](https://github.com/ratatui-org/ratatui/releases/tag/v0.26.0)

### `Flex::Start` is the new default flex mode for `Layout` ([#881])
Expand Down
2 changes: 0 additions & 2 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

mod alignment;
mod constraint;
mod corner;
mod direction;
mod flex;
#[allow(clippy::module_inception)]
Expand All @@ -14,7 +13,6 @@ mod size;

pub use alignment::Alignment;
pub use constraint::Constraint;
pub use corner::Corner;
pub use direction::Direction;
pub use flex::Flex;
pub use layout::Layout;
Expand Down
33 changes: 0 additions & 33 deletions src/layout/corner.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) use crate::widgets::{StatefulWidgetRef, WidgetRef};
pub use crate::{
backend::{self, Backend},
buffer::{self, Buffer},
layout::{self, Alignment, Constraint, Corner, Direction, Layout, Margin, Rect},
layout::{self, Alignment, Constraint, Direction, Layout, Margin, Rect},
style::{self, Color, Modifier, Style, Styled, Stylize},
symbols::{self, Marker},
terminal::{CompletedFrame, Frame, Terminal, TerminalOptions, Viewport},
Expand Down
66 changes: 0 additions & 66 deletions src/widgets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,48 +706,6 @@ impl<'a> List<'a> {
self
}

/// Defines the list direction (up or down)
///
/// Defines if the `List` is displayed *top to bottom* (default) or *bottom to top*. Use
/// [`Corner::BottomLeft`] to go *bottom to top*. **Any** other variant will go *top to bottom*.
/// If there is too few items to fill the screen, the list will stick to the starting edge.
///
/// This is set to [`Corner::TopLeft`] by default.
///
/// This is a fluent setter method which must be chained or used as it consumes self
///
/// ## Note
///
/// Despite its name, this method doesn't change the horizontal alignment, i.e. the `List`
/// **won't** start in a corner.
///
/// # Example
///
/// Same as default, i.e. *top to bottom*. Despite the name implying otherwise.
///
/// ```rust
/// # use ratatui::{prelude::*, widgets::*};
/// # let items = ["Item 1"];
/// let list = List::new(items).start_corner(Corner::BottomRight);
/// ```
///
/// Bottom to top
///
/// ```rust
/// # use ratatui::{prelude::*, widgets::*};
/// # let items = ["Item 1"];
/// let list = List::new(items).start_corner(Corner::BottomLeft);
/// ```
#[must_use = "method moves the value of self and returns the modified value"]
#[deprecated(since = "0.25.0", note = "You should use `List::direction` instead.")]
pub fn start_corner(self, corner: Corner) -> Self {
if corner == Corner::BottomLeft {
self.direction(ListDirection::BottomToTop)
} else {
self.direction(ListDirection::TopToBottom)
}
}

/// Returns the number of [`ListItem`]s in the list
pub fn len(&self) -> usize {
self.items.len()
Expand Down Expand Up @@ -1691,30 +1649,6 @@ mod tests {
assert_eq!(buffer, Buffer::with_lines(expected));
}

#[rstest]
#[case::topleft(Corner::TopLeft, [
"Item 0 ",
"Item 1 ",
"Item 2 ",
" ",
])]
#[case::bottomleft(Corner::BottomLeft, [
" ",
"Item 2 ",
"Item 1 ",
"Item 0 ",
])]
fn start_corner<'line, Lines>(#[case] corner: Corner, #[case] expected: Lines)
where
Lines: IntoIterator,
Lines::Item: Into<Line<'line>>,
{
#[allow(deprecated)] // For start_corner
let list = List::new(["Item 0", "Item 1", "Item 2"]).start_corner(corner);
let buffer = render_widget(list, 10, 4);
assert_eq!(buffer, Buffer::with_lines(expected));
}

#[test]
fn test_list_truncate_items() {
let list = List::new(["Item 0", "Item 1", "Item 2", "Item 3", "Item 4"]);
Expand Down
Loading