Ensure there is a button for every workout type
This commit is contained in:
parent
73a5ab89a3
commit
6e5cbc0930
|
@ -3,15 +3,16 @@
|
|||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/">
|
||||
<file>style.css</file>
|
||||
</gresource>
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions/">
|
||||
<file preprocess="xml-stripblanks">walking2-symbolic.svg</file>
|
||||
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions">
|
||||
<file preprocess="xml-stripblanks">cycling-symbolic.svg</file>
|
||||
</gresource>
|
||||
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions">
|
||||
<file preprocess="xml-stripblanks">running-symbolic.svg</file>
|
||||
</gresource>
|
||||
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions">
|
||||
<file preprocess="xml-stripblanks">cycling-symbolic.svg</file>
|
||||
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions/">
|
||||
<file preprocess="xml-stripblanks">walking-symbolic.svg</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
|
@ -349,56 +349,53 @@ where
|
|||
AddRow: Fn(Record<TraxRecord>) + 'static,
|
||||
{
|
||||
let add_row = Rc::new(add_row);
|
||||
/*
|
||||
let walking_button = gtk::Button::builder()
|
||||
.icon_name("walking2-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
walking_button.connect_clicked({
|
||||
let view_model = view_model.clone();
|
||||
let add_row = add_row.clone();
|
||||
move |_| {
|
||||
let workout = view_model.new_time_distance(TimeDistanceActivity::Walking);
|
||||
add_row(workout.map(TraxRecord::TimeDistance));
|
||||
}
|
||||
});
|
||||
|
||||
let running_button = gtk::Button::builder()
|
||||
.icon_name("running-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
running_button.connect_clicked({
|
||||
let view_model = view_model.clone();
|
||||
move |_| {
|
||||
let workout = view_model.new_time_distance(TimeDistanceActivity::Running);
|
||||
add_row(workout.map(TraxRecord::TimeDistance));
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
let biking_button = gtk::Button::builder()
|
||||
.icon_name("cycling-symbolic")
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
biking_button.connect_clicked({
|
||||
let view_model = view_model.clone();
|
||||
move |_| {
|
||||
let workout = view_model.new_time_distance(TimeDistanceActivity::Biking);
|
||||
add_row(workout.map(TraxRecord::TimeDistance));
|
||||
}
|
||||
});
|
||||
|
||||
let layout = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.build();
|
||||
let row = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
row.append(&biking_button);
|
||||
layout.append(&row);
|
||||
|
||||
for (activity, icon, label) in [
|
||||
(
|
||||
TimeDistanceActivity::Biking,
|
||||
"cycling-symbolic",
|
||||
"Bike Ride",
|
||||
),
|
||||
(TimeDistanceActivity::Rowing, "rowing-symbolic", "Rowing"),
|
||||
(TimeDistanceActivity::Running, "running-symbolic", "Run"),
|
||||
(TimeDistanceActivity::Swimming, "swimming-symbolic", "Swim"),
|
||||
(TimeDistanceActivity::Walking, "walking-symbolic", "Walk"),
|
||||
] {
|
||||
let button = workout_button(activity, icon, label, view_model.clone(), {
|
||||
let add_row = add_row.clone();
|
||||
move |record| add_row(record)
|
||||
});
|
||||
layout.append(&button);
|
||||
}
|
||||
|
||||
layout
|
||||
}
|
||||
|
||||
fn workout_button<AddRow>(
|
||||
activity: TimeDistanceActivity,
|
||||
_icon: &str,
|
||||
label: &str,
|
||||
view_model: DayDetailViewModel,
|
||||
add_row: AddRow,
|
||||
) -> gtk::Button
|
||||
where
|
||||
AddRow: Fn(Record<TraxRecord>) + 'static,
|
||||
{
|
||||
let button = gtk::Button::builder()
|
||||
.label(label)
|
||||
.width_request(64)
|
||||
.height_request(64)
|
||||
.build();
|
||||
button.connect_clicked({
|
||||
let view_model = view_model.clone();
|
||||
move |_| {
|
||||
let workout = view_model.new_time_distance(activity);
|
||||
add_row(workout.map(TraxRecord::TimeDistance));
|
||||
}
|
||||
});
|
||||
button
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue