diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/impl_self.rs | 18 | ||||
-rw-r--r-- | src/app/impl_view.rs | 19 |
2 files changed, 13 insertions, 24 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 39882be..5cd9616 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs | |||
@@ -13,8 +13,7 @@ use notify::{watcher, RecursiveMode, Watcher}; | |||
13 | 13 | ||
14 | use crate::command::{Command, CommandLineError}; | 14 | use crate::command::{Command, CommandLineError}; |
15 | use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode}; | 15 | use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode}; |
16 | use crate::utils; | 16 | use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; |
17 | use crate::CONFIGURATION; | ||
18 | 17 | ||
19 | use crate::app::{App, MessageKind, StatusLine}; | 18 | use crate::app::{App, MessageKind, StatusLine}; |
20 | 19 | ||
@@ -87,7 +86,6 @@ impl App { | |||
87 | } | 86 | } |
88 | 87 | ||
89 | pub fn set_focus(&mut self, d: Absolute) { | 88 | pub fn set_focus(&mut self, d: Absolute) { |
90 | let grid_width = CONFIGURATION.grid_width; | ||
91 | match d { | 89 | match d { |
92 | Absolute::Right => { | 90 | Absolute::Right => { |
93 | if self.focus != self.habits.len() - 1 { | 91 | if self.focus != self.habits.len() - 1 { |
@@ -100,15 +98,15 @@ impl App { | |||
100 | } | 98 | } |
101 | } | 99 | } |
102 | Absolute::Down => { | 100 | Absolute::Down => { |
103 | if self.focus + grid_width < self.habits.len() - 1 { | 101 | if self.focus + GRID_WIDTH < self.habits.len() - 1 { |
104 | self.focus += grid_width; | 102 | self.focus += GRID_WIDTH; |
105 | } else { | 103 | } else { |
106 | self.focus = self.habits.len() - 1; | 104 | self.focus = self.habits.len() - 1; |
107 | } | 105 | } |
108 | } | 106 | } |
109 | Absolute::Up => { | 107 | Absolute::Up => { |
110 | if self.focus as isize - grid_width as isize >= 0 { | 108 | if self.focus as isize - GRID_WIDTH as isize >= 0 { |
111 | self.focus -= grid_width; | 109 | self.focus -= GRID_WIDTH; |
112 | } else { | 110 | } else { |
113 | self.focus = 0; | 111 | self.focus = 0; |
114 | } | 112 | } |
@@ -146,12 +144,10 @@ impl App { | |||
146 | } | 144 | } |
147 | 145 | ||
148 | pub fn max_size(&self) -> Vec2 { | 146 | pub fn max_size(&self) -> Vec2 { |
149 | let grid_width = CONFIGURATION.grid_width; | 147 | let width = GRID_WIDTH * VIEW_WIDTH; |
150 | let width = grid_width * CONFIGURATION.view_width; | ||
151 | let height = { | 148 | let height = { |
152 | if !self.habits.is_empty() { | 149 | if !self.habits.is_empty() { |
153 | (CONFIGURATION.view_height as f64 | 150 | (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil()) |
154 | * (self.habits.len() as f64 / grid_width as f64).ceil()) | ||
155 | as usize | 151 | as usize |
156 | } else { | 152 | } else { |
157 | 0 | 153 | 0 |
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 |