aboutsummaryrefslogtreecommitdiff
path: root/src/habit/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/habit/traits.rs')
-rw-r--r--src/habit/traits.rs46
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
6use typetag; 6use typetag;
7 7
8use crate::habit::{Bit, Count, TrackEvent, ViewMode}; 8use crate::habit::{Bit, Count, InnerData, TrackEvent};
9use crate::views::ShadowView; 9use crate::views::ShadowView;
10 10
11pub trait Habit { 11pub 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")]
34pub trait HabitWrapper: erased_serde::Serialize { 31pub 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)