summaryrefslogtreecommitdiffstats
path: root/src/ui/widgets/tui_tab.rs
blob: 55ca4973acf847d6dce4b8d98a37eceafa737068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Modifier, Style};
use tui::widgets::{Paragraph, Text, Widget};

pub struct TuiTabBar<'a> {
    name: &'a str,
    curr: usize,
    len: usize,
}

impl<'a> TuiTabBar<'a> {
    pub fn new(name: &'a str, curr: usize, len: usize) -> Self {
        Self { name, curr, len }
    }
}

impl<'a> Widget for TuiTabBar<'a> {
    fn draw(&mut self, area: Rect, buf: &mut Buffer) {
        let selected = Style::default().modifier(Modifier::REVERSED);

        let text = [
            Text::styled(format!("{}: {}", self.curr + 1, self.name), selected),
            Text::raw(format!("/{}", self.len)),
        ];

        Paragraph::new(text.iter()).wrap(true).draw(area, buf);
    }
}