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
|
use ratatui::{
prelude::*,
widgets::*,
};
use crate::pomo::state::{Pomo, SessionMode};
pub fn render(f: &mut Frame, app: &mut Pomo) {
// 1. Create a centered area.
// We use 60% of width and 60% of height for that "isolated" feel.
let area = centered_rect(60, 60, f.size());
// 2. Clear the area with a transparent background
// Color::Reset ensures we use your terminal's background/transparency
let main_block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(Color::Cyan))
.style(Style::default().bg(Color::Reset));
// 3. Split the centered area into Timer (Top) and Todo (Bottom)
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Percentage(40), // Timer space
Constraint::Percentage(60), // Todo space
])
.split(main_block.inner(area));
// 4. Render the Timer
let timer_text = format_duration(app.time_remaining);
let timer_color = if app.is_running { Color::Green } else { Color::Yellow };
let timer_para = Paragraph::new(timer_text)
.alignment(Alignment::Center)
.style(Style::default().fg(timer_color).add_modifier(Modifier::BOLD));
// 5. Render the Todo List (Placeholder for now)
let tasks: Vec<ListItem> = app.tasks
.iter()
.map(|t| {
let symbol = if t.is_done { " " } else { " " };
ListItem::new(format!("{} {}", symbol, t.title))
})
.collect();
let list = List::new(tasks)
.block(Block::default().title(" Priorities ").borders(Borders::TOP))
.highlight_style(Style::default().add_modifier(Modifier::REVERSED))
.highlight_symbol(">> ");
// Final Renders
f.render_widget(main_block, area);
f.render_widget(timer_para, chunks[0]);
f.render_stateful_widget(list, chunks[1], &mut app.task_state);
}
/// Helper function to center a rectangle
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]
}
/// Helper to format Duration into MM:SS
fn format_duration(duration: std::time::Duration) -> String {
let secs = duration.as_secs();
let mins = secs / 60;
let secs = secs % 60;
format!("\n\n{:02}:{:02}", mins, secs)
}
|