aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/app.rs b/src/app.rs
index 93e5def..2d83714 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -48,6 +48,13 @@ impl App {
48 self.habits.retain(|h| h.get_name() != name); 48 self.habits.retain(|h| h.get_name() != name);
49 } 49 }
50 50
51 pub fn get_mode(&self) -> ViewMode {
52 if self.habits.is_empty() {
53 return ViewMode::Day;
54 }
55 return self.habits[self.focus].view_mode();
56 }
57
51 pub fn set_mode(&mut self, mode: ViewMode) { 58 pub fn set_mode(&mut self, mode: ViewMode) {
52 if !self.habits.is_empty() { 59 if !self.habits.is_empty() {
53 self.habits[self.focus].set_view_mode(mode); 60 self.habits[self.focus].set_view_mode(mode);
@@ -115,22 +122,19 @@ impl App {
115 let completed = total - remaining; 122 let completed = total - remaining;
116 123
117 let timestamp = if self.view_month_offset == 0 { 124 let timestamp = if self.view_month_offset == 0 {
118 format!( 125 format!("{}", Local::now().date().format("%d/%b/%y"),)
119 "{:>width$}",
120 Local::now().date().format("%d/%b/%y"),
121 width = CONFIGURATION.view_width * CONFIGURATION.grid_width
122 )
123 } else { 126 } else {
124 let months = self.view_month_offset; 127 let months = self.view_month_offset;
125 format!( 128 format!("{}", format!("{} months ago", months),)
126 "{:>width$}",
127 format!("{} months ago", months),
128 width = CONFIGURATION.view_width * CONFIGURATION.grid_width
129 )
130 }; 129 };
131 130
132 StatusLine { 131 StatusLine {
133 0: format!("Today: {} completed, {} remaining", completed, remaining), 132 0: format!(
133 "Today: {} completed, {} remaining --{}--",
134 completed,
135 remaining,
136 self.get_mode()
137 ),
134 1: timestamp, 138 1: timestamp,
135 } 139 }
136 } 140 }
@@ -218,18 +222,27 @@ impl App {
218impl View for App { 222impl View for App {
219 fn draw(&self, printer: &Printer) { 223 fn draw(&self, printer: &Printer) {
220 let grid_width = CONFIGURATION.grid_width; 224 let grid_width = CONFIGURATION.grid_width;
225 let view_width = CONFIGURATION.view_width;
226 let view_height = CONFIGURATION.view_height;
221 let mut offset = Vec2::zero(); 227 let mut offset = Vec2::zero();
222 for (idx, i) in self.habits.iter().enumerate() { 228 for (idx, i) in self.habits.iter().enumerate() {
223 if idx >= grid_width && idx % grid_width == 0 { 229 if idx >= grid_width && idx % grid_width == 0 {
224 offset = offset.map_y(|y| y + CONFIGURATION.view_height).map_x(|_| 0); 230 offset = offset.map_y(|y| y + view_height).map_x(|_| 0);
225 } 231 }
226 i.draw(&printer.offset(offset).focused(self.focus == idx)); 232 i.draw(&printer.offset(offset).focused(self.focus == idx));
227 offset = offset.map_x(|x| x + CONFIGURATION.view_width + 2); 233 offset = offset.map_x(|x| x + view_width + 2);
228 } 234 }
229 235
230 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2); 236 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2);
231 printer.print(offset, &self.status().1); // right status 237
232 printer.print(offset, &self.status().0); // left status 238 let status = self.status();
239 printer.print(offset, &status.0); // left status
240
241 let full = grid_width * (view_width + 2);
242 offset = offset
243 .map_x(|_| full - status.1.len())
244 .map_y(|_| self.max_size().y - 2);
245 printer.print(offset, &status.1); // right status
233 } 246 }
234 247
235 fn required_size(&mut self, _: Vec2) -> Vec2 { 248 fn required_size(&mut self, _: Vec2) -> Vec2 {