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-02-08 04:12:01 +00:00
|
|
|
use ft_core::TimeDistance;
|
2024-01-02 04:58:55 +00:00
|
|
|
use glib::Object;
|
|
|
|
use gtk::{prelude::*, subclass::prelude::*};
|
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct TimeDistanceViewPrivate {
|
2024-01-20 19:35:10 +00:00
|
|
|
#[allow(unused)]
|
2024-01-02 04:58:55 +00:00
|
|
|
record: RefCell<Option<TimeDistance>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
impl ObjectSubclass for TimeDistanceViewPrivate {
|
|
|
|
const NAME: &'static str = "TimeDistanceView";
|
|
|
|
type Type = TimeDistanceView;
|
|
|
|
type ParentType = gtk::Box;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ObjectImpl for TimeDistanceViewPrivate {}
|
|
|
|
impl WidgetImpl for TimeDistanceViewPrivate {}
|
|
|
|
impl BoxImpl for TimeDistanceViewPrivate {}
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
pub struct TimeDistanceView(ObjectSubclass<TimeDistanceViewPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TimeDistanceView {
|
2024-02-08 04:12:01 +00:00
|
|
|
pub fn new(record: TimeDistance) -> Self {
|
2024-01-02 04:58:55 +00:00
|
|
|
let s: Self = Object::builder().build();
|
|
|
|
s.set_orientation(gtk::Orientation::Vertical);
|
|
|
|
s.set_hexpand(true);
|
|
|
|
|
|
|
|
let first_row = gtk::Box::builder().homogeneous(true).build();
|
|
|
|
|
|
|
|
first_row.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
2024-01-20 19:35:10 +00:00
|
|
|
.label(record.datetime.format("%H:%M").to_string())
|
2024-01-02 04:58:55 +00:00
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
|
2024-02-08 04:12:01 +00:00
|
|
|
/*
|
2024-01-02 04:58:55 +00:00
|
|
|
first_row.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(format!("{:?}", type_))
|
|
|
|
.build(),
|
|
|
|
);
|
2024-02-08 04:12:01 +00:00
|
|
|
*/
|
2024-01-02 04:58:55 +00:00
|
|
|
|
|
|
|
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(),
|
|
|
|
);
|
|
|
|
|
|
|
|
s.append(&first_row);
|
|
|
|
|
|
|
|
s.append(
|
|
|
|
>k::Label::builder()
|
|
|
|
.halign(gtk::Align::Start)
|
|
|
|
.label(
|
|
|
|
record
|
|
|
|
.comments
|
2024-01-20 19:35:10 +00:00
|
|
|
.map(|comments| comments.to_string())
|
2024-01-02 04:58:55 +00:00
|
|
|
.unwrap_or("".to_owned()),
|
|
|
|
)
|
|
|
|
.build(),
|
|
|
|
);
|
|
|
|
|
|
|
|
s
|
|
|
|
}
|
|
|
|
}
|