diff options
Diffstat (limited to 'src/app/impl_view.rs')
-rw-r--r-- | src/app/impl_view.rs | 19 |
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 | ||
13 | use crate::app::{App, MessageKind}; | 13 | use crate::app::{App, MessageKind}; |
14 | use crate::habit::{HabitWrapper, ViewMode}; | 14 | use crate::habit::{HabitWrapper, ViewMode}; |
15 | use crate::utils; | 15 | use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; |
16 | use crate::CONFIGURATION; | ||
17 | 16 | ||
18 | impl View for App { | 17 | impl 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 |