Render time distance details in the day detail view
This commit is contained in:
parent
bbf07ef818
commit
fbe21616e3
|
@ -26,6 +26,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,
|
||||||
}
|
}
|
||||||
|
@ -174,51 +176,18 @@ impl DayDetail {
|
||||||
|
|
||||||
s.append(&top_row);
|
s.append(&top_row);
|
||||||
|
|
||||||
/*
|
let records = view_model.records();
|
||||||
records.into_iter().for_each(|record| {
|
for emseries::Record { data, .. } in records {
|
||||||
let record_view = match record {
|
match data {
|
||||||
Record {
|
TraxRecord::BikeRide(ride) => {
|
||||||
data: ft_core::TraxRecord::BikeRide(record),
|
s.append(&time_distance_detail(RecordType::BikeRide, ride))
|
||||||
..
|
}
|
||||||
} => Some(
|
TraxRecord::Row(row) => s.append(&time_distance_detail(RecordType::Row, row)),
|
||||||
TimeDistanceView::new(ft_core::RecordType::BikeRide, record)
|
TraxRecord::Run(run) => s.append(&time_distance_detail(RecordType::Run, run)),
|
||||||
.upcast::<gtk::Widget>(),
|
TraxRecord::Walk(walk) => s.append(&time_distance_detail(RecordType::Walk, walk)),
|
||||||
),
|
_ => {}
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ mod text_entry;
|
||||||
pub use text_entry::{ParseError, TextEntry};
|
pub use text_entry::{ParseError, 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::{weight_editor, Weight};
|
pub use weight::{weight_editor, Weight};
|
||||||
|
|
|
@ -44,87 +44,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(type_: ft_core::RecordType, 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";
|
>k::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 {}
|
>k::Label::builder()
|
||||||
|
.halign(gtk::Align::Start)
|
||||||
glib::wrapper! {
|
.label(format!("{:?}", type_))
|
||||||
pub struct TimeDistanceView(ObjectSubclass<TimeDistanceViewPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
.build(),
|
||||||
}
|
);
|
||||||
|
|
||||||
impl TimeDistanceView {
|
first_row.append(
|
||||||
pub fn new(type_: RecordType, record: TimeDistance) -> Self {
|
>k::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(
|
)
|
||||||
>k::Label::builder()
|
.build(),
|
||||||
.halign(gtk::Align::Start)
|
);
|
||||||
.label(record.datetime.format("%H:%M").to_string())
|
|
||||||
.build(),
|
first_row.append(
|
||||||
);
|
>k::Label::builder()
|
||||||
|
.halign(gtk::Align::Start)
|
||||||
first_row.append(
|
.label(
|
||||||
>k::Label::builder()
|
record
|
||||||
.halign(gtk::Align::Start)
|
.duration
|
||||||
.label(format!("{:?}", type_))
|
.map(|duration| format!("{}", duration))
|
||||||
.build(),
|
.unwrap_or("".to_owned()),
|
||||||
);
|
)
|
||||||
|
.build(),
|
||||||
first_row.append(
|
);
|
||||||
>k::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
layout.append(&first_row);
|
||||||
.label(
|
|
||||||
record
|
layout.append(
|
||||||
.distance
|
>k::Label::builder()
|
||||||
.map(|dist| format!("{}", dist))
|
.halign(gtk::Align::Start)
|
||||||
.unwrap_or("".to_owned()),
|
.label(
|
||||||
)
|
record
|
||||||
.build(),
|
.comments
|
||||||
);
|
.map(|comments| comments.to_string())
|
||||||
|
.unwrap_or("".to_owned()),
|
||||||
first_row.append(
|
)
|
||||||
>k::Label::builder()
|
.build(),
|
||||||
.halign(gtk::Align::Start)
|
);
|
||||||
.label(
|
layout
|
||||||
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
|
|
||||||
.map(|comments| comments.to_string())
|
|
||||||
.unwrap_or("".to_owned()),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue