2023-12-22 22:32:45 +00:00
|
|
|
/*
|
|
|
|
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
|
|
|
|
|
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// use chrono::NaiveDate;
|
|
|
|
// use ft_core::TraxRecord;
|
2023-12-22 23:53:29 +00:00
|
|
|
use ft_core::TraxRecord;
|
2023-12-22 22:32:45 +00:00
|
|
|
use glib::Object;
|
|
|
|
use gtk::{prelude::*, subclass::prelude::*};
|
2023-12-22 23:53:29 +00:00
|
|
|
use std::cell::RefCell;
|
2023-12-22 22:32:45 +00:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct DaySummaryPrivate {
|
|
|
|
date: gtk::Label,
|
2023-12-22 23:53:29 +00:00
|
|
|
weight: RefCell<Option<gtk::Label>>,
|
2023-12-22 22:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
impl ObjectSubclass for DaySummaryPrivate {
|
|
|
|
const NAME: &'static str = "DaySummary";
|
|
|
|
type Type = DaySummary;
|
|
|
|
type ParentType = gtk::Box;
|
|
|
|
|
|
|
|
fn new() -> Self {
|
2023-12-24 17:00:12 +00:00
|
|
|
let date = gtk::Label::builder()
|
|
|
|
.css_classes(["daysummary-date"])
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.build();
|
2023-12-22 22:32:45 +00:00
|
|
|
Self {
|
2023-12-24 17:00:12 +00:00
|
|
|
date,
|
2023-12-22 23:53:29 +00:00
|
|
|
weight: RefCell::new(None),
|
2023-12-22 22:32:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ObjectImpl for DaySummaryPrivate {}
|
|
|
|
impl WidgetImpl for DaySummaryPrivate {}
|
|
|
|
impl BoxImpl for DaySummaryPrivate {}
|
|
|
|
|
|
|
|
glib::wrapper! {
|
2023-12-24 17:00:12 +00:00
|
|
|
/// 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.
|
2023-12-22 22:32:45 +00:00
|
|
|
pub struct DaySummary(ObjectSubclass<DaySummaryPrivate>) @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);
|
2023-12-24 17:00:12 +00:00
|
|
|
s.set_css_classes(&["daysummary"]);
|
2023-12-22 22:32:45 +00:00
|
|
|
|
|
|
|
s.append(&s.imp().date);
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
|
2023-12-24 17:00:12 +00:00
|
|
|
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<TraxRecord>) {
|
2023-12-22 22:32:45 +00:00
|
|
|
self.imp()
|
|
|
|
.date
|
|
|
|
.set_text(&date.format("%y-%m-%d").to_string());
|
2023-12-22 23:53:29 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-12-24 17:00:12 +00:00
|
|
|
let label = gtk::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(&format!("{}", weight_record.weight))
|
|
|
|
.css_classes(["daysummary-weight"])
|
|
|
|
.build();
|
2023-12-22 23:53:29 +00:00
|
|
|
self.append(&label);
|
|
|
|
*self.imp().weight.borrow_mut() = Some(label);
|
|
|
|
}
|
|
|
|
}
|
2023-12-22 22:32:45 +00:00
|
|
|
}
|