use ratatui::{
Frame,
layout::Rect,
style::{Color, Style},
widgets::{Scrollbar, ScrollbarOrientation, ScrollbarState},
};
pub fn render_vertical_scrollbar_styled(
frame: &mut Frame,
area: Rect,
total_items: usize,
viewport_size: usize,
scroll_offset: usize,
color: Color,
) {
if total_items <= viewport_size || viewport_size == 0 {
return;
}
let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(None)
.end_symbol(None)
.thumb_style(Style::default().fg(color))
.track_style(Style::default().fg(color));
let max_scroll = total_items.saturating_sub(viewport_size);
let mut state = ScrollbarState::new(max_scroll + 1)
.position(scroll_offset.min(max_scroll))
.viewport_content_length(viewport_size);
frame.render_stateful_widget(scrollbar, area, &mut state);
}
pub fn render_vertical_scrollbar(
frame: &mut Frame,
area: Rect,
total_items: usize,
viewport_size: usize,
scroll_offset: usize,
) {
if total_items <= viewport_size || viewport_size == 0 {
return;
}
let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
.begin_symbol(None)
.end_symbol(None);
let max_scroll = total_items.saturating_sub(viewport_size);
let mut state = ScrollbarState::new(max_scroll + 1)
.position(scroll_offset.min(max_scroll))
.viewport_content_length(viewport_size);
frame.render_stateful_widget(scrollbar, area, &mut state);
}
#[cfg(test)]
#[path = "scrollbar_tests.rs"]
mod scrollbar_tests;