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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
use ratatui::{
prelude::*,
widgets::*,
};
use crate::pomo::state::Pomo;
pub fn render(f: &mut Frame, app: &mut Pomo) {
let area = centered_rect(50, 50, f.area());
let accent_color = app.mode.get_color();
let main_block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(accent_color))
.style(Style::default().bg(Color::Reset));
let inner_area = main_block.inner(area);
f.render_widget(main_block, area);
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3),
Constraint::Min(1),
])
.split(inner_area);
// Timer
let timer_text = format_duration(app.time_remaining);
let timer_para = Paragraph::new(timer_text)
.alignment(Alignment::Center)
.style(Style::default().fg(Color::White).add_modifier(Modifier::BOLD));
f.render_widget(timer_para, chunks[0]);
// Priority Tasks
let tasks: Vec<ListItem> = app.tasks
.iter()
.map(|t| {
let symbol = if t.is_done { "" } else { "" };
ListItem::new(Line::from(vec![
Span::styled(format!(" {} ", symbol), Style::default().fg(accent_color)),
Span::raw(t.title.clone()),
]))
})
.collect();
let list = List::new(tasks)
.highlight_style(Style::default().bg(Color::Indexed(8)).fg(Color::White))
.highlight_symbol(" ");
f.render_stateful_widget(list, chunks[1], &mut app.task_state);
if app.show_help {
let help_area = centered_rect(30, 30, f.area()); // Smaller popup
// Clear the area underneath so the main UI doesn't interfere
f.render_widget(Clear, help_area);
let help_block = Block::default()
.title(" Help / Controls ")
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(accent_color));
let commands = app.get_commands();
let help_text: Vec<ListItem> = commands
.iter()
.map(|c| {
ListItem::new(Line::from(vec![
Span::styled(format!("{:<7}", c.key), Style::default().fg(accent_color).add_modifier(Modifier::BOLD)),
Span::raw(c.desc),
]))
})
.collect();
let help_list = List::new(help_text).block(help_block);
f.render_widget(help_list, help_area);
}
}
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
let popup_layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Percentage((100 - percent_y) / 2),
Constraint::Percentage(percent_y),
Constraint::Percentage((100 - percent_y) / 2),
])
.split(r);
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage((100 - percent_x) / 2),
Constraint::Percentage(percent_x),
Constraint::Percentage((100 - percent_x) / 2),
])
.split(popup_layout[1])[1]
}
fn format_duration(duration: std::time::Duration) -> String {
let secs = duration.as_secs();
let mins = secs / 60;
let secs = secs % 60;
format!("{:02}:{:02}", mins, secs)
}
|