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.rs61
1 files changed, 18 insertions, 43 deletions
diff --git a/src/habit/traits.rs b/src/habit/traits.rs
index 289fd95..24d941d 100644
--- a/src/habit/traits.rs
+++ b/src/habit/traits.rs
@@ -1,58 +1,45 @@
1use chrono::NaiveDate; 1use chrono::NaiveDate;
2use cursive::direction::{Absolute, Direction}; 2use cursive::direction::Direction;
3use cursive::event::{Event, EventResult}; 3use cursive::event::{Event, EventResult};
4use cursive::{Printer, Vec2}; 4use cursive::{Printer, Vec2};
5 5
6use typetag; 6use typetag;
7 7
8use crate::app::Cursor; 8use crate::habit::{Bit, Count, InnerData, TrackEvent};
9use crate::habit::{Bit, Count, TrackEvent, ViewMode};
10use crate::views::ShadowView; 9use crate::views::ShadowView;
11 10
12pub trait Habit { 11pub trait Habit {
13 type HabitType; 12 type HabitType;
14 13
15 fn set_name(&mut self, name: impl AsRef<str>);
16 fn set_goal(&mut self, goal: Self::HabitType);
17 fn name(&self) -> String;
18 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;
19 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;
20 fn reached_goal(&self, date: NaiveDate) -> bool; 19 fn reached_goal(&self, date: NaiveDate) -> bool;
21 fn remaining(&self, date: NaiveDate) -> u32; 20 fn remaining(&self, date: NaiveDate) -> u32;
22 fn goal(&self) -> u32; 21 fn set_goal(&mut self, goal: Self::HabitType);
23 fn modify(&mut self, date: NaiveDate, event: TrackEvent); 22 fn set_name(&mut self, name: impl AsRef<str>);
24
25 fn set_view_month_offset(&mut self, offset: u32);
26 fn view_month_offset(&self) -> u32;
27
28 fn move_cursor(&mut self, d: Absolute);
29 fn cursor(&self) -> Cursor;
30 23
31 fn set_view_mode(&mut self, mode: ViewMode); 24 fn inner_data_ref(&self) -> &InnerData;
32 fn view_mode(&self) -> ViewMode; 25 fn inner_data_mut_ref(&mut self) -> &mut InnerData;
33 26
34 fn is_auto(&self) -> bool; 27 fn is_auto(&self) -> bool;
35} 28}
36 29
37#[typetag::serde(tag = "type")] 30#[typetag::serde(tag = "type")]
38pub trait HabitWrapper: erased_serde::Serialize { 31pub trait HabitWrapper: erased_serde::Serialize {
39 fn remaining(&self, date: NaiveDate) -> u32; 32 fn draw(&self, printer: &Printer);
40 fn goal(&self) -> u32; 33 fn goal(&self) -> u32;
41 fn modify(&mut self, date: NaiveDate, event: TrackEvent); 34 fn modify(&mut self, date: NaiveDate, event: TrackEvent);
42 fn draw(&self, printer: &Printer); 35 fn name(&self) -> String;
43 fn on_event(&mut self, event: Event) -> EventResult; 36 fn on_event(&mut self, event: Event) -> EventResult;
37 fn remaining(&self, date: NaiveDate) -> u32;
44 fn required_size(&mut self, _: Vec2) -> Vec2; 38 fn required_size(&mut self, _: Vec2) -> Vec2;
45 fn take_focus(&mut self, _: Direction) -> bool; 39 fn take_focus(&mut self, _: Direction) -> bool;
46 fn name(&self) -> String;
47 40
48 fn set_view_month_offset(&mut self, offset: u32); 41 fn inner_data_ref(&self) -> &InnerData;
49 fn view_month_offset(&self) -> u32; 42 fn inner_data_mut_ref(&mut self) -> &mut InnerData;
50
51 fn move_cursor(&mut self, d: Absolute);
52 fn cursor(&self) -> Cursor;
53
54 fn set_view_mode(&mut self, mode: ViewMode);
55 fn view_mode(&self) -> ViewMode;
56 43
57 fn is_auto(&self) -> bool; 44 fn is_auto(&self) -> bool;
58} 45}
@@ -88,23 +75,11 @@ macro_rules! auto_habit_impl {
88 fn name(&self) -> String { 75 fn name(&self) -> String {
89 Habit::name(self) 76 Habit::name(self)
90 } 77 }
91 fn set_view_month_offset(&mut self, offset: u32) { 78 fn inner_data_ref(&self) -> &InnerData {
92 Habit::set_view_month_offset(self, offset) 79 Habit::inner_data_ref(self)
93 }
94 fn view_month_offset(&self) -> u32 {
95 Habit::view_month_offset(self)
96 }
97 fn move_cursor(&mut self, d: Absolute) {
98 Habit::move_cursor(self, d)
99 }
100 fn cursor(&self) -> Cursor {
101 Habit::cursor(self)
102 }
103 fn set_view_mode(&mut self, mode: ViewMode) {
104 Habit::set_view_mode(self, mode)
105 } 80 }
106 fn view_mode(&self) -> ViewMode { 81 fn inner_data_mut_ref(&mut self) -> &mut InnerData {
107 Habit::view_mode(self) 82 Habit::inner_data_mut_ref(self)
108 } 83 }
109 fn is_auto(&self) -> bool { 84 fn is_auto(&self) -> bool {
110 Habit::is_auto(self) 85 Habit::is_auto(self)