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.
This commit is contained in:
EdJoPaTo
2024-02-24 11:08:30 +01:00
parent 98b53e448f
commit b31a599a37
4 changed files with 15 additions and 26 deletions
-1
View File
@@ -40,7 +40,6 @@ jobs:
- -D clippy::pedantic - -D clippy::pedantic
features: features:
- "" # default features - "" # default features
- --all-features
include: include:
# Check future versions and maybe get some glances on soon to be lints # Check future versions and maybe get some glances on soon to be lints
- toolchain: beta - toolchain: beta
-8
View File
@@ -11,14 +11,6 @@ categories = ["command-line-interface"]
include = ["src/**/*", "README.md"] include = ["src/**/*", "README.md"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # 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] [dependencies]
ratatui = { version = "0.26", default-features = false } ratatui = { version = "0.26", default-features = false }
unicode-width = "0.1" unicode-width = "0.1"
+2 -2
View File
@@ -124,8 +124,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<(
.title("Tree Widget") .title("Tree Widget")
.title_bottom(format!("{:?}", app.state)), .title_bottom(format!("{:?}", app.state)),
) )
.scrollbar_margin((1, 1)) .experimental_scrollbar_margin((1, 1))
.scrollbar(Some( .experimental_scrollbar(Some(
Scrollbar::new(ScrollbarOrientation::VerticalRight) Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(None) .begin_symbol(None)
.track_symbol(None) .track_symbol(None)
+13 -15
View File
@@ -13,7 +13,7 @@ use std::collections::HashSet;
use ratatui::buffer::Buffer; use ratatui::buffer::Buffer;
use ratatui::layout::Rect; use ratatui::layout::Rect;
use ratatui::style::Style; use ratatui::style::Style;
use ratatui::widgets::{Block, StatefulWidget, Widget}; use ratatui::widgets::{Block, Scrollbar, ScrollbarState, StatefulWidget, Widget};
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
mod flatten; mod flatten;
@@ -60,9 +60,7 @@ pub struct Tree<'a, Identifier> {
items: Vec<TreeItem<'a, Identifier>>, items: Vec<TreeItem<'a, Identifier>>,
block: Option<Block<'a>>, block: Option<Block<'a>>,
#[cfg(feature = "experimental_scrollbar")] scrollbar: Option<Scrollbar<'a>>,
scrollbar: Option<ratatui::widgets::Scrollbar<'a>>,
#[cfg(feature = "experimental_scrollbar")]
scrollbar_margin: (u16, u16), scrollbar_margin: (u16, u16),
/// Style used as a base style for the widget /// Style used as a base style for the widget
style: Style, style: Style,
@@ -104,9 +102,7 @@ where
Ok(Self { Ok(Self {
items, items,
block: None, block: None,
#[cfg(feature = "experimental_scrollbar")]
scrollbar: None, scrollbar: None,
#[cfg(feature = "experimental_scrollbar")]
scrollbar_margin: (0, 0), scrollbar_margin: (0, 0),
style: Style::new(), style: Style::new(),
highlight_style: Style::new(), highlight_style: Style::new(),
@@ -124,16 +120,20 @@ where
self 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 <https://github.com/ratatui-org/ratatui/issues/174>
#[must_use] #[must_use]
pub const fn scrollbar(mut self, scrollbar: Option<ratatui::widgets::Scrollbar<'a>>) -> Self { pub const fn experimental_scrollbar(mut self, scrollbar: Option<Scrollbar<'a>>) -> Self {
self.scrollbar = scrollbar; self.scrollbar = scrollbar;
self self
} }
#[cfg(feature = "experimental_scrollbar")] /// See [`experimental_scrollbar`](Self::experimental_scrollbar)
#[must_use] #[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.scrollbar_margin = margin;
self self
} }
@@ -252,12 +252,10 @@ where
state.offset = start; state.offset = start;
state.ensure_selected_in_view_on_next_render = false; state.ensure_selected_in_view_on_next_render = false;
#[cfg(feature = "experimental_scrollbar")]
if let Some(scrollbar) = self.scrollbar { if let Some(scrollbar) = self.scrollbar {
let mut scrollbar_state = let mut scrollbar_state = ScrollbarState::new(visible.len().saturating_sub(height))
ratatui::widgets::ScrollbarState::new(visible.len().saturating_sub(height)) .position(start)
.position(start) .viewport_content_length(height);
.viewport_content_length(height);
let scrollbar_area = Rect { let scrollbar_area = Rect {
y: full_area.y.saturating_add(self.scrollbar_margin.0), y: full_area.y.saturating_add(self.scrollbar_margin.0),
height: full_area height: full_area