diff options
-rw-r--r-- | src/views/habitview.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/views/habitview.rs b/src/views/habitview.rs index ddeb456..c9ca505 100644 --- a/src/views/habitview.rs +++ b/src/views/habitview.rs | |||
@@ -9,6 +9,8 @@ use chrono::{Local, NaiveDate}; | |||
9 | 9 | ||
10 | use crate::habit::{Habit, HabitTrait, HabitType, TrackEvent}; | 10 | use crate::habit::{Habit, HabitTrait, HabitType, TrackEvent}; |
11 | 11 | ||
12 | use serde::Serialize; | ||
13 | |||
12 | pub struct HabitView { | 14 | pub struct HabitView { |
13 | habit: Habit, | 15 | habit: Habit, |
14 | // characters to use | 16 | // characters to use |
@@ -31,19 +33,25 @@ impl HabitView { | |||
31 | true_chr: '·', | 33 | true_chr: '·', |
32 | false_chr: '·', | 34 | false_chr: '·', |
33 | future_chr: '·', | 35 | future_chr: '·', |
34 | view_width: 21, | 36 | view_width: 25, |
35 | view_height: 9, | 37 | view_height: 8, |
36 | reached_color: Color::Dark(BaseColor::Cyan), | 38 | reached_color: Color::Dark(BaseColor::Cyan), |
37 | todo_color: Color::Dark(BaseColor::Magenta), | 39 | todo_color: Color::Dark(BaseColor::Magenta), |
38 | future_color: Color::Light(BaseColor::Black), | 40 | future_color: Color::Light(BaseColor::Black), |
39 | }; | 41 | }; |
40 | } | 42 | } |
41 | pub fn get_title(&self) -> String { | 43 | pub fn get_name(&self) -> String { |
42 | return self.habit.get_name().to_owned(); | 44 | return self.habit.get_name().to_owned(); |
43 | } | 45 | } |
44 | pub fn get_size(&self) -> Vec2 { | 46 | pub fn get_size(&self) -> Vec2 { |
45 | (self.view_width, self.view_height).into() | 47 | (self.view_width, self.view_height).into() |
46 | } | 48 | } |
49 | pub fn remaining(&self) -> u32 { | ||
50 | self.habit.remaining(Local::now().naive_utc().date()) | ||
51 | } | ||
52 | pub fn total(&self) -> u32 { | ||
53 | self.habit.total() | ||
54 | } | ||
47 | } | 55 | } |
48 | 56 | ||
49 | impl View for HabitView { | 57 | impl View for HabitView { |
@@ -56,6 +64,20 @@ impl View for HabitView { | |||
56 | let todo_style = Style::from(self.todo_color); | 64 | let todo_style = Style::from(self.todo_color); |
57 | let future_style = Style::from(self.future_color); | 65 | let future_style = Style::from(self.future_color); |
58 | 66 | ||
67 | printer.with_style( | ||
68 | if !printer.focused { | ||
69 | future_style | ||
70 | } else { | ||
71 | goal_reached_style | ||
72 | }, | ||
73 | |p| { | ||
74 | p.print( | ||
75 | (0, 0), | ||
76 | &format!("{:width$}", self.get_name(), width = self.get_size().x), | ||
77 | ) | ||
78 | }, | ||
79 | ); | ||
80 | |||
59 | for i in 1..=31 { | 81 | for i in 1..=31 { |
60 | let day = NaiveDate::from_ymd_opt(year, month, i); | 82 | let day = NaiveDate::from_ymd_opt(year, month, i); |
61 | let mut day_style; | 83 | let mut day_style; |
@@ -66,7 +88,7 @@ impl View for HabitView { | |||
66 | } else { | 88 | } else { |
67 | day_style = todo_style; | 89 | day_style = todo_style; |
68 | } | 90 | } |
69 | let coords = ((i % 7) * 3, i / 7 + 2); | 91 | let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); |
70 | let day_chr: Box<dyn std::fmt::Display> = match self.habit.get_by_date(d) { | 92 | let day_chr: Box<dyn std::fmt::Display> = match self.habit.get_by_date(d) { |
71 | Some(val) => match val { | 93 | Some(val) => match val { |
72 | HabitType::Bit(b) => { | 94 | HabitType::Bit(b) => { |