aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-08-03 11:35:55 +0100
committerAkshay <[email protected]>2020-08-03 11:35:55 +0100
commitfcaf919fd1e176e4b8dd6d5d21e25db7f68c32a8 (patch)
treeb1fa143f95d5bbc48f4008641ce031cd7f5f4532 /src
parent7e1dff439f1768fc463ddcfcd6ea58a7a1711056 (diff)
use consts for dimensions
Diffstat (limited to 'src')
-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};
13 13
14use crate::command::{Command, CommandLineError}; 14use crate::command::{Command, CommandLineError};
15use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode}; 15use crate::habit::{Bit, Count, HabitWrapper, TrackEvent, ViewMode};
16use crate::utils; 16use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH};
17use crate::CONFIGURATION;
18 17
19use crate::app::{App, MessageKind, StatusLine}; 18use crate::app::{App, MessageKind, StatusLine};
20 19
@@ -87,7 +86,6 @@ impl App {
87 } 86 }
88 87
89 pub fn set_focus(&mut self, d: Absolute) { 88 pub fn set_focus(&mut self, d: Absolute) {
90 let grid_width = CONFIGURATION.grid_width;
91 match d { 89 match d {
92 Absolute::Right => { 90 Absolute::Right => {
93 if self.focus != self.habits.len() - 1 { 91 if self.focus != self.habits.len() - 1 {
@@ -100,15 +98,15 @@ impl App {
100 } 98 }
101 } 99 }
102 Absolute::Down => { 100 Absolute::Down => {
103 if self.focus + grid_width < self.habits.len() - 1 { 101 if self.focus + GRID_WIDTH < self.habits.len() - 1 {
104 self.focus += grid_width; 102 self.focus += GRID_WIDTH;
105 } else { 103 } else {
106 self.focus = self.habits.len() - 1; 104 self.focus = self.habits.len() - 1;
107 } 105 }
108 } 106 }
109 Absolute::Up => { 107 Absolute::Up => {
110 if self.focus as isize - grid_width as isize >= 0 { 108 if self.focus as isize - GRID_WIDTH as isize >= 0 {
111 self.focus -= grid_width; 109 self.focus -= GRID_WIDTH;
112 } else { 110 } else {
113 self.focus = 0; 111 self.focus = 0;
114 } 112 }
@@ -146,12 +144,10 @@ impl App {
146 } 144 }
147 145
148 pub fn max_size(&self) -> Vec2 { 146 pub fn max_size(&self) -> Vec2 {
149 let grid_width = CONFIGURATION.grid_width; 147 let width = GRID_WIDTH * VIEW_WIDTH;
150 let width = grid_width * CONFIGURATION.view_width;
151 let height = { 148 let height = {
152 if !self.habits.is_empty() { 149 if !self.habits.is_empty() {
153 (CONFIGURATION.view_height as f64 150 (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil())
154 * (self.habits.len() as f64 / grid_width as f64).ceil())
155 as usize 151 as usize
156 } else { 152 } else {
157 0 153 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;
12 12
13use crate::app::{App, MessageKind}; 13use crate::app::{App, MessageKind};
14use crate::habit::{HabitWrapper, ViewMode}; 14use crate::habit::{HabitWrapper, ViewMode};
15use crate::utils; 15use crate::utils::{self, GRID_WIDTH, VIEW_HEIGHT, VIEW_WIDTH};
16use crate::CONFIGURATION;
17 16
18impl View for App { 17impl View for App {
19 fn draw(&self, printer: &Printer) { 18 fn draw(&self, printer: &Printer) {
20 let grid_width = CONFIGURATION.grid_width;
21 let view_width = CONFIGURATION.view_width;
22 let view_height = CONFIGURATION.view_height;
23 let mut offset = Vec2::zero(); 19 let mut offset = Vec2::zero();
24 for (idx, habit) in self.habits.iter().enumerate() { 20 for (idx, habit) in self.habits.iter().enumerate() {
25 if idx >= grid_width && idx % grid_width == 0 { 21 if idx >= GRID_WIDTH && idx % GRID_WIDTH == 0 {
26 offset = offset.map_y(|y| y + view_height).map_x(|_| 0); 22 offset = offset.map_y(|y| y + VIEW_HEIGHT).map_x(|_| 0);
27 } 23 }
28 habit.draw(&printer.offset(offset).focused(self.focus == idx)); 24 habit.draw(&printer.offset(offset).focused(self.focus == idx));
29 offset = offset.map_x(|x| x + view_width + 2); 25 offset = offset.map_x(|x| x + VIEW_WIDTH + 2);
30 } 26 }
31 27
32 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2); 28 offset = offset.map_x(|_| 0).map_y(|_| self.max_size().y - 2);
@@ -45,13 +41,10 @@ impl View for App {
45 } 41 }
46 42
47 fn required_size(&mut self, _: Vec2) -> Vec2 { 43 fn required_size(&mut self, _: Vec2) -> Vec2 {
48 let grid_width = CONFIGURATION.grid_width; 44 let width = GRID_WIDTH * (VIEW_WIDTH + 2);
49 let view_width = CONFIGURATION.view_width;
50 let view_height = CONFIGURATION.view_height;
51 let width = grid_width * (view_width + 2);
52 let height = { 45 let height = {
53 if self.habits.len() > 0 { 46 if self.habits.len() > 0 {
54 (view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil()) 47 (VIEW_HEIGHT as f64 * (self.habits.len() as f64 / GRID_WIDTH as f64).ceil())
55 as usize 48 as usize
56 } else { 49 } else {
57 0 50 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;
6use cursive::views::{EditView, LinearLayout, OnEventView, TextView}; 6use cursive::views::{EditView, LinearLayout, OnEventView, TextView};
7use cursive::Cursive; 7use cursive::Cursive;
8 8
9use crate::{app::App, CONFIGURATION}; 9use crate::app::App;
10use crate::utils::{GRID_WIDTH, VIEW_WIDTH};
10 11
11static COMMANDS: &'static [&'static str] = &[ 12static COMMANDS: &'static [&'static str] = &[
12 "add", 13 "add",
@@ -68,7 +69,7 @@ pub fn open_command_window(s: &mut Cursive) {
68 } 69 }
69 }, 70 },
70 ) 71 )
71 .fixed_width(CONFIGURATION.view_width * CONFIGURATION.grid_width); 72 .fixed_width(VIEW_WIDTH * GRID_WIDTH);
72 s.call_on_name("Frame", |view: &mut LinearLayout| { 73 s.call_on_name("Frame", |view: &mut LinearLayout| {
73 let mut commandline = LinearLayout::horizontal() 74 let mut commandline = LinearLayout::horizontal()
74 .child(TextView::new(":")) 75 .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 {
18 f, 18 f,
19 "{:^3}", 19 "{:^3}",
20 if self.0 { 20 if self.0 {
21 CONFIGURATION.true_chr 21 CONFIGURATION.look.true_chr
22 } else { 22 } else {
23 CONFIGURATION.false_chr 23 CONFIGURATION.look.false_chr
24 } 24 }
25 ) 25 )
26 } 26 }
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::*;
8use chrono::{Duration, Local, NaiveDate}; 8use chrono::{Duration, Local, NaiveDate};
9 9
10use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; 10use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode};
11use crate::utils::VIEW_WIDTH;
11 12
12use crate::CONFIGURATION; 13use crate::CONFIGURATION;
13 14
@@ -38,7 +39,7 @@ where
38 39
39 let goal_reached_style = Style::from(CONFIGURATION.reached_color()); 40 let goal_reached_style = Style::from(CONFIGURATION.reached_color());
40 let todo_style = Style::from(CONFIGURATION.todo_color()); 41 let todo_style = Style::from(CONFIGURATION.todo_color());
41 let future_style = Style::from(CONFIGURATION.future_color()); 42 let future_style = Style::from(CONFIGURATION.inactive_color());
42 43
43 let strikethrough = Style::from(Effect::Strikethrough); 44 let strikethrough = Style::from(Effect::Strikethrough);
44 45
@@ -61,11 +62,7 @@ where
61 |p| { 62 |p| {
62 p.print( 63 p.print(
63 (0, 0), 64 (0, 0),
64 &format!( 65 &format!(" {:.width$} ", self.name(), width = VIEW_WIDTH - 6),
65 " {:.width$} ",
66 self.name(),
67 width = CONFIGURATION.view_width - 6
68 ),
69 ); 66 );
70 }, 67 },
71 ); 68 );
@@ -80,7 +77,7 @@ where
80 let is_this_week = week.contains(&Local::now().naive_local().date()); 77 let is_this_week = week.contains(&Local::now().naive_local().date());
81 let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>(); 78 let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>();
82 let completions = weekly_goal - remaining; 79 let completions = weekly_goal - remaining;
83 let full = CONFIGURATION.view_width - 8; 80 let full = VIEW_WIDTH - 8;
84 let bars_to_fill = if weekly_goal > 0 { 81 let bars_to_fill = if weekly_goal > 0 {
85 (completions * full as u32) / weekly_goal 82 (completions * full as u32) / weekly_goal
86 } else { 83 } else {
@@ -126,7 +123,7 @@ where
126 }); 123 });
127 } else { 124 } else {
128 printer.with_style(future_style, |p| { 125 printer.with_style(future_style, |p| {
129 p.print(coords, &format!("{:^3}", CONFIGURATION.future_chr)); 126 p.print(coords, &format!("{:^3}", CONFIGURATION.look.future_chr));
130 }); 127 });
131 } 128 }
132 i += 1; 129 i += 1;