diff --git a/fitnesstrax/app/src/components/day.rs b/fitnesstrax/app/src/components/day.rs
index 970bf8b..15eb9ce 100644
--- a/fitnesstrax/app/src/components/day.rs
+++ b/fitnesstrax/app/src/components/day.rs
@@ -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, weight_editor, ActionGroup, Steps, WeightLabel},
+ components::{steps_editor, weight_field, ActionGroup, Steps, WeightLabel},
view_models::DayDetailViewModel,
};
use glib::Object;
@@ -283,7 +283,7 @@ impl DayEdit {
.orientation(gtk::Orientation::Horizontal)
.build();
top_row.append(
- &weight_editor(view_model.weight(), {
+ &weight_field(view_model.weight(), {
let view_model = view_model.clone();
move |w| match w {
Some(w) => view_model.set_weight(w),
diff --git a/fitnesstrax/app/src/components/mod.rs b/fitnesstrax/app/src/components/mod.rs
index 8b2fff5..b6c0fe3 100644
--- a/fitnesstrax/app/src/components/mod.rs
+++ b/fitnesstrax/app/src/components/mod.rs
@@ -27,13 +27,13 @@ mod steps;
pub use steps::{steps_editor, Steps};
mod text_entry;
-pub use text_entry::TextEntry;
+pub use text_entry::{weight_field, TextEntry};
mod time_distance;
pub use time_distance::TimeDistanceView;
mod weight;
-pub use weight::{weight_editor, WeightLabel};
+pub use weight::WeightLabel;
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
diff --git a/fitnesstrax/app/src/components/text_entry.rs b/fitnesstrax/app/src/components/text_entry.rs
index a90ccbb..ff8c206 100644
--- a/fitnesstrax/app/src/components/text_entry.rs
+++ b/fitnesstrax/app/src/components/text_entry.rs
@@ -14,7 +14,9 @@ General Public License for more details.
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see .
*/
-use crate::types::ParseError;
+use crate::types::{
+ DistanceFormatter, DurationFormatter, FormatOption, ParseError, TimeFormatter, WeightFormatter,
+};
use gtk::prelude::*;
use std::{cell::RefCell, rc::Rc};
@@ -104,6 +106,69 @@ impl TextEntry {
}
}
+pub fn time_field(
+ value: Option,
+ on_update: OnUpdate,
+) -> TextEntry
+where
+ OnUpdate: Fn(Option) + 'static,
+{
+ TextEntry::new(
+ "HH:MM",
+ value,
+ |val| val.format(FormatOption::Abbreviated),
+ TimeFormatter::parse,
+ on_update,
+ )
+}
+
+pub fn distance_field(
+ value: Option,
+ on_update: OnUpdate,
+) -> TextEntry
+where
+ OnUpdate: Fn(Option) + 'static,
+{
+ TextEntry::new(
+ "0 km",
+ value,
+ |val| val.format(FormatOption::Abbreviated),
+ DistanceFormatter::parse,
+ on_update,
+ )
+}
+
+pub fn duration_field(
+ value: Option,
+ on_update: OnUpdate,
+) -> TextEntry
+where
+ OnUpdate: Fn(Option) + 'static,
+{
+ TextEntry::new(
+ "0 m",
+ value,
+ |val| val.format(FormatOption::Abbreviated),
+ DurationFormatter::parse,
+ on_update,
+ )
+}
+pub fn weight_field(
+ weight: Option,
+ on_update: OnUpdate,
+) -> TextEntry
+where
+ OnUpdate: Fn(Option) + 'static,
+{
+ TextEntry::new(
+ "0 kg",
+ weight,
+ |val| val.format(FormatOption::Abbreviated),
+ WeightFormatter::parse,
+ on_update,
+ )
+}
+
#[cfg(test)]
mod test {
use super::*;
diff --git a/fitnesstrax/app/src/components/weight.rs b/fitnesstrax/app/src/components/weight.rs
index 1558f74..23ab48f 100644
--- a/fitnesstrax/app/src/components/weight.rs
+++ b/fitnesstrax/app/src/components/weight.rs
@@ -43,19 +43,3 @@ impl WeightLabel {
self.label.clone().upcast()
}
}
-
-pub fn weight_editor(
- weight: Option,
- on_update: OnUpdate,
-) -> TextEntry
-where
- OnUpdate: Fn(Option) + 'static,
-{
- TextEntry::new(
- "0 kg",
- weight,
- |val| val.format(FormatOption::Abbreviated),
- WeightFormatter::parse,
- on_update,
- )
-}
diff --git a/fitnesstrax/app/src/types.rs b/fitnesstrax/app/src/types.rs
index 0411596..5172add 100644
--- a/fitnesstrax/app/src/types.rs
+++ b/fitnesstrax/app/src/types.rs
@@ -60,7 +60,7 @@ pub enum FormatOption {
pub struct TimeFormatter(chrono::NaiveTime);
impl TimeFormatter {
- fn format(&self, option: FormatOption) -> String {
+ pub fn format(&self, option: FormatOption) -> String {
match option {
FormatOption::Abbreviated => self.0.format("%H:%M"),
FormatOption::Full => self.0.format("%H:%M:%S"),
@@ -68,7 +68,7 @@ impl TimeFormatter {
.to_string()
}
- fn parse(s: &str) -> Result {
+ pub fn parse(s: &str) -> Result {
let parts = s
.split(':')
.map(|part| part.parse::().map_err(|_| ParseError))