diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-03-02 18:50:29 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-03-02 18:50:29 -0500 |
commit | e321dfc3c96f50f09c3953340a5a6fea72a5a245 (patch) | |
tree | dc13fee011e7c49536eb28b5b3d5de8bef93af89 /src/ui/widgets/tui_tab.rs | |
parent | 8bc73974e78883eb1f619d1829a8be77933e5c00 (diff) |
add tab widget for showing which tab we are on
- code cleanup
- pageup and pagedown now work properly
Diffstat (limited to 'src/ui/widgets/tui_tab.rs')
-rw-r--r-- | src/ui/widgets/tui_tab.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/ui/widgets/tui_tab.rs b/src/ui/widgets/tui_tab.rs new file mode 100644 index 0000000..55ca497 --- /dev/null +++ b/src/ui/widgets/tui_tab.rs @@ -0,0 +1,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); + } +} |