diff options
-rw-r--r-- | src/habit.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/habit.rs b/src/habit.rs index 13a2bd2..9872bbc 100644 --- a/src/habit.rs +++ b/src/habit.rs | |||
@@ -51,6 +51,8 @@ pub trait Habit { | |||
51 | fn remaining(&self, date: NaiveDate) -> u32; | 51 | fn remaining(&self, date: NaiveDate) -> u32; |
52 | fn total(&self) -> u32; | 52 | fn total(&self) -> u32; |
53 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | 53 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); |
54 | fn set_view_month_offset(&mut self, offset: u32); | ||
55 | fn view_month_offset(&self) -> u32; | ||
54 | } | 56 | } |
55 | 57 | ||
56 | #[typetag::serde(tag = "type")] | 58 | #[typetag::serde(tag = "type")] |
@@ -62,6 +64,8 @@ pub trait HabitWrapper: erased_serde::Serialize { | |||
62 | fn on_event(&mut self, event: Event) -> EventResult; | 64 | fn on_event(&mut self, event: Event) -> EventResult; |
63 | fn required_size(&mut self, _: Vec2) -> Vec2; | 65 | fn required_size(&mut self, _: Vec2) -> Vec2; |
64 | fn take_focus(&mut self, _: Direction) -> bool; | 66 | fn take_focus(&mut self, _: Direction) -> bool; |
67 | fn set_view_month_offset(&mut self, offset: u32); | ||
68 | fn view_month_offset(&self) -> u32; | ||
65 | } | 69 | } |
66 | 70 | ||
67 | macro_rules! auto_habit_impl { | 71 | macro_rules! auto_habit_impl { |
@@ -89,6 +93,12 @@ macro_rules! auto_habit_impl { | |||
89 | fn take_focus(&mut self, d: Direction) -> bool { | 93 | fn take_focus(&mut self, d: Direction) -> bool { |
90 | ShadowView::take_focus(self, d) | 94 | ShadowView::take_focus(self, d) |
91 | } | 95 | } |
96 | fn set_view_month_offset(&mut self, offset: u32) { | ||
97 | Habit::set_view_month_offset(self, offset) | ||
98 | } | ||
99 | fn view_month_offset(&self) -> u32 { | ||
100 | Habit::view_month_offset(self) | ||
101 | } | ||
92 | } | 102 | } |
93 | }; | 103 | }; |
94 | } | 104 | } |
@@ -101,6 +111,9 @@ pub struct Count { | |||
101 | name: String, | 111 | name: String, |
102 | stats: HashMap<NaiveDate, u32>, | 112 | stats: HashMap<NaiveDate, u32>, |
103 | goal: u32, | 113 | goal: u32, |
114 | |||
115 | #[serde(skip)] | ||
116 | view_month_offset: u32, | ||
104 | } | 117 | } |
105 | 118 | ||
106 | impl Count { | 119 | impl Count { |
@@ -109,6 +122,7 @@ impl Count { | |||
109 | name: name.as_ref().to_owned(), | 122 | name: name.as_ref().to_owned(), |
110 | stats: HashMap::new(), | 123 | stats: HashMap::new(), |
111 | goal, | 124 | goal, |
125 | view_month_offset: 0, | ||
112 | }; | 126 | }; |
113 | } | 127 | } |
114 | } | 128 | } |
@@ -169,6 +183,12 @@ impl Habit for Count { | |||
169 | self.insert_entry(date, 1); | 183 | self.insert_entry(date, 1); |
170 | } | 184 | } |
171 | } | 185 | } |
186 | fn set_view_month_offset(&mut self, offset: u32) { | ||
187 | self.view_month_offset = offset; | ||
188 | } | ||
189 | fn view_month_offset(&self) -> u32 { | ||
190 | self.view_month_offset | ||
191 | } | ||
172 | } | 192 | } |
173 | 193 | ||
174 | #[derive(Debug, Serialize, Deserialize)] | 194 | #[derive(Debug, Serialize, Deserialize)] |
@@ -176,6 +196,9 @@ pub struct Bit { | |||
176 | name: String, | 196 | name: String, |
177 | stats: HashMap<NaiveDate, CustomBool>, | 197 | stats: HashMap<NaiveDate, CustomBool>, |
178 | goal: CustomBool, | 198 | goal: CustomBool, |
199 | |||
200 | #[serde(skip)] | ||
201 | view_month_offset: u32, | ||
179 | } | 202 | } |
180 | 203 | ||
181 | impl Bit { | 204 | impl Bit { |
@@ -184,6 +207,7 @@ impl Bit { | |||
184 | name: name.as_ref().to_owned(), | 207 | name: name.as_ref().to_owned(), |
185 | stats: HashMap::new(), | 208 | stats: HashMap::new(), |
186 | goal: CustomBool(true), | 209 | goal: CustomBool(true), |
210 | view_month_offset: 0, | ||
187 | }; | 211 | }; |
188 | } | 212 | } |
189 | } | 213 | } |
@@ -234,4 +258,10 @@ impl Habit for Bit { | |||
234 | self.insert_entry(date, CustomBool(true)); | 258 | self.insert_entry(date, CustomBool(true)); |
235 | } | 259 | } |
236 | } | 260 | } |
261 | fn set_view_month_offset(&mut self, offset: u32) { | ||
262 | self.view_month_offset = offset; | ||
263 | } | ||
264 | fn view_month_offset(&self) -> u32 { | ||
265 | self.view_month_offset | ||
266 | } | ||
237 | } | 267 | } |