Clock<T> (#6)

This commit is contained in:
Jens K.
2024-12-02 17:54:47 +01:00
committed by GitHub
parent 2f587c97b5
commit 4f66ea86d4
9 changed files with 189 additions and 48 deletions

View File

@@ -1,23 +1,30 @@
use ratatui::{
buffer::Buffer,
layout::Rect,
layout::{Constraint, Layout, Rect},
widgets::{Paragraph, Widget},
};
#[derive(Debug, Default, Clone, PartialEq, Eq)]
use crate::clock::{self, Clock};
#[derive(Debug)]
pub struct Countdown {
headline: String,
clock: Clock<clock::Countdown>,
}
impl Countdown {
pub const fn new(headline: String) -> Self {
Self { headline }
pub const fn new(headline: String, clock: Clock<clock::Countdown>) -> Self {
Self { headline, clock }
}
}
impl Widget for Countdown {
fn render(self, area: Rect, buf: &mut Buffer) {
fn render(mut self, area: Rect, buf: &mut Buffer) {
let h = Paragraph::new(self.headline).centered();
h.render(area, buf);
let c = Paragraph::new(self.clock.format()).centered();
let [v1, v2] = Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).areas(area);
h.render(v1, buf);
c.render(v2, buf)
}
}