From cd03d732b1f0df6c020a94135db2db4b690a4937 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 25 Jan 2021 14:54:51 +0530 Subject: handle cursor events and entry --- src/views.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/views.rs') diff --git a/src/views.rs b/src/views.rs index efd1391..4f78ca2 100644 --- a/src/views.rs +++ b/src/views.rs @@ -5,9 +5,10 @@ use cursive::view::View; use cursive::{Printer, Vec2}; use chrono::prelude::*; -use chrono::{Duration, Local, NaiveDate}; +use chrono::{Local, NaiveDate}; use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; +use crate::theme::cursor_gen; use crate::utils::VIEW_WIDTH; use crate::CONFIGURATION; @@ -27,13 +28,15 @@ where T::HabitType: std::fmt::Display, { fn draw(&self, printer: &Printer) { - let now = if self.view_month_offset() == 0 { - Local::today() - } else { - Local::today() - .checked_sub_signed(Duration::weeks(4 * self.view_month_offset() as i64)) - .unwrap() - }; + // let now = if self.view_month_offset() == 0 { + // Local::today() + // } else { + // Local::today() + // .checked_sub_signed(Duration::weeks(4 * self.view_month_offset() as i64)) + // .unwrap() + // }; + let now = self.cursor().0; + let is_today = now == Local::now().naive_local().date(); let year = now.year(); let month = now.month(); @@ -41,10 +44,10 @@ where let todo_style = Style::from(CONFIGURATION.todo_color()); let future_style = Style::from(CONFIGURATION.inactive_color()); + let cursor_style = cursor_gen(); let strikethrough = Style::from(Effect::Strikethrough); - let goal_status = - self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_local().date()); + let goal_status = is_today && self.reached_goal(Local::now().naive_local().date()); printer.with_style( Style::merge(&[ @@ -110,11 +113,9 @@ where let draw_day = |printer: &Printer| { let mut i = 0; while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { - let day_style; + let mut day_style = cursor_style.combine(todo_style); if self.reached_goal(d) { - day_style = goal_reached_style; - } else { - day_style = todo_style; + day_style = day_style.combine(goal_reached_style); } let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); if let Some(c) = self.get_by_date(d) { @@ -146,7 +147,7 @@ where } fn on_event(&mut self, e: Event) -> EventResult { - let now = Local::now().naive_local().date(); + let now = self.cursor().0; if self.is_auto() { return EventResult::Ignored; } -- cgit v1.2.3 From c26de6fbfd55cca906b9c184621a9f550cdcc0f1 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 25 Jan 2021 15:21:36 +0530 Subject: attempt to style cursor --- src/views.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/views.rs') diff --git a/src/views.rs b/src/views.rs index 4f78ca2..a0beb2c 100644 --- a/src/views.rs +++ b/src/views.rs @@ -44,7 +44,6 @@ where let todo_style = Style::from(CONFIGURATION.todo_color()); let future_style = Style::from(CONFIGURATION.inactive_color()); - let cursor_style = cursor_gen(); let strikethrough = Style::from(Effect::Strikethrough); let goal_status = is_today && self.reached_goal(Local::now().naive_local().date()); @@ -113,9 +112,12 @@ where let draw_day = |printer: &Printer| { let mut i = 0; while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { - let mut day_style = cursor_style.combine(todo_style); + let mut day_style = todo_style; if self.reached_goal(d) { - day_style = day_style.combine(goal_reached_style); + day_style = goal_reached_style; + } + if d == now && printer.focused { + day_style = day_style.combine(cursor_gen(day_style)); } let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); if let Some(c) = self.get_by_date(d) { -- cgit v1.2.3 From 9cdef4e296c77fb94d99553de05ba1aaa6c81ed8 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 25 Jan 2021 15:45:03 +0530 Subject: fix cursor coloring --- src/views.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/views.rs') diff --git a/src/views.rs b/src/views.rs index a0beb2c..a306602 100644 --- a/src/views.rs +++ b/src/views.rs @@ -1,6 +1,6 @@ use cursive::direction::Direction; use cursive::event::{Event, EventResult, Key}; -use cursive::theme::{Effect, Style}; +use cursive::theme::{ColorStyle, ColorType, Effect, Style}; use cursive::view::View; use cursive::{Printer, Vec2}; @@ -8,7 +8,7 @@ use chrono::prelude::*; use chrono::{Local, NaiveDate}; use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; -use crate::theme::cursor_gen; +use crate::theme::cursor_bg; use crate::utils::VIEW_WIDTH; use crate::CONFIGURATION; @@ -112,12 +112,20 @@ where let draw_day = |printer: &Printer| { let mut i = 0; while let Some(d) = NaiveDate::from_ymd_opt(year, month, i + 1) { - let mut day_style = todo_style; + let mut day_style = Style::none(); + let mut fs = future_style; + let grs = ColorStyle::front(CONFIGURATION.reached_color()); + let ts = ColorStyle::front(CONFIGURATION.todo_color()); + let cs = ColorStyle::back(cursor_bg()); + if self.reached_goal(d) { - day_style = goal_reached_style; + day_style = day_style.combine(Style::from(grs)); + } else { + day_style = day_style.combine(Style::from(ts)); } if d == now && printer.focused { - day_style = day_style.combine(cursor_gen(day_style)); + day_style = day_style.combine(cs); + fs = fs.combine(cs); } let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); if let Some(c) = self.get_by_date(d) { @@ -125,7 +133,7 @@ where p.print(coords, &format!("{:^3}", c)); }); } else { - printer.with_style(future_style, |p| { + printer.with_style(fs, |p| { p.print(coords, &format!("{:^3}", CONFIGURATION.look.future_chr)); }); } -- cgit v1.2.3 From 53f7a679a0cf7a510de13d67cf370988f71c0d08 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 6 Feb 2021 19:00:40 +0530 Subject: deprecate view_month_offset in favor of cursor --- src/views.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/views.rs') diff --git a/src/views.rs b/src/views.rs index a306602..b90ce2b 100644 --- a/src/views.rs +++ b/src/views.rs @@ -1,6 +1,6 @@ use cursive::direction::Direction; use cursive::event::{Event, EventResult, Key}; -use cursive::theme::{ColorStyle, ColorType, Effect, Style}; +use cursive::theme::{ColorStyle, Effect, Style}; use cursive::view::View; use cursive::{Printer, Vec2}; @@ -35,13 +35,12 @@ where // .checked_sub_signed(Duration::weeks(4 * self.view_month_offset() as i64)) // .unwrap() // }; - let now = self.cursor().0; + let now = self.inner_data_ref().cursor().0; let is_today = now == Local::now().naive_local().date(); let year = now.year(); let month = now.month(); let goal_reached_style = Style::from(CONFIGURATION.reached_color()); - let todo_style = Style::from(CONFIGURATION.todo_color()); let future_style = Style::from(CONFIGURATION.inactive_color()); let strikethrough = Style::from(Effect::Strikethrough); @@ -141,7 +140,7 @@ where } }; - match self.view_mode() { + match self.inner_data_ref().view_mode() { ViewMode::Day => draw_day(printer), ViewMode::Week => draw_week(printer), _ => draw_day(printer), @@ -157,7 +156,7 @@ where } fn on_event(&mut self, e: Event) -> EventResult { - let now = self.cursor().0; + let now = self.inner_data_mut_ref().cursor().0; if self.is_auto() { return EventResult::Ignored; } -- cgit v1.2.3