summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAkshay <nerdy@peppe.rs>2020-08-03 16:05:55 +0530
committerAkshay <nerdy@peppe.rs>2020-08-03 16:05:55 +0530
commitfcaf919fd1e176e4b8dd6d5d21e25db7f68c32a8 (patch)
treeb1fa143f95d5bbc48f4008641ce031cd7f5f4532
parent7e1dff439f1768fc463ddcfcd6ea58a7a1711056 (diff)
use consts for dimensions
-rw-r--r--src/app/impl_self.rs18
-rw-r--r--src/app/impl_view.rs19
-rw-r--r--src/command.rs5
-rw-r--r--src/habit/bit.rs4
-rw-r--r--src/views.rs13
5 files changed, 23 insertions, 36 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};
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
diff --git a/src/command.rs b/src/command.rs
index 0ef5121..8c823a2 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -6,7 +6,8 @@ use cursive::view::Resizable;
use cursive::views::{EditView, LinearLayout, OnEventView, TextView};
use cursive::Cursive;
-use crate::{app::App, CONFIGURATION};
+use crate::app::App;
+use crate::utils::{GRID_WIDTH, VIEW_WIDTH};
static COMMANDS: &'static [&'static str] = &[
"add",
@@ -68,7 +69,7 @@ pub fn open_command_window(s: &mut Cursive) {
}
},
)
- .fixed_width(CONFIGURATION.view_width * CONFIGURATION.grid_width);
+ .fixed_width(VIEW_WIDTH * GRID_WIDTH);
s.call_on_name("Frame", |view: &mut LinearLayout| {
let mut commandline = LinearLayout::horizontal()
.child(TextView::new(":"))
diff --git a/src/habit/bit.rs b/src/habit/bit.rs
index 8fa14c2..2bbb0ac 100644
--- a/src/habit/bit.rs
+++ b/src/habit/bit.rs
@@ -18,9 +18,9 @@ impl fmt::Display for CustomBool {
f,
"{:^3}",
if self.0 {
- CONFIGURATION.true_chr
+ CONFIGURATION.look.true_chr
} else {
- CONFIGURATION.false_chr
+ CONFIGURATION.look.false_chr
}
)
}
diff --git a/src/views.rs b/src/views.rs
index 7adf8c6..efd1391 100644
--- a/src/views.rs
+++ b/src/views.rs
@@ -8,6 +8,7 @@ use chrono::prelude::*;
use chrono::{Duration, Local, NaiveDate};
use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode};
+use crate::utils::VIEW_WIDTH;
use crate::CONFIGURATION;
@@ -38,7 +39,7 @@ where
let goal_reached_style = Style::from(CONFIGURATION.reached_color());
let todo_style = Style::from(CONFIGURATION.todo_color());
- let future_style = Style::from(CONFIGURATION.future_color());
+ let future_style = Style::from(CONFIGURATION.inactive_color());
let strikethrough = Style::from(Effect::Strikethrough);
@@ -61,11 +62,7 @@ where
|p| {
p.print(
(0, 0),
- &format!(
- " {:.width$} ",
- self.name(),
- width = CONFIGURATION.view_width - 6
- ),
+ &format!(" {:.width$} ", self.name(), width = VIEW_WIDTH - 6),
);
},
);
@@ -80,7 +77,7 @@ where
let is_this_week = week.contains(&Local::now().naive_local().date());
let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>();
let completions = weekly_goal - remaining;
- let full = CONFIGURATION.view_width - 8;
+ let full = VIEW_WIDTH - 8;
let bars_to_fill = if weekly_goal > 0 {
(completions * full as u32) / weekly_goal
} else {
@@ -126,7 +123,7 @@ where
});
} else {
printer.with_style(future_style, |p| {
- p.print(coords, &format!("{:^3}", CONFIGURATION.future_chr));
+ p.print(coords, &format!("{:^3}", CONFIGURATION.look.future_chr));
});
}
i += 1;