Ensure there is a button for every workout type #184

Merged
savanni merged 1 commits from fitnesstrax/workout-buttons into main 2024-02-10 03:52:05 +00:00
3 changed files with 48 additions and 50 deletions

View File

@ -3,15 +3,16 @@
<gresource prefix="/com/luminescent-dreams/fitnesstrax/"> <gresource prefix="/com/luminescent-dreams/fitnesstrax/">
<file>style.css</file> <file>style.css</file>
</gresource> </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>
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions"> <gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions">
<file preprocess="xml-stripblanks">running-symbolic.svg</file> <file preprocess="xml-stripblanks">running-symbolic.svg</file>
</gresource> </gresource>
<gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions"> <gresource prefix="/com/luminescent-dreams/fitnesstrax/icons/scalable/actions/">
<file preprocess="xml-stripblanks">cycling-symbolic.svg</file> <file preprocess="xml-stripblanks">walking-symbolic.svg</file>
</gresource> </gresource>
</gresources> </gresources>

View File

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -349,56 +349,53 @@ where
AddRow: Fn(Record<TraxRecord>) + 'static, AddRow: Fn(Record<TraxRecord>) + 'static,
{ {
let add_row = Rc::new(add_row); 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() let layout = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
let row = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal) .orientation(gtk::Orientation::Horizontal)
.build(); .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 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
}