From 33d053d442082547550fc9a54473e05565907f88 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 18 Mar 2020 11:34:41 +0530 Subject: require new super trait, add quit callback --- src/habit.rs | 8 ++++++-- src/main.rs | 11 ++++------- src/views.rs | 2 -- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/habit.rs b/src/habit.rs index 3716183..45eeefa 100644 --- a/src/habit.rs +++ b/src/habit.rs @@ -23,7 +23,7 @@ impl fmt::Display for CustomBool { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "{}", + "{:^3}", if self.0 { CONFIGURATION.true_chr } else { @@ -53,7 +53,7 @@ pub trait Habit { fn modify(&mut self, date: NaiveDate, event: TrackEvent); } -pub trait HabitWrapper { +pub trait HabitWrapper: erased_serde::Serialize { fn remaining(&self, date: NaiveDate) -> u32; fn total(&self) -> u32; fn modify(&mut self, date: NaiveDate, event: TrackEvent); @@ -63,9 +63,13 @@ pub trait HabitWrapper { fn take_focus(&mut self, _: Direction) -> bool; } +use erased_serde::serialize_trait_object; +serialize_trait_object!(HabitWrapper); + impl HabitWrapper for T where T: Habit + ShadowView, + T: Serialize, T::HabitType: std::fmt::Display, { fn remaining(&self, date: NaiveDate) -> u32 { diff --git a/src/main.rs b/src/main.rs index bec4536..cb3393b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,13 +77,10 @@ fn main() { walking.insert_entry(NaiveDate::from_ymd(2020, 3, 14), false.into()); walking.insert_entry(NaiveDate::from_ymd(2020, 3, 15), true.into()); - s.add_global_callback('q', |a| a.quit()); - let app = App::new() - .add_habit(Box::new(gymming)) - .add_habit(Box::new(reading)) - .add_habit(Box::new(walking)) - .set_mode(ViewMode::Month); - + let mut app = App::new(); + app.add_habit(Box::new(gymming)); + app.add_habit(Box::new(reading)); + app.add_habit(Box::new(walking)); s.add_layer(app); s.set_theme(theme::theme_gen()); diff --git a/src/views.rs b/src/views.rs index ebb83b8..975864c 100644 --- a/src/views.rs +++ b/src/views.rs @@ -109,11 +109,9 @@ macro_rules! auto_view_impl { fn required_size(&mut self, x: Vec2) -> Vec2 { ShadowView::required_size(self, x) } - fn take_focus(&mut self, d: Direction) -> bool { ShadowView::take_focus(self, d) } - fn on_event(&mut self, e: Event) -> EventResult { ShadowView::on_event(self, e) } -- cgit v1.2.3