aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/impl_self.rs15
-rw-r--r--src/app/impl_view.rs9
2 files changed, 13 insertions, 11 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index fad965a..b53cdcf 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -11,9 +11,10 @@ use cursive::direction::Absolute;
11use cursive::Vec2; 11use cursive::Vec2;
12use notify::{watcher, RecursiveMode, Watcher}; 12use notify::{watcher, RecursiveMode, Watcher};
13 13
14use crate::CONFIGURATION;
14use crate::command::{Command, CommandLineError, GoalKind}; 15use crate::command::{Command, CommandLineError, GoalKind};
15use crate::habit::{Bit, Count, Float, HabitWrapper, TrackEvent, ViewMode}; 16use crate::habit::{Bit, Count, Float, HabitWrapper, TrackEvent, ViewMode};
16use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; 17use crate::utils::{self, VIEW_HEIGHT, VIEW_WIDTH};
17 18
18use crate::app::{App, Cursor, Message, MessageKind, StatusLine}; 19use crate::app::{App, Cursor, Message, MessageKind, StatusLine};
19 20
@@ -105,15 +106,15 @@ impl App {
105 } 106 }
106 } 107 }
107 Absolute::Down => { 108 Absolute::Down => {
108 if self.focus + GRID_WIDTH < self.habits.len() - 1 { 109 if self.focus + CONFIGURATION.grid_size() < self.habits.len() - 1 {
109 self.focus += GRID_WIDTH; 110 self.focus += CONFIGURATION.grid_size();
110 } else { 111 } else {
111 self.focus = self.habits.len() - 1; 112 self.focus = self.habits.len() - 1;
112 } 113 }
113 } 114 }
114 Absolute::Up => { 115 Absolute::Up => {
115 if self.focus as isize - GRID_WIDTH as isize >= 0 { 116 if self.focus as isize - CONFIGURATION.grid_size() as isize >= 0 {
116 self.focus -= GRID_WIDTH; 117 self.focus -= CONFIGURATION.grid_size();
117 } else { 118 } else {
118 self.focus = 0; 119 self.focus = 0;
119 } 120 }
@@ -152,10 +153,10 @@ impl App {
152 } 153 }
153 154
154 pub fn max_size(&self) -> Vec2 { 155 pub fn max_size(&self) -> Vec2 {
155 let width = GRID_WIDTH * VIEW_WIDTH; 156 let width = CONFIGURATION.grid_size() * VIEW_WIDTH;
156 let height = { 157 let height = {
157 if !self.habits.is_empty() { 158 if !self.habits.is_empty() {
158 (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil()) 159 (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / CONFIGURATION.grid_size() as f64).ceil())
159 as usize 160 as usize
160 } else { 161 } else {
161 0 162 0
diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs
index c369d8f..e4eb67a 100644
--- a/src/app/impl_view.rs
+++ b/src/app/impl_view.rs
@@ -10,15 +10,16 @@ use cursive::view::View;
10use cursive::{Printer, Vec2}; 10use cursive::{Printer, Vec2};
11use notify::DebouncedEvent; 11use notify::DebouncedEvent;
12 12
13use crate::CONFIGURATION;
13use crate::app::{App, MessageKind}; 14use crate::app::{App, MessageKind};
14use crate::habit::{HabitWrapper, ViewMode}; 15use crate::habit::{HabitWrapper, ViewMode};
15use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; 16use crate::utils::{self, VIEW_HEIGHT, VIEW_WIDTH};
16 17
17impl View for App { 18impl View for App {
18 fn draw(&self, printer: &Printer) { 19 fn draw(&self, printer: &Printer) {
19 let mut offset = Vec2::zero(); 20 let mut offset = Vec2::zero();
20 for (idx, habit) in self.habits.iter().enumerate() { 21 for (idx, habit) in self.habits.iter().enumerate() {
21 if idx >= GRID_WIDTH && idx % GRID_WIDTH == 0 { 22 if idx >= CONFIGURATION.grid_size() && idx % CONFIGURATION.grid_size() == 0 {
22 offset = offset.map_y(|y| y + VIEW_HEIGHT).map_x(|_| 0); 23 offset = offset.map_y(|y| y + VIEW_HEIGHT).map_x(|_| 0);
23 } 24 }
24 habit.draw(&printer.offset(offset).focused(self.focus == idx)); 25 habit.draw(&printer.offset(offset).focused(self.focus == idx));
@@ -41,10 +42,10 @@ impl View for App {
41 } 42 }
42 43
43 fn required_size(&mut self, _: Vec2) -> Vec2 { 44 fn required_size(&mut self, _: Vec2) -> Vec2 {
44 let width = GRID_WIDTH * (VIEW_WIDTH + 2); 45 let width = CONFIGURATION.grid_size() * (VIEW_WIDTH + 2);
45 let height = { 46 let height = {
46 if self.habits.len() > 0 { 47 if self.habits.len() > 0 {
47 (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil()) 48 (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / CONFIGURATION.grid_size() as f64).ceil())
48 as usize 49 as usize
49 } else { 50 } else {
50 0 51 0