/* Copyright 2023, Savanni D'Gerinel This file is part of FitnessTrax. FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see . */ // use chrono::NaiveDate; // use ft_core::TraxRecord; use ft_core::TraxRecord; use glib::Object; use gtk::{prelude::*, subclass::prelude::*}; use std::cell::RefCell; pub struct DaySummaryPrivate { date: gtk::Label, weight: RefCell>, } #[glib::object_subclass] impl ObjectSubclass for DaySummaryPrivate { const NAME: &'static str = "DaySummary"; type Type = DaySummary; type ParentType = gtk::Box; fn new() -> Self { let date = gtk::Label::builder() .css_classes(["day-summary__date"]) .halign(gtk::Align::Start) .build(); Self { date, weight: RefCell::new(None), } } } impl ObjectImpl for DaySummaryPrivate {} impl WidgetImpl for DaySummaryPrivate {} impl BoxImpl for DaySummaryPrivate {} glib::wrapper! { /// The DaySummary displays one day's activities in a narrative style. This is meant to give /// an overall feel of everything that happened during the day without going into details. pub struct DaySummary(ObjectSubclass) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; } impl DaySummary { pub fn new() -> Self { let s: Self = Object::builder().build(); s.set_orientation(gtk::Orientation::Vertical); s.set_css_classes(&["day-summary"]); s.append(&s.imp().date); s } pub fn set_data(&self, date: chrono::NaiveDate, records: Vec) { self.imp() .date .set_text(&date.format("%Y-%m-%d").to_string()); if let Some(ref weight_label) = *self.imp().weight.borrow() { self.remove(weight_label); } if let Some(TraxRecord::Weight(weight_record)) = records.iter().filter(|f| f.is_weight()).next() { let label = gtk::Label::builder() .halign(gtk::Align::Start) .label(&format!("{}", weight_record.weight)) .css_classes(["day-summary__weight"]) .build(); self.append(&label); *self.imp().weight.borrow_mut() = Some(label); } self.append( >k::Label::builder() .halign(gtk::Align::Start) .label("15km of biking in 60 minutes") .build(), ); } } pub struct DayDetailPrivate { date: gtk::Label, weight: RefCell>, } #[glib::object_subclass] impl ObjectSubclass for DayDetailPrivate { const NAME: &'static str = "DayDetail"; type Type = DayDetail; type ParentType = gtk::Box; fn new() -> Self { let date = gtk::Label::builder() .css_classes(["daysummary-date"]) .halign(gtk::Align::Start) .build(); Self { date, weight: RefCell::new(None), } } } impl ObjectImpl for DayDetailPrivate {} impl WidgetImpl for DayDetailPrivate {} impl BoxImpl for DayDetailPrivate {} glib::wrapper! { pub struct DayDetail(ObjectSubclass) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; } impl DayDetail { pub fn new(date: chrono::NaiveDate, records: Vec) -> Self { let s: Self = Object::builder().build(); s.set_orientation(gtk::Orientation::Vertical); records.into_iter().for_each(|record| { let record_view = match record { TraxRecord::BikeRide(_) => gtk::Label::new(Some("BikeRide")), TraxRecord::Row(_) => gtk::Label::new(Some("Row")), TraxRecord::Run(_) => gtk::Label::new(Some("Run")), TraxRecord::Steps(_) => gtk::Label::new(Some("Steps")), TraxRecord::Swim(_) => gtk::Label::new(Some("Swim")), TraxRecord::Walk(_) => gtk::Label::new(Some("Walk")), TraxRecord::Weight(_) => gtk::Label::new(Some("Weight")), }; record_view.add_css_class("day-detail"); record_view.set_halign(gtk::Align::Start); s.append(&record_view); }); s } }