diff options
author | Akshay <[email protected]> | 2021-02-21 05:13:32 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-02-21 05:13:32 +0000 |
commit | 38d9dfee224ebcd088c0ebecd9e1243994eea409 (patch) | |
tree | 1215766f07b1c2eaf68f20aba284e710eb9a24a3 /src/habit/traits.rs | |
parent | ad5bf181a176e64c9f70a292cad870e6e8110f09 (diff) | |
parent | 53f7a679a0cf7a510de13d67cf370988f71c0d08 (diff) |
Merge branch 'cursor' into master
Diffstat (limited to 'src/habit/traits.rs')
-rw-r--r-- | src/habit/traits.rs | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/src/habit/traits.rs b/src/habit/traits.rs index 74fd00b..24d941d 100644 --- a/src/habit/traits.rs +++ b/src/habit/traits.rs | |||
@@ -5,47 +5,41 @@ use cursive::{Printer, Vec2}; | |||
5 | 5 | ||
6 | use typetag; | 6 | use typetag; |
7 | 7 | ||
8 | use crate::habit::{Bit, Count, TrackEvent, ViewMode}; | 8 | use crate::habit::{Bit, Count, InnerData, TrackEvent}; |
9 | use crate::views::ShadowView; | 9 | use crate::views::ShadowView; |
10 | 10 | ||
11 | pub trait Habit { | 11 | pub trait Habit { |
12 | type HabitType; | 12 | type HabitType; |
13 | 13 | ||
14 | fn set_name(&mut self, name: impl AsRef<str>); | ||
15 | fn set_goal(&mut self, goal: Self::HabitType); | ||
16 | fn name(&self) -> String; | ||
17 | fn get_by_date(&self, date: NaiveDate) -> Option<&Self::HabitType>; | 14 | fn get_by_date(&self, date: NaiveDate) -> Option<&Self::HabitType>; |
15 | fn goal(&self) -> u32; | ||
18 | fn insert_entry(&mut self, date: NaiveDate, val: Self::HabitType); | 16 | fn insert_entry(&mut self, date: NaiveDate, val: Self::HabitType); |
17 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | ||
18 | fn name(&self) -> String; | ||
19 | fn reached_goal(&self, date: NaiveDate) -> bool; | 19 | fn reached_goal(&self, date: NaiveDate) -> bool; |
20 | fn remaining(&self, date: NaiveDate) -> u32; | 20 | fn remaining(&self, date: NaiveDate) -> u32; |
21 | fn goal(&self) -> u32; | 21 | fn set_goal(&mut self, goal: Self::HabitType); |
22 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | 22 | fn set_name(&mut self, name: impl AsRef<str>); |
23 | |||
24 | fn set_view_month_offset(&mut self, offset: u32); | ||
25 | fn view_month_offset(&self) -> u32; | ||
26 | 23 | ||
27 | fn set_view_mode(&mut self, mode: ViewMode); | 24 | fn inner_data_ref(&self) -> &InnerData; |
28 | fn view_mode(&self) -> ViewMode; | 25 | fn inner_data_mut_ref(&mut self) -> &mut InnerData; |
29 | 26 | ||
30 | fn is_auto(&self) -> bool; | 27 | fn is_auto(&self) -> bool; |
31 | } | 28 | } |
32 | 29 | ||
33 | #[typetag::serde(tag = "type")] | 30 | #[typetag::serde(tag = "type")] |
34 | pub trait HabitWrapper: erased_serde::Serialize { | 31 | pub trait HabitWrapper: erased_serde::Serialize { |
35 | fn remaining(&self, date: NaiveDate) -> u32; | 32 | fn draw(&self, printer: &Printer); |
36 | fn goal(&self) -> u32; | 33 | fn goal(&self) -> u32; |
37 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); | 34 | fn modify(&mut self, date: NaiveDate, event: TrackEvent); |
38 | fn draw(&self, printer: &Printer); | 35 | fn name(&self) -> String; |
39 | fn on_event(&mut self, event: Event) -> EventResult; | 36 | fn on_event(&mut self, event: Event) -> EventResult; |
37 | fn remaining(&self, date: NaiveDate) -> u32; | ||
40 | fn required_size(&mut self, _: Vec2) -> Vec2; | 38 | fn required_size(&mut self, _: Vec2) -> Vec2; |
41 | fn take_focus(&mut self, _: Direction) -> bool; | 39 | fn take_focus(&mut self, _: Direction) -> bool; |
42 | fn name(&self) -> String; | ||
43 | |||
44 | fn set_view_month_offset(&mut self, offset: u32); | ||
45 | fn view_month_offset(&self) -> u32; | ||
46 | 40 | ||
47 | fn set_view_mode(&mut self, mode: ViewMode); | 41 | fn inner_data_ref(&self) -> &InnerData; |
48 | fn view_mode(&self) -> ViewMode; | 42 | fn inner_data_mut_ref(&mut self) -> &mut InnerData; |
49 | 43 | ||
50 | fn is_auto(&self) -> bool; | 44 | fn is_auto(&self) -> bool; |
51 | } | 45 | } |
@@ -81,17 +75,11 @@ macro_rules! auto_habit_impl { | |||
81 | fn name(&self) -> String { | 75 | fn name(&self) -> String { |
82 | Habit::name(self) | 76 | Habit::name(self) |
83 | } | 77 | } |
84 | fn set_view_month_offset(&mut self, offset: u32) { | 78 | fn inner_data_ref(&self) -> &InnerData { |
85 | Habit::set_view_month_offset(self, offset) | 79 | Habit::inner_data_ref(self) |
86 | } | ||
87 | fn view_month_offset(&self) -> u32 { | ||
88 | Habit::view_month_offset(self) | ||
89 | } | ||
90 | fn set_view_mode(&mut self, mode: ViewMode) { | ||
91 | Habit::set_view_mode(self, mode) | ||
92 | } | 80 | } |
93 | fn view_mode(&self) -> ViewMode { | 81 | fn inner_data_mut_ref(&mut self) -> &mut InnerData { |
94 | Habit::view_mode(self) | 82 | Habit::inner_data_mut_ref(self) |
95 | } | 83 | } |
96 | fn is_auto(&self) -> bool { | 84 | fn is_auto(&self) -> bool { |
97 | Habit::is_auto(self) | 85 | Habit::is_auto(self) |