diff options
author | Akshay <[email protected]> | 2020-07-12 05:00:29 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-07-12 05:00:29 +0100 |
commit | 0b18c65466a59b1c9f8d1bfbe596fc2750571dfb (patch) | |
tree | 7ce5dce6c70c4212153812bab78d2f3c3f462694 | |
parent | fbb0c754f4029cc93033ff4aabb28a8ab9c1e7e7 (diff) |
fix trait bounds bug, prep for view modes
-rw-r--r-- | src/habit.rs | 10 | ||||
-rw-r--r-- | src/views.rs | 47 |
2 files changed, 29 insertions, 28 deletions
diff --git a/src/habit.rs b/src/habit.rs index 92e0b9f..5469aab 100644 --- a/src/habit.rs +++ b/src/habit.rs | |||
@@ -15,7 +15,7 @@ pub enum TrackEvent { | |||
15 | Decrement, | 15 | Decrement, |
16 | } | 16 | } |
17 | 17 | ||
18 | #[derive(Debug, PartialEq, Serialize, Deserialize)] | 18 | #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] |
19 | pub enum ViewMode { | 19 | pub enum ViewMode { |
20 | Day, | 20 | Day, |
21 | Month, | 21 | Month, |
@@ -115,17 +115,17 @@ macro_rules! auto_habit_impl { | |||
115 | fn take_focus(&mut self, d: Direction) -> bool { | 115 | fn take_focus(&mut self, d: Direction) -> bool { |
116 | ShadowView::take_focus(self, d) | 116 | ShadowView::take_focus(self, d) |
117 | } | 117 | } |
118 | fn set_view_month_offset(&mut self, offset: u32) { | ||
119 | Habit::set_view_month_offset(self, offset) | ||
120 | } | ||
121 | fn get_name(&self) -> String { | 118 | fn get_name(&self) -> String { |
122 | Habit::name(self) | 119 | Habit::name(self) |
123 | } | 120 | } |
121 | fn set_view_month_offset(&mut self, offset: u32) { | ||
122 | Habit::set_view_month_offset(self, offset) | ||
123 | } | ||
124 | fn view_month_offset(&self) -> u32 { | 124 | fn view_month_offset(&self) -> u32 { |
125 | Habit::view_month_offset(self) | 125 | Habit::view_month_offset(self) |
126 | } | 126 | } |
127 | fn set_view_mode(&mut self, mode: ViewMode) { | 127 | fn set_view_mode(&mut self, mode: ViewMode) { |
128 | Habit::set_view_mode(&mut self, mode: ViewMode) | 128 | Habit::set_view_mode(self, mode) |
129 | } | 129 | } |
130 | fn view_mode(&self) -> ViewMode { | 130 | fn view_mode(&self) -> ViewMode { |
131 | Habit::view_mode(self) | 131 | Habit::view_mode(self) |
diff --git a/src/views.rs b/src/views.rs index facbd55..3e623a9 100644 --- a/src/views.rs +++ b/src/views.rs | |||
@@ -7,7 +7,8 @@ use cursive::{Printer, Vec2}; | |||
7 | use chrono::prelude::*; | 7 | use chrono::prelude::*; |
8 | use chrono::{Duration, Local, NaiveDate}; | 8 | use chrono::{Duration, Local, NaiveDate}; |
9 | 9 | ||
10 | use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; | 10 | use crate::habit::{Bit, Count, Habit, TrackEvent}; |
11 | |||
11 | use crate::CONFIGURATION; | 12 | use crate::CONFIGURATION; |
12 | 13 | ||
13 | pub trait ShadowView { | 14 | pub trait ShadowView { |
@@ -70,29 +71,29 @@ where | |||
70 | // ViewMode::Month => | 71 | // ViewMode::Month => |
71 | // } | 72 | // } |
72 | 73 | ||
73 | let draw_day = |p: &Printer| { | 74 | //let draw_day = |printer: &Printer| { |
74 | let mut i = 1; | 75 | let mut i = 1; |
75 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i) { | 76 | while let Some(d) = NaiveDate::from_ymd_opt(year, month, i) { |
76 | let day_style; | 77 | let day_style; |
77 | if self.reached_goal(d) { | 78 | if self.reached_goal(d) { |
78 | day_style = goal_reached_style; | 79 | day_style = goal_reached_style; |
79 | } else { | 80 | } else { |
80 | day_style = todo_style; | 81 | day_style = todo_style; |
81 | } | ||
82 | let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); | ||
83 | if let Some(c) = self.get_by_date(d) { | ||
84 | printer.with_style(day_style, |p| { | ||
85 | p.print(coords, &format!("{:^3}", c)); | ||
86 | }); | ||
87 | } else { | ||
88 | printer.with_style(future_style, |p| { | ||
89 | p.print(coords, &format!("{:^3}", CONFIGURATION.future_chr)); | ||
90 | }); | ||
91 | } | ||
92 | i += 1; | ||
93 | } | 82 | } |
94 | }; | 83 | let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); |
95 | draw_day(printer); | 84 | if let Some(c) = self.get_by_date(d) { |
85 | printer.with_style(day_style, |p| { | ||
86 | p.print(coords, &format!("{:^3}", c)); | ||
87 | }); | ||
88 | } else { | ||
89 | printer.with_style(future_style, |p| { | ||
90 | p.print(coords, &format!("{:^3}", CONFIGURATION.future_chr)); | ||
91 | }); | ||
92 | } | ||
93 | i += 1; | ||
94 | } | ||
95 | //}; | ||
96 | //draw_day(printer); | ||
96 | } | 97 | } |
97 | 98 | ||
98 | fn required_size(&mut self, _: Vec2) -> Vec2 { | 99 | fn required_size(&mut self, _: Vec2) -> Vec2 { |