diff options
author | Akshay <[email protected]> | 2020-03-18 06:04:41 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-03-18 06:04:41 +0000 |
commit | 33d053d442082547550fc9a54473e05565907f88 (patch) | |
tree | d21697ada3135dd322a80e96cb68dcfe091389f4 /src | |
parent | 0ed2a357ec1446dd03eba963d0e144ef3ebba25a (diff) |
require new super trait, add quit callback
Diffstat (limited to 'src')
-rw-r--r-- | src/habit.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 11 | ||||
-rw-r--r-- | src/views.rs | 2 |
3 files changed, 10 insertions, 11 deletions
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 { | |||
23 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 23 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
24 | write!( | 24 | write!( |
25 | f, | 25 | f, |
26 | "{}", | 26 | "{:^3}", |
27 | if self.0 { | 27 | if self.0 { |
28 | CONFIGURATION.true_chr | 28 | CONFIGURATION.true_chr |
29 | } else { | 29 | } else { |
@@ -53,7 +53,7 @@ pub trait Habit { | |||
53 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | 53 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); |
54 | } | 54 | } |
55 | 55 | ||
56 | pub trait HabitWrapper { | 56 | pub trait HabitWrapper: erased_serde::Serialize { |
57 | fn remaining(&self, date: NaiveDate) -> u32; | 57 | fn remaining(&self, date: NaiveDate) -> u32; |
58 | fn total(&self) -> u32; | 58 | fn total(&self) -> u32; |
59 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | 59 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); |
@@ -63,9 +63,13 @@ pub trait HabitWrapper { | |||
63 | fn take_focus(&mut self, _: Direction) -> bool; | 63 | fn take_focus(&mut self, _: Direction) -> bool; |
64 | } | 64 | } |
65 | 65 | ||
66 | use erased_serde::serialize_trait_object; | ||
67 | serialize_trait_object!(HabitWrapper); | ||
68 | |||
66 | impl<T> HabitWrapper for T | 69 | impl<T> HabitWrapper for T |
67 | where | 70 | where |
68 | T: Habit + ShadowView, | 71 | T: Habit + ShadowView, |
72 | T: Serialize, | ||
69 | T::HabitType: std::fmt::Display, | 73 | T::HabitType: std::fmt::Display, |
70 | { | 74 | { |
71 | fn remaining(&self, date: NaiveDate) -> u32 { | 75 | 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() { | |||
77 | walking.insert_entry(NaiveDate::from_ymd(2020, 3, 14), false.into()); | 77 | walking.insert_entry(NaiveDate::from_ymd(2020, 3, 14), false.into()); |
78 | walking.insert_entry(NaiveDate::from_ymd(2020, 3, 15), true.into()); | 78 | walking.insert_entry(NaiveDate::from_ymd(2020, 3, 15), true.into()); |
79 | 79 | ||
80 | s.add_global_callback('q', |a| a.quit()); | 80 | let mut app = App::new(); |
81 | let app = App::new() | 81 | app.add_habit(Box::new(gymming)); |
82 | .add_habit(Box::new(gymming)) | 82 | app.add_habit(Box::new(reading)); |
83 | .add_habit(Box::new(reading)) | 83 | app.add_habit(Box::new(walking)); |
84 | .add_habit(Box::new(walking)) | ||
85 | .set_mode(ViewMode::Month); | ||
86 | |||
87 | s.add_layer(app); | 84 | s.add_layer(app); |
88 | 85 | ||
89 | s.set_theme(theme::theme_gen()); | 86 | 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 { | |||
109 | fn required_size(&mut self, x: Vec2) -> Vec2 { | 109 | fn required_size(&mut self, x: Vec2) -> Vec2 { |
110 | ShadowView::required_size(self, x) | 110 | ShadowView::required_size(self, x) |
111 | } | 111 | } |
112 | |||
113 | fn take_focus(&mut self, d: Direction) -> bool { | 112 | fn take_focus(&mut self, d: Direction) -> bool { |
114 | ShadowView::take_focus(self, d) | 113 | ShadowView::take_focus(self, d) |
115 | } | 114 | } |
116 | |||
117 | fn on_event(&mut self, e: Event) -> EventResult { | 115 | fn on_event(&mut self, e: Event) -> EventResult { |
118 | ShadowView::on_event(self, e) | 116 | ShadowView::on_event(self, e) |
119 | } | 117 | } |