From af1422d523c95e16b7972adca813a0cfee6d1eba Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Fri, 26 Jan 2024 09:53:42 -0500 Subject: [PATCH] Build some convenienc functions for measurement entry fields Move the weight field into text_entry --- fitnesstrax/app/src/components/mod.rs | 2 +- .../app/src/components/time_distance.rs | 52 ++++++++++++++++++- fitnesstrax/app/src/components/weight.rs | 4 +- fitnesstrax/app/src/views/historical_view.rs | 5 +- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/fitnesstrax/app/src/components/mod.rs b/fitnesstrax/app/src/components/mod.rs index 792db09..59f7347 100644 --- a/fitnesstrax/app/src/components/mod.rs +++ b/fitnesstrax/app/src/components/mod.rs @@ -27,7 +27,7 @@ mod steps; pub use steps::{steps_editor, Steps}; mod text_entry; -pub use text_entry::{weight_field, TextEntry}; +pub use text_entry::{distance_field, duration_field, time_field, weight_field, TextEntry}; mod time_distance; pub use time_distance::{time_distance_detail, time_distance_summary}; diff --git a/fitnesstrax/app/src/components/time_distance.rs b/fitnesstrax/app/src/components/time_distance.rs index 1ff3ba2..3771556 100644 --- a/fitnesstrax/app/src/components/time_distance.rs +++ b/fitnesstrax/app/src/components/time_distance.rs @@ -18,7 +18,9 @@ You should have received a copy of the GNU General Public License along with Fit // use chrono::{Local, NaiveDate}; // use dimensioned::si; use dimensioned::si; -use gtk::prelude::*; +use glib::Object; +use gtk::{prelude::*, subclass::prelude::*}; +use std::cell::RefCell; pub fn time_distance_summary( distance: si::Meter, @@ -99,5 +101,53 @@ pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box { ) .build(), ); + layout } + +#[derive(Default)] +pub struct TimeDistanceEditPrivate { + #[allow(unused)] + record: RefCell>, +} + +#[glib::object_subclass] +impl ObjectSubclass for TimeDistanceEditPrivate { + const NAME: &'static str = "TimeDistanceEdit"; + type Type = TimeDistanceEdit; + type ParentType = gtk::Box; +} + +impl ObjectImpl for TimeDistanceEditPrivate {} +impl WidgetImpl for TimeDistanceEditPrivate {} +impl BoxImpl for TimeDistanceEditPrivate {} + +glib::wrapper! { + pub struct TimeDistanceEdit(ObjectSubclass) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; +} + +impl Default for TimeDistanceEdit { + fn default() -> Self { + let s: Self = Object::builder().build(); + s.set_orientation(gtk::Orientation::Horizontal); + s.set_css_classes(&["time-distance-edit"]); + + s + } +} + +impl TimeDistanceEdit { + #[allow(unused)] + fn empty(_on_update: OnUpdate) -> Self + where + OnUpdate: Fn(&ft_core::TimeDistance), + { + Self::default() + } + + /* + fn with_record(type_: ft_core::RecordType, record: ft_core::TimeDistance, on_update: OnUpdate) -> Self + where OnUpdate: Fn(&ft_core::RecordType, &ft_core::TimeDistance) { + } + */ +} diff --git a/fitnesstrax/app/src/components/weight.rs b/fitnesstrax/app/src/components/weight.rs index 615f3f2..2f17c82 100644 --- a/fitnesstrax/app/src/components/weight.rs +++ b/fitnesstrax/app/src/components/weight.rs @@ -14,9 +14,7 @@ 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::{FormatOption, WeightFormatter}, -}; +use crate::types::{FormatOption, WeightFormatter}; use gtk::prelude::*; pub struct WeightLabel { diff --git a/fitnesstrax/app/src/views/historical_view.rs b/fitnesstrax/app/src/views/historical_view.rs index acbf44b..46fbab6 100644 --- a/fitnesstrax/app/src/views/historical_view.rs +++ b/fitnesstrax/app/src/views/historical_view.rs @@ -56,6 +56,7 @@ impl ObjectSubclass for HistoricalViewPrivate { .single_click_activate(true) .build(), }; + factory.connect_bind({ let app = s.app.clone(); move |_, list_item| { @@ -119,9 +120,7 @@ impl HistoricalView { s.imp().list_view.connect_activate({ let on_select_day = on_select_day.clone(); move |s, idx| { - // This gets triggered whenever the user clicks on an item on the list. What we - // actually want to do here is to open a modal dialog that shows all of the details of - // the day and which allows the user to edit items within that dialog. + // This gets triggered whenever the user clicks on an item on the list. let item = s.model().unwrap().item(idx).unwrap(); let date = item.downcast_ref::().unwrap(); on_select_day(date.date());