diff options
author | Akshay <[email protected]> | 2020-07-19 10:26:39 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-07-19 10:26:39 +0100 |
commit | 8a1dd86155823455e71ca0f73673214073a8a269 (patch) | |
tree | 41ecaffa397d4f86bb55d57b266dd6a65e19f2e0 /src/app/impl_view.rs | |
parent | 9c858841c7566e79c0e05a6295e5f9bc86468d16 (diff) |
add startup hint, fix watcher panics
Diffstat (limited to 'src/app/impl_view.rs')
-rw-r--r-- | src/app/impl_view.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/app/impl_view.rs b/src/app/impl_view.rs index 0a6bce6..892b00c 100644 --- a/src/app/impl_view.rs +++ b/src/app/impl_view.rs | |||
@@ -5,7 +5,7 @@ use std::path::PathBuf; | |||
5 | 5 | ||
6 | use cursive::direction::{Absolute, Direction}; | 6 | use cursive::direction::{Absolute, Direction}; |
7 | use cursive::event::{Event, EventResult, Key}; | 7 | use cursive::event::{Event, EventResult, Key}; |
8 | use cursive::theme::{Color, Style}; | 8 | use cursive::theme::Color; |
9 | use cursive::view::View; | 9 | use cursive::view::View; |
10 | use cursive::{Printer, Vec2}; | 10 | use cursive::{Printer, Vec2}; |
11 | use notify::DebouncedEvent; | 11 | use notify::DebouncedEvent; |
@@ -48,23 +48,16 @@ impl View for App { | |||
48 | let grid_width = CONFIGURATION.grid_width; | 48 | let grid_width = CONFIGURATION.grid_width; |
49 | let view_width = CONFIGURATION.view_width; | 49 | let view_width = CONFIGURATION.view_width; |
50 | let view_height = CONFIGURATION.view_height; | 50 | let view_height = CONFIGURATION.view_height; |
51 | let width = { | 51 | let width = grid_width * (view_width + 2); |
52 | if self.habits.len() > 0 { | ||
53 | grid_width * (view_width + 2) | ||
54 | } else { | ||
55 | 0 | ||
56 | } | ||
57 | }; | ||
58 | let height = { | 52 | let height = { |
59 | if self.habits.len() > 0 { | 53 | if self.habits.len() > 0 { |
60 | (view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil()) | 54 | (view_height as f64 * (self.habits.len() as f64 / grid_width as f64).ceil()) |
61 | as usize | 55 | as usize |
62 | + 2 // to acoomodate statusline and message line | ||
63 | } else { | 56 | } else { |
64 | 0 | 57 | 0 |
65 | } | 58 | } |
66 | }; | 59 | }; |
67 | Vec2::new(width, height) | 60 | Vec2::new(width, height + 2) |
68 | } | 61 | } |
69 | 62 | ||
70 | fn take_focus(&mut self, _: Direction) -> bool { | 63 | fn take_focus(&mut self, _: Direction) -> bool { |
@@ -89,6 +82,9 @@ impl View for App { | |||
89 | } | 82 | } |
90 | _ => {} | 83 | _ => {} |
91 | }; | 84 | }; |
85 | if self.habits.is_empty() { | ||
86 | return EventResult::Ignored; | ||
87 | } | ||
92 | match e { | 88 | match e { |
93 | Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => { | 89 | Event::Key(Key::Right) | Event::Key(Key::Tab) | Event::Char('l') => { |
94 | self.set_focus(Absolute::Right); | 90 | self.set_focus(Absolute::Right); |