diff options
author | Akshay <[email protected]> | 2021-02-24 06:27:37 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-02-24 06:27:37 +0000 |
commit | fbcc966a3da8a75842c6b8843a9fd7f1edb0db15 (patch) | |
tree | be2851277e689fec2f1629ca7a03bba1c8931446 /src/habit/traits.rs | |
parent | 3169cb6c8056b46a6f08533014366b8c441971f8 (diff) |
add GoalKinds
- this allows for changing habit goals easily
- easier to add new habits to dijo in newer versions
Diffstat (limited to 'src/habit/traits.rs')
-rw-r--r-- | src/habit/traits.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/habit/traits.rs b/src/habit/traits.rs index 24d941d..54ec9e1 100644 --- a/src/habit/traits.rs +++ b/src/habit/traits.rs | |||
@@ -2,10 +2,10 @@ use chrono::NaiveDate; | |||
2 | use cursive::direction::Direction; | 2 | use cursive::direction::Direction; |
3 | use cursive::event::{Event, EventResult}; | 3 | use cursive::event::{Event, EventResult}; |
4 | use cursive::{Printer, Vec2}; | 4 | use cursive::{Printer, Vec2}; |
5 | |||
6 | use typetag; | 5 | use typetag; |
7 | 6 | ||
8 | use crate::habit::{Bit, Count, InnerData, TrackEvent}; | 7 | use crate::command::GoalKind; |
8 | use crate::habit::{Bit, Count, Float, InnerData, TrackEvent}; | ||
9 | use crate::views::ShadowView; | 9 | use crate::views::ShadowView; |
10 | 10 | ||
11 | pub trait Habit { | 11 | pub trait Habit { |
@@ -20,6 +20,7 @@ pub trait Habit { | |||
20 | fn remaining(&self, date: NaiveDate) -> u32; | 20 | fn remaining(&self, date: NaiveDate) -> u32; |
21 | fn set_goal(&mut self, goal: Self::HabitType); | 21 | fn set_goal(&mut self, goal: Self::HabitType); |
22 | fn set_name(&mut self, name: impl AsRef<str>); | 22 | fn set_name(&mut self, name: impl AsRef<str>); |
23 | fn kind(&self) -> GoalKind; | ||
23 | 24 | ||
24 | fn inner_data_ref(&self) -> &InnerData; | 25 | fn inner_data_ref(&self) -> &InnerData; |
25 | fn inner_data_mut_ref(&mut self) -> &mut InnerData; | 26 | fn inner_data_mut_ref(&mut self) -> &mut InnerData; |
@@ -31,6 +32,7 @@ pub trait Habit { | |||
31 | pub trait HabitWrapper: erased_serde::Serialize { | 32 | pub trait HabitWrapper: erased_serde::Serialize { |
32 | fn draw(&self, printer: &Printer); | 33 | fn draw(&self, printer: &Printer); |
33 | fn goal(&self) -> u32; | 34 | fn goal(&self) -> u32; |
35 | fn kind(&self) -> GoalKind; | ||
34 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | 36 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); |
35 | fn name(&self) -> String; | 37 | fn name(&self) -> String; |
36 | fn on_event(&mut self, event: Event) -> EventResult; | 38 | fn on_event(&mut self, event: Event) -> EventResult; |
@@ -69,6 +71,9 @@ macro_rules! auto_habit_impl { | |||
69 | fn goal(&self) -> u32 { | 71 | fn goal(&self) -> u32 { |
70 | Habit::goal(self) | 72 | Habit::goal(self) |
71 | } | 73 | } |
74 | fn kind(&self) -> GoalKind { | ||
75 | Habit::kind(self) | ||
76 | } | ||
72 | fn modify(&mut self, date: NaiveDate, event: TrackEvent) { | 77 | fn modify(&mut self, date: NaiveDate, event: TrackEvent) { |
73 | Habit::modify(self, date, event); | 78 | Habit::modify(self, date, event); |
74 | } | 79 | } |
@@ -88,5 +93,12 @@ macro_rules! auto_habit_impl { | |||
88 | }; | 93 | }; |
89 | } | 94 | } |
90 | 95 | ||
91 | auto_habit_impl!(Count); | 96 | macro_rules! generate_implementations { |
92 | auto_habit_impl!(Bit); | 97 | ($($x:ident),*) => ( |
98 | $( | ||
99 | auto_habit_impl!($x); | ||
100 | )* | ||
101 | ); | ||
102 | } | ||
103 | |||
104 | generate_implementations!(Count, Bit, Float); | ||