Add a step count editor field #162
|
@ -11,8 +11,7 @@
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome__footer {
|
.welcome__footer {}
|
||||||
}
|
|
||||||
|
|
||||||
.historical {
|
.historical {
|
||||||
margin: 32px;
|
margin: 32px;
|
||||||
|
@ -37,3 +36,7 @@
|
||||||
margin: 8px;
|
margin: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.step-view {
|
||||||
|
padding: 8px;
|
||||||
|
margin: 8px;
|
||||||
|
}
|
|
@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
// use chrono::NaiveDate;
|
// use chrono::NaiveDate;
|
||||||
// use ft_core::TraxRecord;
|
// use ft_core::TraxRecord;
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{ActionGroup, Weight},
|
components::{steps_editor, ActionGroup, Steps, Weight, WeightEdit},
|
||||||
view_models::DayDetailViewModel,
|
view_models::DayDetailViewModel,
|
||||||
};
|
};
|
||||||
use emseries::Record;
|
use emseries::Record;
|
||||||
|
@ -25,8 +25,6 @@ use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use super::weight::WeightEdit;
|
|
||||||
|
|
||||||
pub struct DaySummaryPrivate {
|
pub struct DaySummaryPrivate {
|
||||||
date: gtk::Label,
|
date: gtk::Label,
|
||||||
weight: RefCell<Option<gtk::Label>>,
|
weight: RefCell<Option<gtk::Label>>,
|
||||||
|
@ -169,8 +167,16 @@ impl DayDetail {
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let top_row = gtk::Box::builder()
|
||||||
|
.orientation(gtk::Orientation::Horizontal)
|
||||||
|
.build();
|
||||||
let weight_view = Weight::new(view_model.weight());
|
let weight_view = Weight::new(view_model.weight());
|
||||||
s.append(&weight_view.widget());
|
top_row.append(&weight_view.widget());
|
||||||
|
|
||||||
|
let steps_view = Steps::new(view_model.steps());
|
||||||
|
top_row.append(&steps_view.widget());
|
||||||
|
|
||||||
|
s.append(&top_row);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
records.into_iter().for_each(|record| {
|
records.into_iter().for_each(|record| {
|
||||||
|
@ -281,7 +287,8 @@ impl DayEdit {
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
|
|
||||||
s.append(
|
let top_row = gtk::Box::builder().orientation(gtk::Orientation::Horizontal).build();
|
||||||
|
top_row.append(
|
||||||
&WeightEdit::new(view_model.weight(), {
|
&WeightEdit::new(view_model.weight(), {
|
||||||
let view_model = view_model.clone();
|
let view_model = view_model.clone();
|
||||||
move |w| {
|
move |w| {
|
||||||
|
@ -291,6 +298,15 @@ impl DayEdit {
|
||||||
.widget(),
|
.widget(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
top_row.append(
|
||||||
|
&steps_editor(view_model.steps(), {
|
||||||
|
let view_model = view_model.clone();
|
||||||
|
move |s| view_model.set_steps(s)
|
||||||
|
})
|
||||||
|
.widget(),
|
||||||
|
);
|
||||||
|
s.append(&top_row);
|
||||||
|
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@ pub use day::{DayDetail, DayEdit, DaySummary};
|
||||||
mod singleton;
|
mod singleton;
|
||||||
pub use singleton::{Singleton, SingletonImpl};
|
pub use singleton::{Singleton, SingletonImpl};
|
||||||
|
|
||||||
|
mod steps;
|
||||||
|
pub use steps::{steps_editor, Steps};
|
||||||
|
|
||||||
mod text_entry;
|
mod text_entry;
|
||||||
pub use text_entry::{ParseError, TextEntry};
|
pub use text_entry::{ParseError, TextEntry};
|
||||||
|
|
||||||
|
@ -30,7 +33,7 @@ mod time_distance;
|
||||||
pub use time_distance::TimeDistanceView;
|
pub use time_distance::TimeDistanceView;
|
||||||
|
|
||||||
mod weight;
|
mod weight;
|
||||||
pub use weight::Weight;
|
pub use weight::{Weight, WeightEdit};
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
|
This file is part of FitnessTrax.
|
||||||
|
|
||||||
|
FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||||
|
General Public License as published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||||
|
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use crate::components::{ParseError, TextEntry};
|
||||||
|
use gtk::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Steps {
|
||||||
|
label: gtk::Label,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Steps {
|
||||||
|
pub fn new(steps: Option<u32>) -> Self {
|
||||||
|
let label = gtk::Label::builder()
|
||||||
|
.css_classes(["card", "step-view"])
|
||||||
|
.can_focus(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
match steps {
|
||||||
|
Some(s) => label.set_text(&format!("{}", s)),
|
||||||
|
None => label.set_text("No steps recorded"),
|
||||||
|
}
|
||||||
|
|
||||||
|
Self { label }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn widget(&self) -> gtk::Widget {
|
||||||
|
self.label.clone().upcast()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn steps_editor<OnUpdate>(value: Option<u32>, on_update: OnUpdate) -> TextEntry<u32>
|
||||||
|
where
|
||||||
|
OnUpdate: Fn(u32) + 'static,
|
||||||
|
{
|
||||||
|
TextEntry::new(
|
||||||
|
"0",
|
||||||
|
value,
|
||||||
|
|v| format!("{}", v),
|
||||||
|
move |v| match v.parse::<u32>() {
|
||||||
|
Ok(val) => {
|
||||||
|
on_update(val);
|
||||||
|
Ok(val)
|
||||||
|
}
|
||||||
|
Err(_) => Err(ParseError),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue