diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/habit.rs | 15 | ||||
-rw-r--r-- | src/views/habitview.rs | 3 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/habit.rs b/src/habit.rs index cd1703e..8527ac2 100644 --- a/src/habit.rs +++ b/src/habit.rs | |||
@@ -33,6 +33,7 @@ pub trait HabitTrait { | |||
33 | fn get_by_date(&self, date: NaiveDate) -> Option<&HabitType>; | 33 | fn get_by_date(&self, date: NaiveDate) -> Option<&HabitType>; |
34 | fn insert_entry(&mut self, date: NaiveDate, val: HabitType); | 34 | fn insert_entry(&mut self, date: NaiveDate, val: HabitType); |
35 | fn reached_goal(&self, date: NaiveDate) -> bool; | 35 | fn reached_goal(&self, date: NaiveDate) -> bool; |
36 | fn remaining(&self, date: NaiveDate) -> u32; | ||
36 | } | 37 | } |
37 | 38 | ||
38 | #[derive(Serialize, Debug)] | 39 | #[derive(Serialize, Debug)] |
@@ -73,7 +74,7 @@ impl Habit { | |||
73 | } | 74 | } |
74 | } else { | 75 | } else { |
75 | match self.goal { | 76 | match self.goal { |
76 | HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(false)), | 77 | HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(true)), |
77 | HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)), | 78 | HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)), |
78 | } | 79 | } |
79 | } | 80 | } |
@@ -109,4 +110,16 @@ impl HabitTrait for Habit { | |||
109 | } | 110 | } |
110 | return false; | 111 | return false; |
111 | } | 112 | } |
113 | fn remaining(&self, date: NaiveDate) -> u32 { | ||
114 | if self.reached_goal(date) { | ||
115 | return 0; | ||
116 | } else if let Some(val) = self.stats.get(&date) { | ||
117 | match val { | ||
118 | HabitType::Bit(_) => return 1, | ||
119 | HabitType::Count(c) => return self.goal.inner_count() - *c, | ||
120 | } | ||
121 | } else { | ||
122 | return 0; | ||
123 | } | ||
124 | } | ||
112 | } | 125 | } |
diff --git a/src/views/habitview.rs b/src/views/habitview.rs index 3ae0c90..ddeb456 100644 --- a/src/views/habitview.rs +++ b/src/views/habitview.rs | |||
@@ -41,6 +41,9 @@ impl HabitView { | |||
41 | pub fn get_title(&self) -> String { | 41 | pub fn get_title(&self) -> String { |
42 | return self.habit.get_name().to_owned(); | 42 | return self.habit.get_name().to_owned(); |
43 | } | 43 | } |
44 | pub fn get_size(&self) -> Vec2 { | ||
45 | (self.view_width, self.view_height).into() | ||
46 | } | ||
44 | } | 47 | } |
45 | 48 | ||
46 | impl View for HabitView { | 49 | impl View for HabitView { |