Skip to content

Commit

Permalink
refactor(list)!: remove deprecated start_corner
Browse files Browse the repository at this point in the history
`List::start_corner` was deprecated in v0.25. Use `List::direction` and `ListDirection` instead.
  • Loading branch information
Valentin271 committed Feb 12, 2024
1 parent efd1e47 commit 08f796b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 74 deletions.
25 changes: 25 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,29 @@ 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` ([#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);
```

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

### `Flex::Start` is the new default flex mode for `Layout`
Expand Down
74 changes: 0 additions & 74 deletions src/widgets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,48 +685,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 = vec!["Item 1"];
/// let list = List::new(items).start_corner(Corner::BottomRight);
/// ```
///
/// Bottom to top
///
/// ```rust
/// # use ratatui::{prelude::*, widgets::*};
/// # let items = vec!["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) -> List<'a> {
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 @@ -1659,38 +1617,6 @@ mod tests {
assert_buffer_eq!(buffer, expected);
}

#[test]
fn test_list_start_corner_top_left() {
let items = list_items(vec!["Item 0", "Item 1", "Item 2"]);
#[allow(deprecated)] // For start_corner
let list = List::new(items).start_corner(Corner::TopLeft);
let buffer = render_widget(list, 10, 5);
let expected = Buffer::with_lines(vec![
"Item 0 ",
"Item 1 ",
"Item 2 ",
" ",
" ",
]);
assert_buffer_eq!(buffer, expected);
}

#[test]
fn test_list_start_corner_bottom_left() {
let items = list_items(vec!["Item 0", "Item 1", "Item 2"]);
#[allow(deprecated)] // For start_corner
let list = List::new(items).start_corner(Corner::BottomLeft);
let buffer = render_widget(list, 10, 5);
let expected = Buffer::with_lines(vec![
" ",
" ",
"Item 2 ",
"Item 1 ",
"Item 0 ",
]);
assert_buffer_eq!(buffer, expected);
}

#[test]
fn test_list_truncate_items() {
let items = list_items(vec!["Item 0", "Item 1", "Item 2", "Item 3", "Item 4"]);
Expand Down

0 comments on commit 08f796b

Please sign in to comment.