mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-26 06:30:29 +00:00
fix(scrollbar)!: move symbols to symbols module (#330)
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:🔣: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`.
This commit is contained in:
parent
8db9fb4aeb
commit
7539f775fe
4 changed files with 56 additions and 49 deletions
|
@ -9,7 +9,7 @@ use crossterm::{
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
use ratatui::{prelude::*, widgets::*};
|
use ratatui::{prelude::*, symbols::scrollbar, widgets::*};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct App {
|
struct App {
|
||||||
|
|
|
@ -233,3 +233,52 @@ pub enum Marker {
|
||||||
/// Up to 8 points per cell
|
/// Up to 8 points per cell
|
||||||
Braille,
|
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: "→",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ mod gauge;
|
||||||
mod list;
|
mod list;
|
||||||
mod paragraph;
|
mod paragraph;
|
||||||
mod reflow;
|
mod reflow;
|
||||||
pub mod scrollbar;
|
mod scrollbar;
|
||||||
mod sparkline;
|
mod sparkline;
|
||||||
mod table;
|
mod table;
|
||||||
mod tabs;
|
mod tabs;
|
||||||
|
|
|
@ -3,52 +3,7 @@ use crate::{
|
||||||
buffer::Buffer,
|
buffer::Buffer,
|
||||||
layout::Rect,
|
layout::Rect,
|
||||||
style::Style,
|
style::Style,
|
||||||
symbols::{block::FULL, line},
|
symbols::scrollbar::{Set, DOUBLE_HORIZONTAL, DOUBLE_VERTICAL},
|
||||||
};
|
|
||||||
|
|
||||||
/// 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: "→",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An enum representing the direction of scrolling in a Scrollbar widget.
|
/// An enum representing the direction of scrolling in a Scrollbar widget.
|
||||||
|
@ -501,7 +456,10 @@ impl<'a> StatefulWidget for Scrollbar<'a> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::assert_buffer_eq;
|
use crate::{
|
||||||
|
assert_buffer_eq,
|
||||||
|
symbols::scrollbar::{HORIZONTAL, VERTICAL},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_render_when_area_zero() {
|
fn test_no_render_when_area_zero() {
|
||||||
|
|
Loading…
Reference in a new issue