aboutsummaryrefslogtreecommitdiff
path: root/src/app/impl_view.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-08-03 11:35:55 +0100
committerAkshay <[email protected]>2020-08-03 11:35:55 +0100
commitfcaf919fd1e176e4b8dd6d5d21e25db7f68c32a8 (patch)
treeb1fa143f95d5bbc48f4008641ce031cd7f5f4532 /src/app/impl_view.rs
parent7e1dff439f1768fc463ddcfcd6ea58a7a1711056 (diff)
use consts for dimensions
Diffstat (limited to 'src/app/impl_view.rs')
-rw-r--r--src/app/impl_view.rs19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs
index 0dfd20b..395cac4 100644
--- a/src/app/impl_view.rs
+++ b/src/app/impl_view.rs
@@ -12,21 +12,17 @@ use notify::DebouncedEvent;
12 12
13use crate::app::{App, MessageKind}; 13use crate::app::{App, MessageKind};
14use crate::habit::{HabitWrapper, ViewMode}; 14use crate::habit::{HabitWrapper, ViewMode};
15use crate::utils; 15use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH};
16use crate::CONFIGURATION;
17 16
18impl View for App { 17impl View for App {
19 fn draw(&self, printer: &Printer) { 18 fn draw(&self, printer: &Printer) {
20 let grid_width = CONFIGURATION.grid_width;
21 let view_width = CONFIGURATION.view_width;
22 let view_height = CONFIGURATION.view_height;
23 let mut offset = Vec2::zero(); 19 let mut offset = Vec2::zero();
24 for (idx, habit) in self.habits.iter().enumerate() { 20 for (idx, habit) in self.habits.iter().enumerate() {
25 if idx >= grid_width && idx % grid_width == 0 { 21 if idx >= GRID_WIDTH && idx % GRID_WIDTH == 0 {
26 offset = offset.map_y(|y| y + view_height).map_x(|_| 0); 22 offset = offset.map_y(|y| y + VIEW_HEIGHT).map_x(|_| 0);
27 } 23 }
28 habit.draw(&printer.offset(offset).focused(self.focus == idx)); 24 habit.draw(&printer.offset(offset).focused(self.focus == idx));
29 offset = offset.map_x(|x| x + view_width + 2); 25 offset = offset.map_x(|x| x + VIEW_WIDTH + 2);
30 } 26 }
31 27
32 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2); 28 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2);
@@ -45,13 +41,10 @@ impl View for App {
45 } 41 }
46 42
47 fn required_size(&mut self, _: Vec2) -> Vec2 { 43 fn required_size(&mut self, _: Vec2) -> Vec2 {
48 let grid_width = CONFIGURATION.grid_width; 44 let width = GRID_WIDTH * (VIEW_WIDTH + 2);
49 let view_width = CONFIGURATION.view_width;
50 let view_height = CONFIGURATION.view_height;
51 let width = grid_width * (view_width + 2);
52 let height = { 45 let height = {
53 if self.habits.len() > 0 { 46 if self.habits.len() > 0 {
54 (view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil()) 47 (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil())
55 as usize 48 as usize
56 } else { 49 } else {
57 0 50 0