Add calendar, refactor more

This commit is contained in:
Kenny Levinsen
2023-01-16 00:25:34 +01:00
parent 3a40bb18c5
commit 7593cd48a4
15 changed files with 689 additions and 286 deletions
+13 -4
View File
@@ -4,6 +4,7 @@ use crate::{
buffer::BufferView,
color::Color,
fonts::FontMap,
state::Event,
widgets::{Geometry, Widget},
};
@@ -21,7 +22,8 @@ pub struct Clock {
impl<'a> Clock {
pub fn new(font: &'static str, size: f32) -> Clock {
Clock {
font, size,
font,
size,
dirty: true,
geometry: Default::default(),
digit_width: 0,
@@ -31,9 +33,6 @@ impl<'a> Clock {
}
impl<'a> Widget for Clock {
fn set_dirty(&mut self, dirty: bool) {
self.dirty = dirty;
}
fn get_dirty(&self) -> bool {
self.dirty
}
@@ -42,6 +41,15 @@ impl<'a> Widget for Clock {
self.geometry
}
fn event(&mut self, event: &Event) {
match event {
Event::NewMinute => {
self.dirty = true;
}
_ => (),
}
}
fn draw(&mut self, fonts: &mut FontMap, view: &mut BufferView) -> Geometry {
let time = Local::now().naive_local();
let fg = Color::new(1., 1., 1., 1.);
@@ -58,6 +66,7 @@ impl<'a> Widget for Clock {
&format!("{:02}:{:02}", time.hour(), time.minute()),
)
.unwrap();
self.dirty = false;
self.geometry
}