Add a step count editor field #162

Merged
savanni merged 3 commits from fitnesstrax/step-counting into main 2024-01-20 22:08:31 +00:00
3 changed files with 28 additions and 48 deletions
Showing only changes of commit 9461c387fe - Show all commits

View File

@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Fit
// use chrono::NaiveDate;
// use ft_core::TraxRecord;
use crate::{
components::{steps_editor, ActionGroup, Steps, Weight, WeightEdit},
components::{steps_editor, weight_editor, ActionGroup, Steps, Weight},
view_models::DayDetailViewModel,
};
use emseries::Record;
@ -287,9 +287,11 @@ impl DayEdit {
.build(),
);
let top_row = gtk::Box::builder().orientation(gtk::Orientation::Horizontal).build();
let top_row = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.build();
top_row.append(
&WeightEdit::new(view_model.weight(), {
&weight_editor(view_model.weight(), {
let view_model = view_model.clone();
move |w| {
view_model.set_weight(w);

View File

@ -33,7 +33,7 @@ mod time_distance;
pub use time_distance::TimeDistanceView;
mod weight;
pub use weight::{Weight, WeightEdit};
pub use weight::{weight_editor, Weight};
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};

View File

@ -18,9 +18,6 @@ use crate::components::{ParseError, TextEntry};
use dimensioned::si;
use gtk::prelude::*;
#[derive(Default)]
pub struct WeightViewPrivate {}
pub struct Weight {
label: gtk::Label,
}
@ -45,18 +42,14 @@ impl Weight {
}
}
#[derive(Debug)]
pub struct WeightEdit {
entry: TextEntry<si::Kilogram<f64>>,
}
impl WeightEdit {
pub fn new<OnUpdate>(weight: Option<si::Kilogram<f64>>, on_update: OnUpdate) -> Self
pub fn weight_editor<OnUpdate>(
weight: Option<si::Kilogram<f64>>,
on_update: OnUpdate,
) -> TextEntry<si::Kilogram<f64>>
where
OnUpdate: Fn(si::Kilogram<f64>) + 'static,
{
Self {
entry: TextEntry::new(
TextEntry::new(
"0 kg",
weight,
|val: &si::Kilogram<f64>| val.to_string(),
@ -70,20 +63,5 @@ impl WeightEdit {
Err(err) => Err(err),
}
},
),
}
}
#[allow(unused)]
pub fn set_value(&self, value: Option<si::Kilogram<f64>>) {
self.entry.set_value(value);
}
pub fn value(&self) -> Option<si::Kilogram<f64>> {
self.entry.value()
}
pub fn widget(&self) -> gtk::Widget {
self.entry.widget()
}
)
}