From fcaf919fd1e176e4b8dd6d5d21e25db7f68c32a8 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 3 Aug 2020 16:05:55 +0530 Subject: use consts for dimensions --- src/app/impl_self.rs | 18 +++++++----------- src/app/impl_view.rs | 19 ++++++------------- 2 files changed, 13 insertions(+), 24 deletions(-) (limited to 'src/app') 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}; use crate::command::{Command, CommandLineError}; use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode}; -use crate::utils; -use crate::CONFIGURATION; +use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; use crate::app::{App, MessageKind, StatusLine}; @@ -87,7 +86,6 @@ impl App { } pub fn set_focus(&mut self, d: Absolute) { - let grid_width = CONFIGURATION.grid_width; match d { Absolute::Right => { if self.focus != self.habits.len() - 1 { @@ -100,15 +98,15 @@ impl App { } } Absolute::Down => { - if self.focus + grid_width < self.habits.len() - 1 { - self.focus += grid_width; + if self.focus + GRID_WIDTH < self.habits.len() - 1 { + self.focus += GRID_WIDTH; } else { self.focus = self.habits.len() - 1; } } Absolute::Up => { - if self.focus as isize - grid_width as isize >= 0 { - self.focus -= grid_width; + if self.focus as isize - GRID_WIDTH as isize >= 0 { + self.focus -= GRID_WIDTH; } else { self.focus = 0; } @@ -146,12 +144,10 @@ impl App { } pub fn max_size(&self) -> Vec2 { - let grid_width = CONFIGURATION.grid_width; - let width = grid_width * CONFIGURATION.view_width; + let width = GRID_WIDTH * VIEW_WIDTH; let height = { if !self.habits.is_empty() { - (CONFIGURATION.view_height as f64 - * (self.habits.len() as f64 / grid_width as f64).ceil()) + (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil()) as usize } else { 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; use crate::app::{App, MessageKind}; use crate::habit::{HabitWrapper, ViewMode}; -use crate::utils; -use crate::CONFIGURATION; +use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; impl View for App { fn draw(&self, printer: &Printer) { - let grid_width = CONFIGURATION.grid_width; - let view_width = CONFIGURATION.view_width; - let view_height = CONFIGURATION.view_height; let mut offset = Vec2::zero(); for (idx, habit) in self.habits.iter().enumerate() { - if idx >= grid_width && idx % grid_width == 0 { - offset = offset.map_y(|y| y + view_height).map_x(|_| 0); + if idx >= GRID_WIDTH && idx % GRID_WIDTH == 0 { + offset = offset.map_y(|y| y + VIEW_HEIGHT).map_x(|_| 0); } habit.draw(&printer.offset(offset).focused(self.focus == idx)); - offset = offset.map_x(|x| x + view_width + 2); + offset = offset.map_x(|x| x + VIEW_WIDTH + 2); } offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2); @@ -45,13 +41,10 @@ impl View for App { } fn required_size(&mut self, _: Vec2) -> Vec2 { - let grid_width = CONFIGURATION.grid_width; - let view_width = CONFIGURATION.view_width; - let view_height = CONFIGURATION.view_height; - let width = grid_width * (view_width + 2); + let width = GRID_WIDTH * (VIEW_WIDTH + 2); let height = { if self.habits.len() > 0 { - (view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil()) + (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil()) as usize } else { 0 -- cgit v1.2.3