Clock<T> (#6)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user