mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-10 07:04:17 +00:00
refactor(list)!: remove deprecated start_corner
and Corner
(#759)
`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` is removed entirely. Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
This commit is contained in:
parent
eef1afe915
commit
4770e71581
5 changed files with 28 additions and 102 deletions
|
@ -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`
|
||||
|
@ -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])
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
mod alignment;
|
||||
mod constraint;
|
||||
mod corner;
|
||||
mod direction;
|
||||
mod flex;
|
||||
#[allow(clippy::module_inception)]
|
||||
|
@ -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;
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
use strum::{Display, EnumString};
|
||||
|
||||
#[derive(Debug, Default, Display, EnumString, Clone, Copy, Eq, PartialEq, Hash)]
|
||||
pub enum Corner {
|
||||
#[default]
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomRight,
|
||||
BottomLeft,
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use strum::ParseError;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn corner_to_string() {
|
||||
assert_eq!(Corner::BottomLeft.to_string(), "BottomLeft");
|
||||
assert_eq!(Corner::BottomRight.to_string(), "BottomRight");
|
||||
assert_eq!(Corner::TopLeft.to_string(), "TopLeft");
|
||||
assert_eq!(Corner::TopRight.to_string(), "TopRight");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn corner_from_str() {
|
||||
assert_eq!("BottomLeft".parse::<Corner>(), Ok(Corner::BottomLeft));
|
||||
assert_eq!("BottomRight".parse::<Corner>(), Ok(Corner::BottomRight));
|
||||
assert_eq!("TopLeft".parse::<Corner>(), Ok(Corner::TopLeft));
|
||||
assert_eq!("TopRight".parse::<Corner>(), Ok(Corner::TopRight));
|
||||
assert_eq!("".parse::<Corner>(), Err(ParseError::VariantNotFound));
|
||||
}
|
||||
}
|
|
@ -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},
|
||||
|
|
|
@ -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()
|
||||
|
@ -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"]);
|
||||
|
|
Loading…
Reference in a new issue