From 4770e715819475cdca2f2ccdbac00cba203cd6d2 Mon Sep 17 00:00:00 2001 From: Valentin271 <36198422+Valentin271@users.noreply.github.com> Date: Fri, 24 May 2024 20:52:01 +0200 Subject: [PATCH] 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 --- BREAKING-CHANGES.md | 27 ++++++++++++++++++ src/layout.rs | 2 -- src/layout/corner.rs | 33 ---------------------- src/prelude.rs | 2 +- src/widgets/list.rs | 66 -------------------------------------------- 5 files changed, 28 insertions(+), 102 deletions(-) delete mode 100644 src/layout/corner.rs diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index 27e37edb..1a00472b 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -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]) diff --git a/src/layout.rs b/src/layout.rs index dc88be8a..dbae27f8 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -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; diff --git a/src/layout/corner.rs b/src/layout/corner.rs deleted file mode 100644 index 4da84565..00000000 --- a/src/layout/corner.rs +++ /dev/null @@ -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::(), Ok(Corner::BottomLeft)); - assert_eq!("BottomRight".parse::(), Ok(Corner::BottomRight)); - assert_eq!("TopLeft".parse::(), Ok(Corner::TopLeft)); - assert_eq!("TopRight".parse::(), Ok(Corner::TopRight)); - assert_eq!("".parse::(), Err(ParseError::VariantNotFound)); - } -} diff --git a/src/prelude.rs b/src/prelude.rs index 13c8706a..55250ab7 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -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}, diff --git a/src/widgets/list.rs b/src/widgets/list.rs index 0321dc57..d884b4bb 100755 --- a/src/widgets/list.rs +++ b/src/widgets/list.rs @@ -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>, - { - #[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"]);