termimad/
scrollbar_style.rs1use crate::{
2 color::*,
3 crossterm::style::Color,
4 styled_char::StyledChar,
5};
6
7#[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}