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/habit/bit.rs | 12 ++++++++++++ src/habit/count.rs | 12 ++++++++++++ src/habit/traits.rs | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) (limited to 'src/habit') diff --git a/src/habit/bit.rs b/src/habit/bit.rs index 2bbb0ac..7fe6fd9 100644 --- a/src/habit/bit.rs +++ b/src/habit/bit.rs @@ -1,8 +1,10 @@ use std::collections::HashMap; use chrono::NaiveDate; +use cursive::direction::Absolute; use serde::{Deserialize, Serialize}; +use crate::app::Cursor; use crate::habit::prelude::default_auto; use crate::habit::traits::Habit; use crate::habit::{TrackEvent, ViewMode}; @@ -44,6 +46,9 @@ pub struct Bit { #[serde(skip)] view_month_offset: u32, + #[serde(skip)] + cursor: Cursor, + #[serde(skip)] view_mode: ViewMode, } @@ -56,6 +61,7 @@ impl Bit { goal: CustomBool(true), auto, view_month_offset: 0, + cursor: Cursor::new(), view_mode: ViewMode::Day, }; } @@ -124,6 +130,12 @@ impl Habit for Bit { fn view_month_offset(&self) -> u32 { self.view_month_offset } + fn move_cursor(&mut self, d: Absolute) { + self.cursor.do_move(d); + } + fn cursor(&self) -> Cursor { + self.cursor + } fn set_view_mode(&mut self, mode: ViewMode) { self.view_mode = mode; } diff --git a/src/habit/count.rs b/src/habit/count.rs index d351758..b14354c 100644 --- a/src/habit/count.rs +++ b/src/habit/count.rs @@ -1,8 +1,10 @@ use std::collections::HashMap; use chrono::NaiveDate; +use cursive::direction::Absolute; use serde::{Deserialize, Serialize}; +use crate::app::Cursor; use crate::habit::prelude::default_auto; use crate::habit::traits::Habit; use crate::habit::{TrackEvent, ViewMode}; @@ -19,6 +21,9 @@ pub struct Count { #[serde(skip)] view_month_offset: u32, + #[serde(skip)] + cursor: Cursor, + #[serde(skip)] view_mode: ViewMode, } @@ -31,6 +36,7 @@ impl Count { goal, auto, view_month_offset: 0, + cursor: Cursor::new(), view_mode: ViewMode::Day, }; } @@ -101,6 +107,12 @@ impl Habit for Count { fn view_month_offset(&self) -> u32 { self.view_month_offset } + fn move_cursor(&mut self, d: Absolute) { + self.cursor.do_move(d); + } + fn cursor(&self) -> Cursor { + self.cursor + } fn set_view_mode(&mut self, mode: ViewMode) { self.view_mode = mode; } diff --git a/src/habit/traits.rs b/src/habit/traits.rs index 74fd00b..289fd95 100644 --- a/src/habit/traits.rs +++ b/src/habit/traits.rs @@ -1,10 +1,11 @@ use chrono::NaiveDate; -use cursive::direction::Direction; +use cursive::direction::{Absolute, Direction}; use cursive::event::{Event, EventResult}; use cursive::{Printer, Vec2}; use typetag; +use crate::app::Cursor; use crate::habit::{Bit, Count, TrackEvent, ViewMode}; use crate::views::ShadowView; @@ -24,6 +25,9 @@ pub trait Habit { fn set_view_month_offset(&mut self, offset: u32); fn view_month_offset(&self) -> u32; + fn move_cursor(&mut self, d: Absolute); + fn cursor(&self) -> Cursor; + fn set_view_mode(&mut self, mode: ViewMode); fn view_mode(&self) -> ViewMode; @@ -44,6 +48,9 @@ pub trait HabitWrapper: erased_serde::Serialize { fn set_view_month_offset(&mut self, offset: u32); fn view_month_offset(&self) -> u32; + fn move_cursor(&mut self, d: Absolute); + fn cursor(&self) -> Cursor; + fn set_view_mode(&mut self, mode: ViewMode); fn view_mode(&self) -> ViewMode; @@ -87,6 +94,12 @@ macro_rules! auto_habit_impl { fn view_month_offset(&self) -> u32 { Habit::view_month_offset(self) } + fn move_cursor(&mut self, d: Absolute) { + Habit::move_cursor(self, d) + } + fn cursor(&self) -> Cursor { + Habit::cursor(self) + } fn set_view_mode(&mut self, mode: ViewMode) { Habit::set_view_mode(self, mode) } -- cgit v1.2.3