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 Jan 6, 2024
1 parent bc274e2 commit c1949c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 74 deletions.
22 changes: 22 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ github with a [breaking change] label.
This is a quick summary of the sections below:

- [v0.26.0 (unreleased)](#v0260-unreleased)
- Removed deprecated `List::start_corner`
- Removed deprecated `Block::title_on_bottom`
- `Line` now has an extra `style` field which applies the style to the entire line
- `Block` style methods cannot be created in a const context
Expand Down Expand Up @@ -45,6 +46,27 @@ This is a quick summary of the sections below:

## v0.26.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);
```

### Remove deprecated `Block::title_on_bottom` ([#757])

[#757]: https://github.com/ratatui-org/ratatui/pull/757
Expand Down
74 changes: 0 additions & 74 deletions src/widgets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,48 +662,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 @@ -1563,38 +1521,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 c1949c3

Please sign in to comment.