diff options
author | Akshay <[email protected]> | 2021-05-13 18:01:26 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2021-05-13 18:01:26 +0100 |
commit | a9142b54a72bac4864ae1147a96fcf6896cee3d6 (patch) | |
tree | bb7e3cf5dafecc24c09d592b58c904b8aa7e26dc /src/app | |
parent | bf30b22665ef596f8627559bd8378d7ab6fbbd47 (diff) |
allow custom grid_size from toml filegrid-width
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/impl_self.rs | 15 | ||||
-rw-r--r-- | src/app/impl_view.rs | 9 |
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; | |||
11 | use cursive::Vec2; | 11 | use cursive::Vec2; |
12 | use notify::{watcher, RecursiveMode, Watcher}; | 12 | use notify::{watcher, RecursiveMode, Watcher}; |
13 | 13 | ||
14 | use crate::CONFIGURATION; | ||
14 | use crate::command::{Command, CommandLineError, GoalKind}; | 15 | use crate::command::{Command, CommandLineError, GoalKind}; |
15 | use crate::habit::{Bit, Count, Float, HabitWrapper, TrackEvent, ViewMode}; | 16 | use crate::habit::{Bit, Count, Float, HabitWrapper, TrackEvent, ViewMode}; |
16 | use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; | 17 | use crate::utils::{self, VIEW_HEIGHT, VIEW_WIDTH}; |
17 | 18 | ||
18 | use crate::app::{App, Cursor, Message, MessageKind, StatusLine}; | 19 | use 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; | |||
10 | use cursive::{Printer, Vec2}; | 10 | use cursive::{Printer, Vec2}; |
11 | use notify::DebouncedEvent; | 11 | use notify::DebouncedEvent; |
12 | 12 | ||
13 | use crate::CONFIGURATION; | ||
13 | use crate::app::{App, MessageKind}; | 14 | use crate::app::{App, MessageKind}; |
14 | use crate::habit::{HabitWrapper, ViewMode}; | 15 | use crate::habit::{HabitWrapper, ViewMode}; |
15 | use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; | 16 | use crate::utils::{self, VIEW_HEIGHT, VIEW_WIDTH}; |
16 | 17 | ||
17 | impl View for App { | 18 | impl 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 |