2024-01-02 04:58:55 +00:00
|
|
|
/*
|
2024-02-08 04:12:01 +00:00
|
|
|
Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
2024-01-02 04:58:55 +00:00
|
|
|
|
|
|
|
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 crate::components::{EditView, ParseError, TextEntry};
|
|
|
|
// use chrono::{Local, NaiveDate};
|
|
|
|
// use dimensioned::si;
|
2024-01-21 15:50:18 +00:00
|
|
|
use dimensioned::si;
|
2024-01-27 15:37:18 +00:00
|
|
|
use ft_core::TimeDistance;
|
2024-01-26 14:53:42 +00:00
|
|
|
use glib::Object;
|
|
|
|
use gtk::{prelude::*, subclass::prelude::*};
|
|
|
|
use std::cell::RefCell;
|
2024-01-02 04:58:55 +00:00
|
|
|
|
2024-01-21 15:50:18 +00:00
|
|
|
pub fn time_distance_summary(
|
|
|
|
distance: si::Meter<f64>,
|
|
|
|
duration: si::Second<f64>,
|
|
|
|
) -> Option<gtk::Label> {
|
|
|
|
let text = match (distance > si::M, duration > si::S) {
|
|
|
|
(true, true) => Some(format!(
|
|
|
|
"{} kilometers of biking in {} minutes",
|
|
|
|
distance.value_unsafe / 1000.,
|
|
|
|
duration.value_unsafe / 60.
|
|
|
|
)),
|
|
|
|
(true, false) => Some(format!(
|
|
|
|
"{} kilometers of biking",
|
|
|
|
distance.value_unsafe / 1000.
|
|
|
|
)),
|
|
|
|
(false, true) => Some(format!("{} seconds of biking", duration.value_unsafe / 60.)),
|
|
|
|
(false, false) => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
text.map(|text| gtk::Label::new(Some(&text)))
|
|
|
|
}
|
|
|
|
|
2024-01-23 13:28:39 +00:00
|
|
|
pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box {
|
|
|
|
let layout = gtk::Box::builder()
|
|
|
|
.orientation(gtk::Orientation::Vertical)
|
|
|
|
.hexpand(true)
|
|
|
|
.build();
|
|
|
|
let first_row = gtk::Box::builder().homogeneous(true).build();
|
|
|
|
|
|
|
|
first_row.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(record.datetime.format("%H:%M").to_string())
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
|
|
|
|
first_row.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(format!("{:?}", record.activity))
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
|
|
|
|
first_row.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(
|
|
|
|
record
|
|
|
|
.distance
|
|
|
|
.map(|dist| format!("{}", dist))
|
|
|
|
.unwrap_or("".to_owned()),
|
|
|
|
)
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
|
|
|
|
first_row.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(
|
|
|
|
record
|
|
|
|
.duration
|
|
|
|
.map(|duration| format!("{}", duration))
|
|
|
|
.unwrap_or("".to_owned()),
|
|
|
|
)
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
|
|
|
|
layout.append(&first_row);
|
|
|
|
|
|
|
|
layout.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(
|
|
|
|
record
|
|
|
|
.comments
|
|
|
|
.map(|comments| comments.to_string())
|
|
|
|
.unwrap_or("".to_owned()),
|
|
|
|
)
|
|
|
|
.build(),
|
|
|
|
);
|
2024-01-26 14:53:42 +00:00
|
|
|
|
2024-01-23 13:28:39 +00:00
|
|
|
layout
|
2024-01-02 04:58:55 +00:00
|
|
|
}
|
2024-01-26 14:53:42 +00:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct TimeDistanceEditPrivate {
|
|
|
|
#[allow(unused)]
|
|
|
|
record: RefCell<Option<ft_core::TimeDistance>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
impl ObjectSubclass for TimeDistanceEditPrivate {
|
|
|
|
const NAME: &'static str = "TimeDistanceEdit";
|
|
|
|
type Type = TimeDistanceEdit;
|
|
|
|
type ParentType = gtk::Box;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ObjectImpl for TimeDistanceEditPrivate {}
|
|
|
|
impl WidgetImpl for TimeDistanceEditPrivate {}
|
|
|
|
impl BoxImpl for TimeDistanceEditPrivate {}
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
pub struct TimeDistanceEdit(ObjectSubclass<TimeDistanceEditPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TimeDistanceEdit {
|
|
|
|
fn default() -> Self {
|
|
|
|
let s: Self = Object::builder().build();
|
|
|
|
s.set_orientation(gtk::Orientation::Horizontal);
|
2024-01-27 15:37:18 +00:00
|
|
|
s.set_hexpand(true);
|
2024-01-26 14:53:42 +00:00
|
|
|
s.set_css_classes(&["time-distance-edit"]);
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TimeDistanceEdit {
|
2024-01-27 15:37:18 +00:00
|
|
|
pub fn new<OnUpdate>(record: TimeDistance, _on_update: OnUpdate) -> Self
|
2024-01-26 14:53:42 +00:00
|
|
|
where
|
|
|
|
OnUpdate: Fn(&ft_core::TimeDistance),
|
|
|
|
{
|
2024-01-27 15:37:18 +00:00
|
|
|
println!("new TimeDistanceEdit");
|
|
|
|
let s = Self::default();
|
|
|
|
|
|
|
|
s.append(>k::Label::new(Some(
|
|
|
|
record.datetime.format("%H:%M").to_string().as_ref(),
|
|
|
|
)));
|
|
|
|
|
|
|
|
s
|
2024-01-26 14:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
fn with_record<OnUpdate>(type_: ft_core::RecordType, record: ft_core::TimeDistance, on_update: OnUpdate) -> Self
|
|
|
|
where OnUpdate: Fn(&ft_core::RecordType, &ft_core::TimeDistance) {
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|