Render and be able to edit bike rides (and sorta other time distance workouts) #169

Merged
savanni merged 13 commits from fitnesstrax/time-distance-workout into main 2024-02-09 00:05:26 +00:00
3 changed files with 67 additions and 135 deletions
Showing only changes of commit 96c4201680 - Show all commits

View File

@ -28,6 +28,8 @@ use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell; use std::cell::RefCell;
use super::time_distance_detail;
pub struct DaySummaryPrivate { pub struct DaySummaryPrivate {
date: gtk::Label, date: gtk::Label,
} }
@ -178,51 +180,10 @@ impl DayDetail {
s.append(&top_row); s.append(&top_row);
/* let records = view_model.time_distance_records();
records.into_iter().for_each(|record| { for emseries::Record { data, .. } in records {
let record_view = match record { s.append(&time_distance_detail(data));
Record { }
data: ft_core::TraxRecord::BikeRide(record),
..
} => Some(
TimeDistanceView::new(ft_core::RecordType::BikeRide, record)
.upcast::<gtk::Widget>(),
),
Record {
data: ft_core::TraxRecord::Row(record),
..
} => Some(
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
),
Record {
data: ft_core::TraxRecord::Run(record),
..
} => Some(
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
),
Record {
data: ft_core::TraxRecord::Swim(record),
..
} => Some(
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
),
Record {
data: ft_core::TraxRecord::Walk(record),
..
} => Some(
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
),
_ => None,
};
if let Some(record_view) = record_view {
record_view.add_css_class("day-detail");
record_view.set_halign(gtk::Align::Start);
s.append(&record_view);
}
});
*/
s s
} }

View File

@ -30,7 +30,7 @@ mod text_entry;
pub use text_entry::{weight_field, TextEntry}; pub use text_entry::{weight_field, TextEntry};
mod time_distance; mod time_distance;
pub use time_distance::{time_distance_summary, TimeDistanceView}; pub use time_distance::{time_distance_detail, time_distance_summary};
mod weight; mod weight;
pub use weight::WeightLabel; pub use weight::WeightLabel;

View File

@ -18,10 +18,7 @@ You should have received a copy of the GNU General Public License along with Fit
// use chrono::{Local, NaiveDate}; // use chrono::{Local, NaiveDate};
// use dimensioned::si; // use dimensioned::si;
use dimensioned::si; use dimensioned::si;
use ft_core::TimeDistance; use gtk::prelude::*;
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell;
pub fn time_distance_summary( pub fn time_distance_summary(
distance: si::Meter<f64>, distance: si::Meter<f64>,
@ -44,89 +41,63 @@ pub fn time_distance_summary(
text.map(|text| gtk::Label::new(Some(&text))) text.map(|text| gtk::Label::new(Some(&text)))
} }
#[derive(Default)] pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box {
pub struct TimeDistanceViewPrivate { let layout = gtk::Box::builder()
#[allow(unused)] .orientation(gtk::Orientation::Vertical)
record: RefCell<Option<TimeDistance>>, .hexpand(true)
} .build();
let first_row = gtk::Box::builder().homogeneous(true).build();
#[glib::object_subclass]
impl ObjectSubclass for TimeDistanceViewPrivate { first_row.append(
const NAME: &'static str = "TimeDistanceView"; &gtk::Label::builder()
type Type = TimeDistanceView; .halign(gtk::Align::Start)
type ParentType = gtk::Box; .label(record.datetime.format("%H:%M").to_string())
} .build(),
);
impl ObjectImpl for TimeDistanceViewPrivate {}
impl WidgetImpl for TimeDistanceViewPrivate {} first_row.append(
impl BoxImpl for TimeDistanceViewPrivate {} &gtk::Label::builder()
.halign(gtk::Align::Start)
glib::wrapper! { .label(format!("{:?}", record.activity))
pub struct TimeDistanceView(ObjectSubclass<TimeDistanceViewPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; .build(),
} );
impl TimeDistanceView { first_row.append(
pub fn new(record: TimeDistance) -> Self { &gtk::Label::builder()
let s: Self = Object::builder().build(); .halign(gtk::Align::Start)
s.set_orientation(gtk::Orientation::Vertical); .label(
s.set_hexpand(true); record
.distance
let first_row = gtk::Box::builder().homogeneous(true).build(); .map(|dist| format!("{}", dist))
.unwrap_or("".to_owned()),
first_row.append( )
&gtk::Label::builder() .build(),
.halign(gtk::Align::Start) );
.label(record.datetime.format("%H:%M").to_string())
.build(), first_row.append(
); &gtk::Label::builder()
.halign(gtk::Align::Start)
/* .label(
first_row.append( record
&gtk::Label::builder() .duration
.halign(gtk::Align::Start) .map(|duration| format!("{}", duration))
.label(format!("{:?}", type_)) .unwrap_or("".to_owned()),
.build(), )
); .build(),
*/ );
first_row.append( layout.append(&first_row);
&gtk::Label::builder()
.halign(gtk::Align::Start) layout.append(
.label( &gtk::Label::builder()
record .halign(gtk::Align::Start)
.distance .label(
.map(|dist| format!("{}", dist)) record
.unwrap_or("".to_owned()), .comments
) .map(|comments| comments.to_string())
.build(), .unwrap_or("".to_owned()),
); )
.build(),
first_row.append( );
&gtk::Label::builder() layout
.halign(gtk::Align::Start)
.label(
record
.duration
.map(|duration| format!("{}", duration))
.unwrap_or("".to_owned()),
)
.build(),
);
s.append(&first_row);
s.append(
&gtk::Label::builder()
.halign(gtk::Align::Start)
.label(
record
.comments
.map(|comments| comments.to_string())
.unwrap_or("".to_owned()),
)
.build(),
);
s
}
} }