From 0b18c65466a59b1c9f8d1bfbe596fc2750571dfb Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 12 Jul 2020 09:30:29 +0530 Subject: fix trait bounds bug, prep for view modes --- src/habit.rs | 10 +++++----- src/views.rs | 47 ++++++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/habit.rs b/src/habit.rs index 92e0b9f..5469aab 100644 --- a/src/habit.rs +++ b/src/habit.rs @@ -15,7 +15,7 @@ pub enum TrackEvent { Decrement, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] pub enum ViewMode { Day, Month, @@ -115,17 +115,17 @@ macro_rules! auto_habit_impl { fn take_focus(&mut self, d: Direction) -> bool { ShadowView::take_focus(self, d) } - fn set_view_month_offset(&mut self, offset: u32) { - Habit::set_view_month_offset(self, offset) - } fn get_name(&self) -> String { Habit::name(self) } + fn set_view_month_offset(&mut self, offset: u32) { + Habit::set_view_month_offset(self, offset) + } fn view_month_offset(&self) -> u32 { Habit::view_month_offset(self) } fn set_view_mode(&mut self, mode: ViewMode) { - Habit::set_view_mode(&mut self, mode: ViewMode) + Habit::set_view_mode(self, mode) } fn view_mode(&self) -> ViewMode { Habit::view_mode(self) diff --git a/src/views.rs b/src/views.rs index facbd55..3e623a9 100644 --- a/src/views.rs +++ b/src/views.rs @@ -7,7 +7,8 @@ use cursive::{Printer, Vec2}; use chrono::prelude::*; use chrono::{Duration, Local, NaiveDate}; -use crate::habit::{Bit, Count, Habit, TrackEvent, ViewMode}; +use crate::habit::{Bit, Count, Habit, TrackEvent}; + use crate::CONFIGURATION; pub trait ShadowView { @@ -70,29 +71,29 @@ where // ViewMode::Month => // } - let draw_day = |p: &Printer| { - let mut i = 1; - while let Some(d) = NaiveDate::from_ymd_opt(year, month, i) { - let day_style; - if self.reached_goal(d) { - day_style = goal_reached_style; - } else { - day_style = todo_style; - } - let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); - if let Some(c) = self.get_by_date(d) { - printer.with_style(day_style, |p| { - p.print(coords, &format!("{:^3}", c)); - }); - } else { - printer.with_style(future_style, |p| { - p.print(coords, &format!("{:^3}", CONFIGURATION.future_chr)); - }); - } - i += 1; + //let draw_day = |printer: &Printer| { + let mut i = 1; + while let Some(d) = NaiveDate::from_ymd_opt(year, month, i) { + let day_style; + if self.reached_goal(d) { + day_style = goal_reached_style; + } else { + day_style = todo_style; } - }; - draw_day(printer); + let coords: Vec2 = ((i % 7) * 3, i / 7 + 2).into(); + if let Some(c) = self.get_by_date(d) { + printer.with_style(day_style, |p| { + p.print(coords, &format!("{:^3}", c)); + }); + } else { + printer.with_style(future_style, |p| { + p.print(coords, &format!("{:^3}", CONFIGURATION.future_chr)); + }); + } + i += 1; + } + //}; + //draw_day(printer); } fn required_size(&mut self, _: Vec2) -> Vec2 { -- cgit v1.2.3