blob: 0f6a79a8ef5ed2a77dc3f84789f1d9d6fa0b73f0 (
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
30
31
32
33
34
|
use ratatui::{layout::Constraint, widgets::{Row, Table, Widget}, prelude::Text};
use crate::model::Task;
#[derive(Debug)]
pub struct TaskList<'a> {
tasks: &'a[Task]
}
impl<'a> TaskList<'a> {
pub fn new(tasks: &'a[Task]) -> TaskList<'a> {
TaskList {
tasks
}
}
}
impl<'a> Widget for &TaskList<'a> {
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) {
let rows: Vec<Row> = self.tasks.into_iter()
.map(|t: &Task| Row::new(vec![Text::from(t.name.as_str()), Text::from(t.description.as_str())]))
.collect();
let widths = [
Constraint::Percentage(50),
Constraint::Fill(1),
];
Table::new(rows, widths)
.render(area, buf);
}
}
|