diff options
author | Akshay <[email protected]> | 2020-02-15 12:51:17 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-02-15 12:51:17 +0000 |
commit | 242aa78d1f593a42f82cc32b4cc84eb003c3bbe7 (patch) | |
tree | 7b6875627c73d3cbf29d0dcfc6b8ff5514205d18 /src | |
parent | aedff3ffa7259b7daefa4d1ec96e75015edd4e96 (diff) |
redo main samples
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs index 128df03..2b70033 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -2,51 +2,50 @@ | |||
2 | 2 | ||
3 | use chrono::NaiveDate; | 3 | use chrono::NaiveDate; |
4 | 4 | ||
5 | use cursive::views::{Dialog, LinearLayout}; | 5 | use cursive::views::{Dialog, EditView, LinearLayout, ListView, SelectView}; |
6 | use cursive::Cursive; | 6 | use cursive::Cursive; |
7 | 7 | ||
8 | mod habit; | 8 | mod habit; |
9 | use crate::habit::Habit; | 9 | use crate::habit::{Habit, HabitTrait, HabitType}; |
10 | 10 | ||
11 | mod views; | 11 | mod views; |
12 | use crate::views::bitview::BitView; | 12 | use crate::views::habitview::HabitView; |
13 | use crate::views::countview::CountView; | ||
14 | 13 | ||
15 | mod theme; | 14 | mod theme; |
16 | 15 | ||
17 | enum ViewMode { | 16 | struct App { |
18 | Daily, | 17 | habits: Vec<Habit>, |
19 | Monthly, | 18 | status: String, |
20 | } | 19 | } |
21 | 20 | ||
22 | fn main() { | 21 | fn main() { |
23 | let mut work_out: Habit<bool> = Habit::new("gymming", true); | ||
24 | work_out.insert_entry(NaiveDate::from_ymd(2020, 2, 4), true); | ||
25 | work_out.insert_entry(NaiveDate::from_ymd(2020, 2, 2), true); | ||
26 | work_out.insert_entry(NaiveDate::from_ymd(2020, 2, 3), true); | ||
27 | work_out.insert_entry(NaiveDate::from_ymd(2020, 2, 1), true); | ||
28 | work_out.insert_entry(NaiveDate::from_ymd(2020, 2, 5), false); | ||
29 | work_out.insert_entry(NaiveDate::from_ymd(2020, 2, 8), false); | ||
30 | work_out.insert_entry(NaiveDate::from_ymd(2020, 2, 11), false); | ||
31 | |||
32 | let mut again: Habit<u32> = Habit::new("reading", 5); | ||
33 | again.insert_entry(NaiveDate::from_ymd(2020, 2, 4), 4); | ||
34 | again.insert_entry(NaiveDate::from_ymd(2020, 2, 2), 2); | ||
35 | again.insert_entry(NaiveDate::from_ymd(2020, 2, 7), 5); | ||
36 | |||
37 | let mut s = Cursive::default(); | 22 | let mut s = Cursive::default(); |
38 | 23 | ||
39 | let gym_view = BitView::new(work_out); | 24 | let mut gymming = Habit::new("gym", HabitType::Count(5)); |
40 | let gym_title = gym_view.get_title(); | 25 | gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Count(7)); |
26 | gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Count(8)); | ||
27 | gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Count(9)); | ||
28 | gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Count(10)); | ||
29 | gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Count(11)); | ||
30 | |||
31 | let mut reading = Habit::new("read", HabitType::Count(5)); | ||
32 | reading.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Bit(true)); | ||
33 | reading.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Bit(false)); | ||
34 | reading.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Bit(true)); | ||
35 | reading.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Bit(false)); | ||
36 | reading.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Bit(true)); | ||
37 | |||
38 | let gym_title = gymming.get_name(); | ||
39 | let gym_view = HabitView::new(gymming); | ||
41 | 40 | ||
42 | let reading_view = CountView::new(again); | 41 | let read_title = reading.get_name(); |
43 | let reading_title = reading_view.get_title(); | 42 | let read_view = HabitView::new(reading); |
44 | 43 | ||
45 | s.add_global_callback('q', |a| a.quit()); | 44 | s.add_global_callback('q', |a| a.quit()); |
46 | s.add_layer( | 45 | s.add_layer( |
47 | LinearLayout::horizontal() | 46 | LinearLayout::horizontal() |
48 | .child(Dialog::around(gym_view).title(gym_title)) | 47 | .child(Dialog::around(gym_view).title(gym_title)) |
49 | .child(Dialog::around(reading_view).title(reading_title)), | 48 | .child(Dialog::around(read_view).title(read_title)), |
50 | ); | 49 | ); |
51 | 50 | ||
52 | s.set_theme(theme::theme_gen()); | 51 | s.set_theme(theme::theme_gen()); |