diff options
author | Akshay <[email protected]> | 2020-07-14 12:50:36 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-07-14 12:50:36 +0100 |
commit | 3ded40d04f49983e7907366536dbc94917cee666 (patch) | |
tree | 5e837246e3603249c9a7e4343d1afb762d5d0e71 /src/habit/traits.rs | |
parent | 68ebbd1f753e0937bfaf07006daf1d6144c21bed (diff) |
more boilerplate for auto-trackable habits
add funding.yml also :^)
Diffstat (limited to 'src/habit/traits.rs')
-rw-r--r-- | src/habit/traits.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/habit/traits.rs b/src/habit/traits.rs index e28e55d..5092bc5 100644 --- a/src/habit/traits.rs +++ b/src/habit/traits.rs | |||
@@ -26,6 +26,8 @@ pub trait Habit { | |||
26 | 26 | ||
27 | fn set_view_mode(&mut self, mode: ViewMode); | 27 | fn set_view_mode(&mut self, mode: ViewMode); |
28 | fn view_mode(&self) -> ViewMode; | 28 | fn view_mode(&self) -> ViewMode; |
29 | |||
30 | fn is_auto(&self) -> bool; | ||
29 | } | 31 | } |
30 | 32 | ||
31 | #[typetag::serde(tag = "type")] | 33 | #[typetag::serde(tag = "type")] |
@@ -44,21 +46,15 @@ pub trait HabitWrapper: erased_serde::Serialize { | |||
44 | 46 | ||
45 | fn set_view_mode(&mut self, mode: ViewMode); | 47 | fn set_view_mode(&mut self, mode: ViewMode); |
46 | fn view_mode(&self) -> ViewMode; | 48 | fn view_mode(&self) -> ViewMode; |
49 | |||
50 | fn is_auto(&self) -> bool; | ||
47 | } | 51 | } |
48 | 52 | ||
49 | macro_rules! auto_habit_impl { | 53 | macro_rules! auto_habit_impl { |
50 | ($struct_name:ident) => { | 54 | ($struct_name:ident) => { |
51 | #[typetag::serde] | 55 | #[typetag::serde] |
52 | impl HabitWrapper for $struct_name { | 56 | impl HabitWrapper for $struct_name { |
53 | fn remaining(&self, date: NaiveDate) -> u32 { | 57 | // ShadowView |
54 | Habit::remaining(self, date) | ||
55 | } | ||
56 | fn goal(&self) -> u32 { | ||
57 | Habit::goal(self) | ||
58 | } | ||
59 | fn modify(&mut self, date: NaiveDate, event: TrackEvent) { | ||
60 | Habit::modify(self, date, event); | ||
61 | } | ||
62 | fn draw(&self, printer: &Printer) { | 58 | fn draw(&self, printer: &Printer) { |
63 | ShadowView::draw(self, printer) | 59 | ShadowView::draw(self, printer) |
64 | } | 60 | } |
@@ -71,6 +67,17 @@ macro_rules! auto_habit_impl { | |||
71 | fn take_focus(&mut self, d: Direction) -> bool { | 67 | fn take_focus(&mut self, d: Direction) -> bool { |
72 | ShadowView::take_focus(self, d) | 68 | ShadowView::take_focus(self, d) |
73 | } | 69 | } |
70 | |||
71 | // Habit | ||
72 | fn remaining(&self, date: NaiveDate) -> u32 { | ||
73 | Habit::remaining(self, date) | ||
74 | } | ||
75 | fn goal(&self) -> u32 { | ||
76 | Habit::goal(self) | ||
77 | } | ||
78 | fn modify(&mut self, date: NaiveDate, event: TrackEvent) { | ||
79 | Habit::modify(self, date, event); | ||
80 | } | ||
74 | fn get_name(&self) -> String { | 81 | fn get_name(&self) -> String { |
75 | Habit::name(self) | 82 | Habit::name(self) |
76 | } | 83 | } |
@@ -86,6 +93,9 @@ macro_rules! auto_habit_impl { | |||
86 | fn view_mode(&self) -> ViewMode { | 93 | fn view_mode(&self) -> ViewMode { |
87 | Habit::view_mode(self) | 94 | Habit::view_mode(self) |
88 | } | 95 | } |
96 | fn is_auto(&self) -> bool { | ||
97 | Habit::is_auto(self) | ||
98 | } | ||
89 | } | 99 | } |
90 | }; | 100 | }; |
91 | } | 101 | } |