From 39b21b4501e48da56ddbdbadc97c3ccf32746029 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 26 Feb 2020 12:26:37 +0530 Subject: fix null entry with bits, add remaining api --- src/habit.rs | 15 ++++++++++++++- src/views/habitview.rs | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src') 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 { fn get_by_date(&self, date: NaiveDate) -> Option<&HabitType>; fn insert_entry(&mut self, date: NaiveDate, val: HabitType); fn reached_goal(&self, date: NaiveDate) -> bool; + fn remaining(&self, date: NaiveDate) -> u32; } #[derive(Serialize, Debug)] @@ -73,7 +74,7 @@ impl Habit { } } else { match self.goal { - HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(false)), + HabitType::Bit(_) => self.insert_entry(date, HabitType::Bit(true)), HabitType::Count(_) => self.insert_entry(date, HabitType::Count(0)), } } @@ -109,4 +110,16 @@ impl HabitTrait for Habit { } return false; } + fn remaining(&self, date: NaiveDate) -> u32 { + if self.reached_goal(date) { + return 0; + } else if let Some(val) = self.stats.get(&date) { + match val { + HabitType::Bit(_) => return 1, + HabitType::Count(c) => return self.goal.inner_count() - *c, + } + } else { + return 0; + } + } } 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 { pub fn get_title(&self) -> String { return self.habit.get_name().to_owned(); } + pub fn get_size(&self) -> Vec2 { + (self.view_width, self.view_height).into() + } } impl View for HabitView { -- cgit v1.2.3