From a9142b54a72bac4864ae1147a96fcf6896cee3d6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 13 May 2021 22:31:26 +0530 Subject: allow custom grid_size from toml file --- src/app/impl_self.rs | 15 ++++++++------- src/app/impl_view.rs | 9 +++++---- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/app') 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; use cursive::Vec2; use notify::{watcher, RecursiveMode, Watcher}; +use crate::CONFIGURATION; use crate::command::{Command, CommandLineError, GoalKind}; use crate::habit::{Bit, Count, Float, HabitWrapper, TrackEvent, ViewMode}; -use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; +use crate::utils::{self, VIEW_HEIGHT, VIEW_WIDTH}; use crate::app::{App, Cursor, Message, MessageKind, StatusLine}; @@ -105,15 +106,15 @@ impl App { } } Absolute::Down => { - if self.focus + GRID_WIDTH < self.habits.len() - 1 { - self.focus += GRID_WIDTH; + if self.focus + CONFIGURATION.grid_size() < self.habits.len() - 1 { + self.focus += CONFIGURATION.grid_size(); } 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 - CONFIGURATION.grid_size() as isize >= 0 { + self.focus -= CONFIGURATION.grid_size(); } else { self.focus = 0; } @@ -152,10 +153,10 @@ impl App { } pub fn max_size(&self) -> Vec2 { - let width = GRID_WIDTH * VIEW_WIDTH; + let width = CONFIGURATION.grid_size() * VIEW_WIDTH; let height = { if !self.habits.is_empty() { - (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil()) + (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / CONFIGURATION.grid_size() as f64).ceil()) as usize } else { 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; use cursive::{Printer, Vec2}; use notify::DebouncedEvent; +use crate::CONFIGURATION; use crate::app::{App, MessageKind}; use crate::habit::{HabitWrapper, ViewMode}; -use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH}; +use crate::utils::{self, VIEW_HEIGHT, VIEW_WIDTH}; impl View for App { fn draw(&self, printer: &Printer) { let mut offset = Vec2::zero(); for (idx, habit) in self.habits.iter().enumerate() { - if idx >= GRID_WIDTH && idx % GRID_WIDTH == 0 { + if idx >= CONFIGURATION.grid_size() && idx % CONFIGURATION.grid_size() == 0 { offset = offset.map_y(|y| y + VIEW_HEIGHT).map_x(|_| 0); } habit.draw(&printer.offset(offset).focused(self.focus == idx)); @@ -41,10 +42,10 @@ impl View for App { } fn required_size(&mut self, _: Vec2) -> Vec2 { - let width = GRID_WIDTH * (VIEW_WIDTH + 2); + let width = CONFIGURATION.grid_size() * (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 / CONFIGURATION.grid_size() as f64).ceil()) as usize } else { 0 -- cgit v1.2.3