Apply clippy

This commit is contained in:
Savanni D'Gerinel 2024-02-18 11:28:40 -05:00 committed by savanni
parent 74dbb58ed9
commit d137ee2481
4 changed files with 28 additions and 39 deletions

View File

@ -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<RefCell<chrono::NaiveDate>>,
year: TextEntry<i32>,
@ -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 {

View File

@ -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<DateRangePickerPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
}
impl DateRangePicker {
pub fn new() -> Self {
pub fn connect_on_search<OnSearch>(&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<OnSearch>(&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(),
}
}
}

View File

@ -109,10 +109,6 @@ impl<T: Clone + std::fmt::Debug + 'static> TextEntry<T> {
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::<gtk::Widget>()
}

View File

@ -29,7 +29,6 @@ use std::{cell::RefCell, rc::Rc};
/// records.
pub struct HistoricalViewPrivate {
app: Rc<RefCell<Option<App>>>,
time_window: Rc<RefCell<DayInterval>>,
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)