aboutsummaryrefslogtreecommitdiff
path: root/src/habit
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-01-25 09:24:51 +0000
committerAkshay <[email protected]>2021-01-25 09:24:51 +0000
commitcd03d732b1f0df6c020a94135db2db4b690a4937 (patch)
tree94da0cfb56711abb1d8344d1804882c93201902d /src/habit
parent665fd3fb61891b73175690158cde38cf7f94ebc7 (diff)
handle cursor events and entry
Diffstat (limited to 'src/habit')
-rw-r--r--src/habit/bit.rs12
-rw-r--r--src/habit/count.rs12
-rw-r--r--src/habit/traits.rs15
3 files changed, 38 insertions, 1 deletions
diff --git a/src/habit/bit.rs b/src/habit/bit.rs
index 2bbb0ac..7fe6fd9 100644
--- a/src/habit/bit.rs
+++ b/src/habit/bit.rs
@@ -1,8 +1,10 @@
1use std::collections::HashMap; 1use std::collections::HashMap;
2 2
3use chrono::NaiveDate; 3use chrono::NaiveDate;
4use cursive::direction::Absolute;
4use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
5 6
7use crate::app::Cursor;
6use crate::habit::prelude::default_auto; 8use crate::habit::prelude::default_auto;
7use crate::habit::traits::Habit; 9use crate::habit::traits::Habit;
8use crate::habit::{TrackEvent, ViewMode}; 10use crate::habit::{TrackEvent, ViewMode};
@@ -45,6 +47,9 @@ pub struct Bit {
45 view_month_offset: u32, 47 view_month_offset: u32,
46 48
47 #[serde(skip)] 49 #[serde(skip)]
50 cursor: Cursor,
51
52 #[serde(skip)]
48 view_mode: ViewMode, 53 view_mode: ViewMode,
49} 54}
50 55
@@ -56,6 +61,7 @@ impl Bit {
56 goal: CustomBool(true), 61 goal: CustomBool(true),
57 auto, 62 auto,
58 view_month_offset: 0, 63 view_month_offset: 0,
64 cursor: Cursor::new(),
59 view_mode: ViewMode::Day, 65 view_mode: ViewMode::Day,
60 }; 66 };
61 } 67 }
@@ -124,6 +130,12 @@ impl Habit for Bit {
124 fn view_month_offset(&self) -> u32 { 130 fn view_month_offset(&self) -> u32 {
125 self.view_month_offset 131 self.view_month_offset
126 } 132 }
133 fn move_cursor(&mut self, d: Absolute) {
134 self.cursor.do_move(d);
135 }
136 fn cursor(&self) -> Cursor {
137 self.cursor
138 }
127 fn set_view_mode(&mut self, mode: ViewMode) { 139 fn set_view_mode(&mut self, mode: ViewMode) {
128 self.view_mode = mode; 140 self.view_mode = mode;
129 } 141 }
diff --git a/src/habit/count.rs b/src/habit/count.rs
index d351758..b14354c 100644
--- a/src/habit/count.rs
+++ b/src/habit/count.rs
@@ -1,8 +1,10 @@
1use std::collections::HashMap; 1use std::collections::HashMap;
2 2
3use chrono::NaiveDate; 3use chrono::NaiveDate;
4use cursive::direction::Absolute;
4use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
5 6
7use crate::app::Cursor;
6use crate::habit::prelude::default_auto; 8use crate::habit::prelude::default_auto;
7use crate::habit::traits::Habit; 9use crate::habit::traits::Habit;
8use crate::habit::{TrackEvent, ViewMode}; 10use crate::habit::{TrackEvent, ViewMode};
@@ -20,6 +22,9 @@ pub struct Count {
20 view_month_offset: u32, 22 view_month_offset: u32,
21 23
22 #[serde(skip)] 24 #[serde(skip)]
25 cursor: Cursor,
26
27 #[serde(skip)]
23 view_mode: ViewMode, 28 view_mode: ViewMode,
24} 29}
25 30
@@ -31,6 +36,7 @@ impl Count {
31 goal, 36 goal,
32 auto, 37 auto,
33 view_month_offset: 0, 38 view_month_offset: 0,
39 cursor: Cursor::new(),
34 view_mode: ViewMode::Day, 40 view_mode: ViewMode::Day,
35 }; 41 };
36 } 42 }
@@ -101,6 +107,12 @@ impl Habit for Count {
101 fn view_month_offset(&self) -> u32 { 107 fn view_month_offset(&self) -> u32 {
102 self.view_month_offset 108 self.view_month_offset
103 } 109 }
110 fn move_cursor(&mut self, d: Absolute) {
111 self.cursor.do_move(d);
112 }
113 fn cursor(&self) -> Cursor {
114 self.cursor
115 }
104 fn set_view_mode(&mut self, mode: ViewMode) { 116 fn set_view_mode(&mut self, mode: ViewMode) {
105 self.view_mode = mode; 117 self.view_mode = mode;
106 } 118 }
diff --git a/src/habit/traits.rs b/src/habit/traits.rs
index 74fd00b..289fd95 100644
--- a/src/habit/traits.rs
+++ b/src/habit/traits.rs
@@ -1,10 +1,11 @@
1use chrono::NaiveDate; 1use chrono::NaiveDate;
2use cursive::direction::Direction; 2use cursive::direction::{Absolute, 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, TrackEvent, ViewMode}; 9use crate::habit::{Bit, Count, TrackEvent, ViewMode};
9use crate::views::ShadowView; 10use crate::views::ShadowView;
10 11
@@ -24,6 +25,9 @@ pub trait Habit {
24 fn set_view_month_offset(&mut self, offset: u32); 25 fn set_view_month_offset(&mut self, offset: u32);
25 fn view_month_offset(&self) -> u32; 26 fn view_month_offset(&self) -> u32;
26 27
28 fn move_cursor(&mut self, d: Absolute);
29 fn cursor(&self) -> Cursor;
30
27 fn set_view_mode(&mut self, mode: ViewMode); 31 fn set_view_mode(&mut self, mode: ViewMode);
28 fn view_mode(&self) -> ViewMode; 32 fn view_mode(&self) -> ViewMode;
29 33
@@ -44,6 +48,9 @@ pub trait HabitWrapper: erased_serde::Serialize {
44 fn set_view_month_offset(&mut self, offset: u32); 48 fn set_view_month_offset(&mut self, offset: u32);
45 fn view_month_offset(&self) -> u32; 49 fn view_month_offset(&self) -> u32;
46 50
51 fn move_cursor(&mut self, d: Absolute);
52 fn cursor(&self) -> Cursor;
53
47 fn set_view_mode(&mut self, mode: ViewMode); 54 fn set_view_mode(&mut self, mode: ViewMode);
48 fn view_mode(&self) -> ViewMode; 55 fn view_mode(&self) -> ViewMode;
49 56
@@ -87,6 +94,12 @@ macro_rules! auto_habit_impl {
87 fn view_month_offset(&self) -> u32 { 94 fn view_month_offset(&self) -> u32 {
88 Habit::view_month_offset(self) 95 Habit::view_month_offset(self)
89 } 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 }
90 fn set_view_mode(&mut self, mode: ViewMode) { 103 fn set_view_mode(&mut self, mode: ViewMode) {
91 Habit::set_view_mode(self, mode) 104 Habit::set_view_mode(self, mode)
92 } 105 }