Skip to content

Commit

Permalink
fix(scrollbar)!: move symbols to symbols module (#330)
Browse files Browse the repository at this point in the history
The symbols and sets are moved from `widgets::scrollbar` to
`symbols::scrollbar`. This makes it consistent with the other symbol
sets and allows us to make the scrollbar module private rather than
re-exporting it.

BREAKING CHANGE: The symbols are now in the `symbols` module. To update
your code, add an import for `ratatui::symbols::scrollbar::*` (or the
specific symbols you need). The scrollbar module is no longer public. To
update your code, remove any `widgets::scrollbar` imports and replace it
with `ratatui::widgets::Scrollbar`.
  • Loading branch information
joshka committed Jul 26, 2023
1 parent 8db9fb4 commit 7539f77
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crossterm::{
execute,
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
};
use ratatui::{prelude::*, widgets::*};
use ratatui::{prelude::*, symbols::scrollbar, widgets::*};

#[derive(Default)]
struct App {
Expand Down
49 changes: 49 additions & 0 deletions src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,52 @@ pub enum Marker {
/// Up to 8 points per cell
Braille,
}

pub mod scrollbar {
use super::{block, line};

/// Scrollbar Set
/// ```text
/// <--▮------->
/// ^ ^ ^ ^
/// │ │ │ └ end
/// │ │ └──── track
/// │ └──────── thumb
/// └─────────── begin
/// ```
#[derive(Debug, Clone)]
pub struct Set {
pub track: &'static str,
pub thumb: &'static str,
pub begin: &'static str,
pub end: &'static str,
}

pub const DOUBLE_VERTICAL: Set = Set {
track: line::DOUBLE_VERTICAL,
thumb: block::FULL,
begin: "▲",
end: "▼",
};

pub const DOUBLE_HORIZONTAL: Set = Set {
track: line::DOUBLE_HORIZONTAL,
thumb: block::FULL,
begin: "◄",
end: "►",
};

pub const VERTICAL: Set = Set {
track: line::VERTICAL,
thumb: block::FULL,
begin: "↑",
end: "↓",
};

pub const HORIZONTAL: Set = Set {
track: line::HORIZONTAL,
thumb: block::FULL,
begin: "←",
end: "→",
};
}
2 changes: 1 addition & 1 deletion src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod gauge;
mod list;
mod paragraph;
mod reflow;
pub mod scrollbar;
mod scrollbar;
mod sparkline;
mod table;
mod tabs;
Expand Down
52 changes: 5 additions & 47 deletions src/widgets/scrollbar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,7 @@ use crate::{
buffer::Buffer,
layout::Rect,
style::Style,
symbols::{block::FULL, line},
};

/// Scrollbar Set
/// ```text
/// <--▮------->
/// ^ ^ ^ ^
/// │ │ │ └ end
/// │ │ └──── track
/// │ └──────── thumb
/// └─────────── begin
/// ```
#[derive(Debug, Clone)]
pub struct Set {
pub track: &'static str,
pub thumb: &'static str,
pub begin: &'static str,
pub end: &'static str,
}

pub const DOUBLE_VERTICAL: Set = Set {
track: line::DOUBLE_VERTICAL,
thumb: FULL,
begin: "▲",
end: "▼",
};

pub const DOUBLE_HORIZONTAL: Set = Set {
track: line::DOUBLE_HORIZONTAL,
thumb: FULL,
begin: "◄",
end: "►",
};

pub const VERTICAL: Set = Set {
track: line::VERTICAL,
thumb: FULL,
begin: "↑",
end: "↓",
};

pub const HORIZONTAL: Set = Set {
track: line::HORIZONTAL,
thumb: FULL,
begin: "←",
end: "→",
symbols::scrollbar::{Set, DOUBLE_HORIZONTAL, DOUBLE_VERTICAL},
};

/// An enum representing the direction of scrolling in a Scrollbar widget.
Expand Down Expand Up @@ -501,7 +456,10 @@ impl<'a> StatefulWidget for Scrollbar<'a> {
#[cfg(test)]
mod tests {
use super::*;
use crate::assert_buffer_eq;
use crate::{
assert_buffer_eq,
symbols::scrollbar::{HORIZONTAL, VERTICAL},
};

#[test]
fn test_no_render_when_area_zero() {
Expand Down

0 comments on commit 7539f77

Please sign in to comment.