-
Notifications
You must be signed in to change notification settings - Fork 258
/
app_widget.rs
69 lines (60 loc) · 2.04 KB
/
app_widget.rs
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use ratatui::{prelude::*, widgets::*};
use crate::{styles, tabs::Tab, tui};
pub struct AppWidget {
tab: Box<dyn Tab>,
tab_index: usize,
titles: Vec<String>,
}
impl AppWidget {
pub fn new(tab: Box<dyn Tab>, tab_index: usize, titles: Vec<String>) -> Self {
AppWidget {
tab,
tab_index,
titles,
}
}
}
impl Widget for AppWidget {
fn render(self, area: Rect, buf: &mut Buffer) {
Block::new().bg(styles::APP_BACKGROUND).render(area, buf);
let area = tui::layout(area, Direction::Vertical, vec![1, 0, 1]);
self.render_title_bar(area[0], buf);
self.render_selected_tab(area[1], buf);
self.render_bottom_bar(area[2], buf);
}
}
impl AppWidget {
fn render_title_bar(&self, area: Rect, buf: &mut Buffer) {
let area = tui::layout(area, Direction::Horizontal, vec![17, 0]);
Paragraph::new(Span::styled("Ratatui v0.23.0 ", styles::APP_TITLE)).render(area[0], buf);
Tabs::new(self.titles.clone())
.style(styles::TABS)
.highlight_style(styles::TABS_SELECTED)
.select(self.tab_index)
.render(area[1], buf);
}
fn render_selected_tab(&self, area: Rect, buf: &mut Buffer) {
self.tab.render(area, buf);
}
fn render_bottom_bar(&self, area: Rect, buf: &mut Buffer) {
let key_style = Style::new().fg(Color::Indexed(232)).bg(Color::Indexed(236));
Paragraph::new(Line::from(vec![
" Q/Esc ".set_style(key_style),
" Quit ".into(),
" Tab ".set_style(key_style),
" Next Tab ".into(),
" ←/h ".set_style(key_style),
" Left ".into(),
" →/l ".set_style(key_style),
" Right ".into(),
" ↑/k ".set_style(key_style),
" Up ".into(),
" ↓/j ".set_style(key_style),
" Down".into(),
]))
.alignment(Alignment::Center)
.fg(Color::Indexed(236))
.bg(Color::Indexed(232))
.render(area, buf);
}
}