Simplify the weight editor
This commit is contained in:
parent
d4c48c4443
commit
9461c387fe
|
@ -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);
|
||||
|
|
|
@ -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::*};
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue