From b31a599a37a1e3d2c933cfe85e171904a6f6f08e Mon Sep 17 00:00:00 2001 From: EdJoPaTo Date: Sat, 24 Feb 2024 11:08:30 +0100 Subject: [PATCH] refactor(scrollbar): experimental prefix over feature A feature flag has quite some complexity with it and is annyoing. Write a rustdoc comment about it and be clear about it being experimental and include it as is. --- .github/workflows/rust.yml | 1 - Cargo.toml | 8 -------- examples/example.rs | 4 ++-- src/lib.rs | 28 +++++++++++++--------------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dd7250a..b9fcc94 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,7 +40,6 @@ jobs: - -D clippy::pedantic features: - "" # default features - - --all-features include: # Check future versions and maybe get some glances on soon to be lints - toolchain: beta diff --git a/Cargo.toml b/Cargo.toml index cf8e2af..ae70eb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,6 @@ categories = ["command-line-interface"] include = ["src/**/*", "README.md"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[features] -default = [] -experimental_scrollbar = [] - -[[example]] -name = "example" -required-features = ["experimental_scrollbar"] - [dependencies] ratatui = { version = "0.26", default-features = false } unicode-width = "0.1" diff --git a/examples/example.rs b/examples/example.rs index 5aed4dc..bbe16c1 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -124,8 +124,8 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> io::Result<( .title("Tree Widget") .title_bottom(format!("{:?}", app.state)), ) - .scrollbar_margin((1, 1)) - .scrollbar(Some( + .experimental_scrollbar_margin((1, 1)) + .experimental_scrollbar(Some( Scrollbar::new(ScrollbarOrientation::VerticalRight) .begin_symbol(None) .track_symbol(None) diff --git a/src/lib.rs b/src/lib.rs index 3468b0c..20a41d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ use std::collections::HashSet; use ratatui::buffer::Buffer; use ratatui::layout::Rect; use ratatui::style::Style; -use ratatui::widgets::{Block, StatefulWidget, Widget}; +use ratatui::widgets::{Block, Scrollbar, ScrollbarState, StatefulWidget, Widget}; use unicode_width::UnicodeWidthStr; mod flatten; @@ -60,9 +60,7 @@ pub struct Tree<'a, Identifier> { items: Vec>, block: Option>, - #[cfg(feature = "experimental_scrollbar")] - scrollbar: Option>, - #[cfg(feature = "experimental_scrollbar")] + scrollbar: Option>, scrollbar_margin: (u16, u16), /// Style used as a base style for the widget style: Style, @@ -104,9 +102,7 @@ where Ok(Self { items, block: None, - #[cfg(feature = "experimental_scrollbar")] scrollbar: None, - #[cfg(feature = "experimental_scrollbar")] scrollbar_margin: (0, 0), style: Style::new(), highlight_style: Style::new(), @@ -124,16 +120,20 @@ where self } - #[cfg(feature = "experimental_scrollbar")] + /// Show the scrollbar when rendering this widget. + /// + /// Experimental: Can change on any release without any additional notice. + /// Its there to test and experiment with whats possible with scrolling widgets. + /// Also see #[must_use] - pub const fn scrollbar(mut self, scrollbar: Option>) -> Self { + pub const fn experimental_scrollbar(mut self, scrollbar: Option>) -> Self { self.scrollbar = scrollbar; self } - #[cfg(feature = "experimental_scrollbar")] + /// See [`experimental_scrollbar`](Self::experimental_scrollbar) #[must_use] - pub const fn scrollbar_margin(mut self, margin: (u16, u16)) -> Self { + pub const fn experimental_scrollbar_margin(mut self, margin: (u16, u16)) -> Self { self.scrollbar_margin = margin; self } @@ -252,12 +252,10 @@ where state.offset = start; state.ensure_selected_in_view_on_next_render = false; - #[cfg(feature = "experimental_scrollbar")] if let Some(scrollbar) = self.scrollbar { - let mut scrollbar_state = - ratatui::widgets::ScrollbarState::new(visible.len().saturating_sub(height)) - .position(start) - .viewport_content_length(height); + let mut scrollbar_state = ScrollbarState::new(visible.len().saturating_sub(height)) + .position(start) + .viewport_content_length(height); let scrollbar_area = Rect { y: full_area.y.saturating_add(self.scrollbar_margin.0), height: full_area