From 605d310c57436b85f02ff1598204a4d2f5bfa898 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 18 Feb 2024 11:28:40 -0500 Subject: [PATCH] Apply clippy --- fitnesstrax/app/src/components/date_field.rs | 9 +--- fitnesstrax/app/src/components/date_range.rs | 50 ++++++++++---------- fitnesstrax/app/src/components/text_entry.rs | 4 -- fitnesstrax/app/src/views/historical_view.rs | 4 +- 4 files changed, 28 insertions(+), 39 deletions(-) diff --git a/fitnesstrax/app/src/components/date_field.rs b/fitnesstrax/app/src/components/date_field.rs index dafab5d..7e8697c 100644 --- a/fitnesstrax/app/src/components/date_field.rs +++ b/fitnesstrax/app/src/components/date_field.rs @@ -20,13 +20,6 @@ use glib::Object; use gtk::{prelude::*, subclass::prelude::*}; use std::{cell::RefCell, rc::Rc}; -#[derive(Clone, Debug)] -enum Part { - Year, - Month, - Day, -} - pub struct DateFieldPrivate { date: Rc>, year: TextEntry, @@ -140,7 +133,7 @@ impl DateField { } pub fn date(&self) -> chrono::NaiveDate { - self.imp().date.borrow().clone() + *self.imp().date.borrow() } /* pub fn is_valid(&self) -> bool { diff --git a/fitnesstrax/app/src/components/date_range.rs b/fitnesstrax/app/src/components/date_range.rs index ebad6aa..6cb0198 100644 --- a/fitnesstrax/app/src/components/date_range.rs +++ b/fitnesstrax/app/src/components/date_range.rs @@ -15,15 +15,13 @@ You should have received a copy of the GNU General Public License along with Fit */ use crate::{ - app::App, - components::{DateField, DaySummary}, + components::{DateField}, types::DayInterval, - view_models::DayDetailViewModel, }; use chrono::{Duration, Local, Months}; use glib::Object; use gtk::{prelude::*, subclass::prelude::*}; -use std::{cell::RefCell, rc::Rc}; +use std::{cell::RefCell}; type OnSearch = dyn Fn(DayInterval) + 'static; @@ -58,8 +56,31 @@ glib::wrapper! { pub struct DateRangePicker(ObjectSubclass) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; } + impl DateRangePicker { - pub fn new() -> Self { + pub fn connect_on_search(&self, f: OnSearch) + where + OnSearch: Fn(DayInterval) + 'static, + { + *self.imp().on_search.borrow_mut() = Box::new(f); + } + + fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) { + self.imp().start.set_date(start); + self.imp().end.set_date(end); + } + + fn interval(&self) -> DayInterval { + DayInterval { + start: self.imp().start.date(), + end: self.imp().end.date(), + } + } +} + + +impl Default for DateRangePicker { + fn default() -> Self { let s: Self = Object::builder().build(); s.set_orientation(gtk::Orientation::Vertical); @@ -146,23 +167,4 @@ impl DateRangePicker { s } - - pub fn connect_on_search(&self, f: OnSearch) - where - OnSearch: Fn(DayInterval) + 'static, - { - *self.imp().on_search.borrow_mut() = Box::new(f); - } - - fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) { - self.imp().start.set_date(start); - self.imp().end.set_date(end); - } - - fn interval(&self) -> DayInterval { - DayInterval { - start: self.imp().start.date(), - end: self.imp().end.date(), - } - } } diff --git a/fitnesstrax/app/src/components/text_entry.rs b/fitnesstrax/app/src/components/text_entry.rs index 74615ab..a0790bc 100644 --- a/fitnesstrax/app/src/components/text_entry.rs +++ b/fitnesstrax/app/src/components/text_entry.rs @@ -109,10 +109,6 @@ impl TextEntry { self.widget.add_css_class(class_); } - pub fn remove_css_class(&self, class_: &str) { - self.widget.remove_css_class(class_); - } - pub fn widget(&self) -> gtk::Widget { self.widget.clone().upcast::() } diff --git a/fitnesstrax/app/src/views/historical_view.rs b/fitnesstrax/app/src/views/historical_view.rs index bfb60e1..d843482 100644 --- a/fitnesstrax/app/src/views/historical_view.rs +++ b/fitnesstrax/app/src/views/historical_view.rs @@ -29,7 +29,6 @@ use std::{cell::RefCell, rc::Rc}; /// records. pub struct HistoricalViewPrivate { app: Rc>>, - time_window: Rc>, list_view: gtk::ListView, } @@ -50,7 +49,6 @@ impl ObjectSubclass for HistoricalViewPrivate { let s = Self { app: Rc::new(RefCell::new(None)), - time_window: Rc::new(RefCell::new(DayInterval::default())), list_view: gtk::ListView::builder() .factory(&factory) .single_click_activate(true) @@ -108,7 +106,7 @@ impl HistoricalView { *s.imp().app.borrow_mut() = Some(app); - let date_range_picker = DateRangePicker::new(); + let date_range_picker = DateRangePicker::default(); date_range_picker.connect_on_search({ let s = s.clone(); move |interval| s.set_interval(interval)