termimad/
scrollbar_style.rs

1use crate::{
2    color::*,
3    crossterm::style::Color,
4    styled_char::StyledChar,
5};
6
7/// A scrollbar style defined by two styled chars, one
8///  for the track, and one for the thumb.
9///
10/// For the default styling only the fg color is defined
11///  and the char is ▐ but everything can be changed.
12#[derive(Clone, Debug, PartialEq)]
13pub struct ScrollBarStyle {
14    pub track: StyledChar,
15    pub thumb: StyledChar,
16}
17
18impl ScrollBarStyle {
19    pub fn new() -> Self {
20        let char = '▐';
21        Self {
22            track: StyledChar::from_fg_char(gray(5), char),
23            thumb: StyledChar::from_fg_char(gray(21), char),
24        }
25    }
26    pub fn set_bg(&mut self, bg: Color) {
27        self.track.set_bg(bg);
28        self.thumb.set_bg(bg);
29    }
30}
31
32impl Default for ScrollBarStyle {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38impl From<StyledChar> for ScrollBarStyle {
39    fn from(sc: StyledChar) -> Self {
40        let char = sc.nude_char();
41        Self {
42            track: StyledChar::from_fg_char(sc.get_bg().unwrap_or(gray(5)), char),
43            thumb: StyledChar::from_fg_char(sc.get_fg().unwrap_or(gray(21)), char),
44        }
45    }
46}