diff options
author | Akshay <[email protected]> | 2020-07-11 17:47:45 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-07-11 17:47:45 +0100 |
commit | ce6db76dc3d8f2f8b43a2e8769cf17416e57a065 (patch) | |
tree | 6383763aa474040d4a0060de24871a60e7231781 /src/habit.rs | |
parent | 33d9ba70bee7e6271404d1db7b2724885ee5c9e8 (diff) |
begin work on month mode
Diffstat (limited to 'src/habit.rs')
-rw-r--r-- | src/habit.rs | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/src/habit.rs b/src/habit.rs index 48dd363..92e0b9f 100644 --- a/src/habit.rs +++ b/src/habit.rs | |||
@@ -15,6 +15,19 @@ pub enum TrackEvent { | |||
15 | Decrement, | 15 | Decrement, |
16 | } | 16 | } |
17 | 17 | ||
18 | #[derive(Debug, PartialEq, Serialize, Deserialize)] | ||
19 | pub enum ViewMode { | ||
20 | Day, | ||
21 | Month, | ||
22 | Year, | ||
23 | } | ||
24 | |||
25 | impl std::default::Default for ViewMode { | ||
26 | fn default() -> Self { | ||
27 | ViewMode::Day | ||
28 | } | ||
29 | } | ||
30 | |||
18 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] | 31 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
19 | pub struct CustomBool(bool); | 32 | pub struct CustomBool(bool); |
20 | 33 | ||
@@ -51,8 +64,12 @@ pub trait Habit { | |||
51 | fn remaining(&self, date: NaiveDate) -> u32; | 64 | fn remaining(&self, date: NaiveDate) -> u32; |
52 | fn total(&self) -> u32; | 65 | fn total(&self) -> u32; |
53 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | 66 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); |
67 | |||
54 | fn set_view_month_offset(&mut self, offset: u32); | 68 | fn set_view_month_offset(&mut self, offset: u32); |
55 | fn view_month_offset(&self) -> u32; | 69 | fn view_month_offset(&self) -> u32; |
70 | |||
71 | fn set_view_mode(&mut self, mode: ViewMode); | ||
72 | fn view_mode(&self) -> ViewMode; | ||
56 | } | 73 | } |
57 | 74 | ||
58 | #[typetag::serde(tag = "type")] | 75 | #[typetag::serde(tag = "type")] |
@@ -64,9 +81,13 @@ pub trait HabitWrapper: erased_serde::Serialize { | |||
64 | fn on_event(&mut self, event: Event) -> EventResult; | 81 | fn on_event(&mut self, event: Event) -> EventResult; |
65 | fn required_size(&mut self, _: Vec2) -> Vec2; | 82 | fn required_size(&mut self, _: Vec2) -> Vec2; |
66 | fn take_focus(&mut self, _: Direction) -> bool; | 83 | fn take_focus(&mut self, _: Direction) -> bool; |
84 | fn get_name(&self) -> String; | ||
85 | |||
67 | fn set_view_month_offset(&mut self, offset: u32); | 86 | fn set_view_month_offset(&mut self, offset: u32); |
68 | fn view_month_offset(&self) -> u32; | 87 | fn view_month_offset(&self) -> u32; |
69 | fn get_name(&self) -> String; | 88 | |
89 | fn set_view_mode(&mut self, mode: ViewMode); | ||
90 | fn view_mode(&self) -> ViewMode; | ||
70 | } | 91 | } |
71 | 92 | ||
72 | macro_rules! auto_habit_impl { | 93 | macro_rules! auto_habit_impl { |
@@ -97,11 +118,17 @@ macro_rules! auto_habit_impl { | |||
97 | fn set_view_month_offset(&mut self, offset: u32) { | 118 | fn set_view_month_offset(&mut self, offset: u32) { |
98 | Habit::set_view_month_offset(self, offset) | 119 | Habit::set_view_month_offset(self, offset) |
99 | } | 120 | } |
121 | fn get_name(&self) -> String { | ||
122 | Habit::name(self) | ||
123 | } | ||
100 | fn view_month_offset(&self) -> u32 { | 124 | fn view_month_offset(&self) -> u32 { |
101 | Habit::view_month_offset(self) | 125 | Habit::view_month_offset(self) |
102 | } | 126 | } |
103 | fn get_name(&self) -> String { | 127 | fn set_view_mode(&mut self, mode: ViewMode) { |
104 | Habit::name(self) | 128 | Habit::set_view_mode(&mut self, mode: ViewMode) |
129 | } | ||
130 | fn view_mode(&self) -> ViewMode { | ||
131 | Habit::view_mode(self) | ||
105 | } | 132 | } |
106 | } | 133 | } |
107 | }; | 134 | }; |
@@ -118,6 +145,9 @@ pub struct Count { | |||
118 | 145 | ||
119 | #[serde(skip)] | 146 | #[serde(skip)] |
120 | view_month_offset: u32, | 147 | view_month_offset: u32, |
148 | |||
149 | #[serde(skip)] | ||
150 | view_mode: ViewMode, | ||
121 | } | 151 | } |
122 | 152 | ||
123 | impl Count { | 153 | impl Count { |
@@ -127,6 +157,7 @@ impl Count { | |||
127 | stats: HashMap::new(), | 157 | stats: HashMap::new(), |
128 | goal, | 158 | goal, |
129 | view_month_offset: 0, | 159 | view_month_offset: 0, |
160 | view_mode: ViewMode::Day, | ||
130 | }; | 161 | }; |
131 | } | 162 | } |
132 | } | 163 | } |
@@ -193,6 +224,12 @@ impl Habit for Count { | |||
193 | fn view_month_offset(&self) -> u32 { | 224 | fn view_month_offset(&self) -> u32 { |
194 | self.view_month_offset | 225 | self.view_month_offset |
195 | } | 226 | } |
227 | fn set_view_mode(&mut self, mode: ViewMode) { | ||
228 | self.view_mode = mode; | ||
229 | } | ||
230 | fn view_mode(&self) -> ViewMode { | ||
231 | self.view_mode | ||
232 | } | ||
196 | } | 233 | } |
197 | 234 | ||
198 | #[derive(Debug, Serialize, Deserialize)] | 235 | #[derive(Debug, Serialize, Deserialize)] |
@@ -203,6 +240,9 @@ pub struct Bit { | |||
203 | 240 | ||
204 | #[serde(skip)] | 241 | #[serde(skip)] |
205 | view_month_offset: u32, | 242 | view_month_offset: u32, |
243 | |||
244 | #[serde(skip)] | ||
245 | view_mode: ViewMode, | ||
206 | } | 246 | } |
207 | 247 | ||
208 | impl Bit { | 248 | impl Bit { |
@@ -212,6 +252,7 @@ impl Bit { | |||
212 | stats: HashMap::new(), | 252 | stats: HashMap::new(), |
213 | goal: CustomBool(true), | 253 | goal: CustomBool(true), |
214 | view_month_offset: 0, | 254 | view_month_offset: 0, |
255 | view_mode: ViewMode::Day, | ||
215 | }; | 256 | }; |
216 | } | 257 | } |
217 | } | 258 | } |
@@ -268,4 +309,10 @@ impl Habit for Bit { | |||
268 | fn view_month_offset(&self) -> u32 { | 309 | fn view_month_offset(&self) -> u32 { |
269 | self.view_month_offset | 310 | self.view_month_offset |
270 | } | 311 | } |
312 | fn set_view_mode(&mut self, mode: ViewMode) { | ||
313 | self.view_mode = mode; | ||
314 | } | ||
315 | fn view_mode(&self) -> ViewMode { | ||
316 | self.view_mode | ||
317 | } | ||
271 | } | 318 | } |