Compare commits
No commits in common. "1e6555ef6187401439d0061f7ff3ec2da85a0d01" and "2d223973824a66a4136da8479011583df880e617" have entirely different histories.
1e6555ef61
...
2d22397382
|
@ -699,7 +699,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dashboard"
|
name = "dashboard"
|
||||||
version = "0.1.2"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
This file is part of FitnessTrax.
|
This file is part of FitnessTrax.
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::App,
|
app::App,
|
||||||
views::{DayDetailView, HistoricalView, PlaceholderView, View, WelcomeView},
|
components::DayDetail,
|
||||||
|
views::{HistoricalView, PlaceholderView, View, WelcomeView},
|
||||||
};
|
};
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use chrono::{Duration, Local};
|
use chrono::{Duration, Local};
|
||||||
|
@ -137,7 +138,18 @@ impl AppWindow {
|
||||||
Rc::new(move |date, records| {
|
Rc::new(move |date, records| {
|
||||||
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||||
layout.append(&adw::HeaderBar::new());
|
layout.append(&adw::HeaderBar::new());
|
||||||
layout.append(&DayDetailView::new(date, records, s.app.clone()));
|
layout.append(&DayDetail::new(
|
||||||
|
date,
|
||||||
|
records,
|
||||||
|
{
|
||||||
|
let s = s.clone();
|
||||||
|
move |record| s.on_put_record(record)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
let s = s.clone();
|
||||||
|
move |record| s.on_update_record(record)
|
||||||
|
},
|
||||||
|
));
|
||||||
let page = &adw::NavigationPage::builder()
|
let page = &adw::NavigationPage::builder()
|
||||||
.title(date.format("%Y-%m-%d").to_string())
|
.title(date.format("%Y-%m-%d").to_string())
|
||||||
.child(&layout)
|
.child(&layout)
|
||||||
|
|
|
@ -16,8 +16,9 @@ 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::components::{TimeDistanceView, Weight};
|
use crate::components::{TimeDistanceView, WeightView};
|
||||||
use emseries::Record;
|
use emseries::Record;
|
||||||
|
use ft_core::{RecordType, TraxRecord, Weight};
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -66,7 +67,7 @@ impl DaySummary {
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<Record<ft_core::TraxRecord>>) {
|
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) {
|
||||||
self.imp()
|
self.imp()
|
||||||
.date
|
.date
|
||||||
.set_text(&date.format("%Y-%m-%d").to_string());
|
.set_text(&date.format("%Y-%m-%d").to_string());
|
||||||
|
@ -76,7 +77,7 @@ impl DaySummary {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(Record {
|
if let Some(Record {
|
||||||
data: ft_core::TraxRecord::Weight(weight_record),
|
data: TraxRecord::Weight(weight_record),
|
||||||
..
|
..
|
||||||
}) = records.iter().filter(|f| f.data.is_weight()).next()
|
}) = records.iter().filter(|f| f.data.is_weight()).next()
|
||||||
{
|
{
|
||||||
|
@ -100,33 +101,6 @@ impl DaySummary {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct CommandRowPrivate;
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for CommandRowPrivate {
|
|
||||||
const NAME: &'static str = "DayDetailCommandRow";
|
|
||||||
type Type = CommandRow;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for CommandRowPrivate {}
|
|
||||||
impl WidgetImpl for CommandRowPrivate {}
|
|
||||||
impl BoxImpl for CommandRowPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
struct CommandRow(ObjectSubclass<CommandRowPrivate>) @extends gtk::Box, gtk::Widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandRow {
|
|
||||||
fn new() -> Self {
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
s.set_halign(gtk::Align::End);
|
|
||||||
s.append(>k::Button::builder().label("Edit").build());
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DayDetailPrivate {
|
pub struct DayDetailPrivate {
|
||||||
date: gtk::Label,
|
date: gtk::Label,
|
||||||
weight: RefCell<Option<gtk::Label>>,
|
weight: RefCell<Option<gtk::Label>>,
|
||||||
|
@ -161,21 +135,17 @@ glib::wrapper! {
|
||||||
impl DayDetail {
|
impl DayDetail {
|
||||||
pub fn new<PutRecordFn, UpdateRecordFn>(
|
pub fn new<PutRecordFn, UpdateRecordFn>(
|
||||||
date: chrono::NaiveDate,
|
date: chrono::NaiveDate,
|
||||||
records: Vec<Record<ft_core::TraxRecord>>,
|
records: Vec<Record<TraxRecord>>,
|
||||||
on_put_record: PutRecordFn,
|
on_put_record: PutRecordFn,
|
||||||
on_update_record: UpdateRecordFn,
|
on_update_record: UpdateRecordFn,
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
PutRecordFn: Fn(ft_core::TraxRecord) + 'static,
|
PutRecordFn: Fn(TraxRecord) + 'static,
|
||||||
UpdateRecordFn: Fn(Record<ft_core::TraxRecord>) + 'static,
|
UpdateRecordFn: Fn(Record<TraxRecord>) + 'static,
|
||||||
{
|
{
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
s.set_hexpand(true);
|
|
||||||
|
|
||||||
s.append(&CommandRow::new());
|
|
||||||
|
|
||||||
/*
|
|
||||||
let click_controller = gtk::GestureClick::new();
|
let click_controller = gtk::GestureClick::new();
|
||||||
click_controller.connect_released({
|
click_controller.connect_released({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
|
@ -188,65 +158,52 @@ impl DayDetail {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
s.add_controller(click_controller);
|
s.add_controller(click_controller);
|
||||||
*/
|
|
||||||
|
|
||||||
let weight_record = records.iter().find_map(|record| match record {
|
let weight_record = records.iter().find_map(|record| match record {
|
||||||
Record {
|
Record {
|
||||||
id,
|
id,
|
||||||
data: ft_core::TraxRecord::Weight(record),
|
data: TraxRecord::Weight(record),
|
||||||
} => Some((id.clone(), record.clone())),
|
} => Some((id.clone(), record.clone())),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let weight_view = match weight_record {
|
let weight_view = match weight_record {
|
||||||
Some((id, data)) => Weight::new(Some(data.clone()), move |weight| {
|
Some((id, data)) => WeightView::new(date.clone(), Some(data.clone()), move |weight| {
|
||||||
on_update_record(Record {
|
on_update_record(Record {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
data: ft_core::TraxRecord::Weight(ft_core::Weight { date, weight }),
|
data: TraxRecord::Weight(Weight { date, weight }),
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
None => Weight::new(None, move |weight| {
|
None => WeightView::new(date.clone(), None, move |weight| {
|
||||||
on_put_record(ft_core::TraxRecord::Weight(ft_core::Weight {
|
on_put_record(TraxRecord::Weight(Weight { date, weight }));
|
||||||
date,
|
|
||||||
weight,
|
|
||||||
}));
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
s.append(&weight_view.widget());
|
s.append(&weight_view);
|
||||||
|
|
||||||
records.into_iter().for_each(|record| {
|
records.into_iter().for_each(|record| {
|
||||||
let record_view = match record {
|
let record_view = match record {
|
||||||
Record {
|
Record {
|
||||||
data: ft_core::TraxRecord::BikeRide(record),
|
data: TraxRecord::BikeRide(record),
|
||||||
..
|
..
|
||||||
} => Some(
|
} => Some(
|
||||||
TimeDistanceView::new(ft_core::RecordType::BikeRide, record)
|
TimeDistanceView::new(RecordType::BikeRide, record).upcast::<gtk::Widget>(),
|
||||||
.upcast::<gtk::Widget>(),
|
|
||||||
),
|
),
|
||||||
Record {
|
Record {
|
||||||
data: ft_core::TraxRecord::Row(record),
|
data: TraxRecord::Row(record),
|
||||||
..
|
..
|
||||||
} => Some(
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
|
||||||
),
|
|
||||||
Record {
|
Record {
|
||||||
data: ft_core::TraxRecord::Run(record),
|
data: TraxRecord::Run(record),
|
||||||
..
|
..
|
||||||
} => Some(
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
|
||||||
),
|
|
||||||
Record {
|
Record {
|
||||||
data: ft_core::TraxRecord::Swim(record),
|
data: TraxRecord::Swim(record),
|
||||||
..
|
..
|
||||||
} => Some(
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
|
||||||
),
|
|
||||||
Record {
|
Record {
|
||||||
data: ft_core::TraxRecord::Walk(record),
|
data: TraxRecord::Walk(record),
|
||||||
..
|
..
|
||||||
} => Some(
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
|
||||||
),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
This file is part of FitnessTrax.
|
This file is part of FitnessTrax.
|
||||||
|
|
||||||
|
@ -20,9 +20,6 @@ pub use day::{DayDetail, DaySummary};
|
||||||
mod edit_view;
|
mod edit_view;
|
||||||
pub use edit_view::EditView;
|
pub use edit_view::EditView;
|
||||||
|
|
||||||
mod singleton;
|
|
||||||
pub use singleton::{Singleton, SingletonImpl};
|
|
||||||
|
|
||||||
mod text_entry;
|
mod text_entry;
|
||||||
pub use text_entry::{ParseError, TextEntry};
|
pub use text_entry::{ParseError, TextEntry};
|
||||||
|
|
||||||
|
@ -30,7 +27,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::WeightView;
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//! A Widget container for a single components
|
|
||||||
use glib::Object;
|
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
pub struct SingletonPrivate {
|
|
||||||
widget: RefCell<gtk::Widget>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for SingletonPrivate {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
widget: RefCell::new(gtk::Label::new(None).upcast()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for SingletonPrivate {
|
|
||||||
const NAME: &'static str = "Singleton";
|
|
||||||
type Type = Singleton;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for SingletonPrivate {}
|
|
||||||
impl WidgetImpl for SingletonPrivate {}
|
|
||||||
impl BoxImpl for SingletonPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
/// The Singleton component contains exactly one child widget. The swap function makes it easy
|
|
||||||
/// to handle the job of swapping that child out for a different one.
|
|
||||||
pub struct Singleton(ObjectSubclass<SingletonPrivate>) @extends gtk::Box, gtk::Widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Singleton {
|
|
||||||
fn default() -> Self {
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
|
|
||||||
s.append(&*s.imp().widget.borrow());
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Singleton {
|
|
||||||
pub fn swap(&self, new_widget: &impl IsA<gtk::Widget>) {
|
|
||||||
let new_widget = new_widget.clone().upcast();
|
|
||||||
self.remove(&*self.imp().widget.borrow());
|
|
||||||
self.append(&new_widget);
|
|
||||||
*self.imp().widget.borrow_mut() = new_widget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait SingletonImpl: WidgetImpl + BoxImpl {}
|
|
||||||
unsafe impl<T: SingletonImpl> IsSubclassable<T> for Singleton {}
|
|
|
@ -24,12 +24,12 @@ pub struct TextEntry<T: Clone> {
|
||||||
value: Rc<RefCell<Option<T>>>,
|
value: Rc<RefCell<Option<T>>>,
|
||||||
widget: gtk::Entry,
|
widget: gtk::Entry,
|
||||||
renderer: Rc<Box<dyn Fn(&T) -> String>>,
|
renderer: Rc<Box<dyn Fn(&T) -> String>>,
|
||||||
parser: Rc<Box<dyn Fn(&str) -> Result<T, ParseError>>>,
|
validator: Rc<Box<dyn Fn(&str) -> Result<T, ParseError>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// I do not understand why the data should be 'static.
|
// I do not understand why the data should be 'static.
|
||||||
impl<T: Clone + 'static> TextEntry<T> {
|
impl<T: Clone + 'static> TextEntry<T> {
|
||||||
pub fn new<R, V>(placeholder: &str, value: Option<T>, renderer: R, parser: V) -> Self
|
pub fn new<R, V>(placeholder: &str, value: Option<T>, renderer: R, validator: V) -> Self
|
||||||
where
|
where
|
||||||
R: Fn(&T) -> String + 'static,
|
R: Fn(&T) -> String + 'static,
|
||||||
V: Fn(&str) -> Result<T, ParseError> + 'static,
|
V: Fn(&str) -> Result<T, ParseError> + 'static,
|
||||||
|
@ -44,7 +44,7 @@ impl<T: Clone + 'static> TextEntry<T> {
|
||||||
value: Rc::new(RefCell::new(value)),
|
value: Rc::new(RefCell::new(value)),
|
||||||
widget,
|
widget,
|
||||||
renderer: Rc::new(Box::new(renderer)),
|
renderer: Rc::new(Box::new(renderer)),
|
||||||
parser: Rc::new(Box::new(parser)),
|
validator: Rc::new(Box::new(validator)),
|
||||||
};
|
};
|
||||||
|
|
||||||
s.widget.buffer().connect_text_notify({
|
s.widget.buffer().connect_text_notify({
|
||||||
|
@ -61,7 +61,7 @@ impl<T: Clone + 'static> TextEntry<T> {
|
||||||
self.widget.remove_css_class("error");
|
self.widget.remove_css_class("error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match (self.parser)(buffer.text().as_str()) {
|
match (self.validator)(buffer.text().as_str()) {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
*self.value.borrow_mut() = Some(v);
|
*self.value.borrow_mut() = Some(v);
|
||||||
self.widget.remove_css_class("error");
|
self.widget.remove_css_class("error");
|
||||||
|
|
|
@ -14,53 +14,47 @@ 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/>.
|
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::{EditView, ParseError, Singleton, TextEntry};
|
use crate::components::{EditView, ParseError, TextEntry};
|
||||||
use chrono::{Local, NaiveDate};
|
use chrono::{Local, NaiveDate};
|
||||||
use dimensioned::si;
|
use dimensioned::si;
|
||||||
use glib::{object::ObjectRef, Object};
|
use ft_core::Weight;
|
||||||
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::{borrow::Borrow, cell::RefCell};
|
use std::cell::RefCell;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct WeightViewPrivate {
|
pub struct WeightViewPrivate {
|
||||||
/*
|
|
||||||
date: RefCell<NaiveDate>,
|
date: RefCell<NaiveDate>,
|
||||||
record: RefCell<Option<Weight>>,
|
record: RefCell<Option<Weight>>,
|
||||||
|
|
||||||
widget: RefCell<EditView<gtk::Label, TextEntry<si::Kilogram<f64>>>>,
|
widget: RefCell<EditView<gtk::Label, TextEntry<si::Kilogram<f64>>>>,
|
||||||
|
|
||||||
on_edit_finished: RefCell<Box<dyn Fn(si::Kilogram<f64>)>>,
|
on_edit_finished: RefCell<Box<dyn Fn(si::Kilogram<f64>)>>,
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
impl Default for WeightViewPrivate {
|
impl Default for WeightViewPrivate {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
date: RefCell::new(Local::now().date_naive()),
|
date: RefCell::new(Local::now().date_naive()),
|
||||||
record: RefCell::new(None),
|
record: RefCell::new(None),
|
||||||
widget: RefCell::new(EditView::Unconfigured),
|
widget: RefCell::new(EditView::Unconfigured),
|
||||||
container: Singleton::default(),
|
|
||||||
on_edit_finished: RefCell::new(Box::new(|_| {})),
|
on_edit_finished: RefCell::new(Box::new(|_| {})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
impl ObjectSubclass for WeightViewPrivate {
|
impl ObjectSubclass for WeightViewPrivate {
|
||||||
const NAME: &'static str = "WeightView";
|
const NAME: &'static str = "WeightView";
|
||||||
type Type = WeightView;
|
type Type = WeightView;
|
||||||
type ParentType = gtk::Label;
|
type ParentType = gtk::Box;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectImpl for WeightViewPrivate {}
|
impl ObjectImpl for WeightViewPrivate {}
|
||||||
impl WidgetImpl for WeightViewPrivate {}
|
impl WidgetImpl for WeightViewPrivate {}
|
||||||
impl LabelImpl for WeightViewPrivate {}
|
impl BoxImpl for WeightViewPrivate {}
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct WeightView(ObjectSubclass<WeightViewPrivate>) @extends gtk::Label, gtk::Widget;
|
pub struct WeightView(ObjectSubclass<WeightViewPrivate>) @extends gtk::Box, gtk::Widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WeightView {
|
impl WeightView {
|
||||||
|
@ -73,33 +67,16 @@ impl WeightView {
|
||||||
OnEditFinished: Fn(si::Kilogram<f64>) + 'static,
|
OnEditFinished: Fn(si::Kilogram<f64>) + 'static,
|
||||||
{
|
{
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
s.set_css_classes(&["card", "weight-view"]);
|
|
||||||
s.set_can_focus(true);
|
|
||||||
|
|
||||||
s.append(&s.imp().container);
|
|
||||||
|
|
||||||
match weight {
|
|
||||||
Some(weight) => {
|
|
||||||
s.remove_css_class("dim_label");
|
|
||||||
s.set_label(&format!("{:?}", weight));
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
s.add_css_class("dim_label");
|
|
||||||
s.set_label("No weight recorded");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
*s.imp().on_edit_finished.borrow_mut() = Box::new(on_edit_finished);
|
*s.imp().on_edit_finished.borrow_mut() = Box::new(on_edit_finished);
|
||||||
*s.imp().date.borrow_mut() = date;
|
*s.imp().date.borrow_mut() = date;
|
||||||
|
|
||||||
*s.imp().record.borrow_mut() = weight;
|
*s.imp().record.borrow_mut() = weight;
|
||||||
s.view();
|
s.view();
|
||||||
*/
|
|
||||||
|
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
fn view(&self) {
|
fn view(&self) {
|
||||||
let view = gtk::Label::builder()
|
let view = gtk::Label::builder()
|
||||||
.css_classes(["card", "weight-view"])
|
.css_classes(["card", "weight-view"])
|
||||||
|
@ -128,7 +105,7 @@ impl WeightView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// self.swap(EditView::View(view));
|
self.swap(EditView::View(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit(&self) {
|
fn edit(&self) {
|
||||||
|
@ -144,19 +121,11 @@ impl WeightView {
|
||||||
None => edit.set_value(None),
|
None => edit.set_value(None),
|
||||||
}
|
}
|
||||||
|
|
||||||
// self.swap(EditView::Edit(edit.clone()));
|
self.swap(EditView::Edit(edit.clone()));
|
||||||
edit.grab_focus();
|
edit.grab_focus();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
fn swap(&self, new_view: EditView<gtk::Label, TextEntry<si::Kilogram<f64>>>) {
|
fn swap(&self, new_view: EditView<gtk::Label, TextEntry<si::Kilogram<f64>>>) {
|
||||||
match new_view {
|
|
||||||
EditView::Unconfigured => {}
|
|
||||||
EditView::View(view) => self.imp().container.swap(&view.upcast()),
|
|
||||||
EditView::Edit(editor) => self.imp().container.swap(&editor.widget()),
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
let mut widget = self.imp().widget.borrow_mut();
|
let mut widget = self.imp().widget.borrow_mut();
|
||||||
match *widget {
|
match *widget {
|
||||||
EditView::Unconfigured => {}
|
EditView::Unconfigured => {}
|
||||||
|
@ -170,11 +139,8 @@ impl WeightView {
|
||||||
EditView::Edit(ref editor) => self.append(&editor.widget()),
|
EditView::Edit(ref editor) => self.append(&editor.widget()),
|
||||||
}
|
}
|
||||||
*widget = new_view;
|
*widget = new_view;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
pub fn blur(&self) {
|
pub fn blur(&self) {
|
||||||
match *self.imp().widget.borrow() {
|
match *self.imp().widget.borrow() {
|
||||||
EditView::Unconfigured => {}
|
EditView::Unconfigured => {}
|
||||||
|
@ -217,36 +183,4 @@ impl WeightView {
|
||||||
|
|
||||||
self.view();
|
self.view();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub struct Weight {
|
|
||||||
label: gtk::Label,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Weight {
|
|
||||||
pub fn new<OnEditFinished>(
|
|
||||||
weight: Option<ft_core::Weight>,
|
|
||||||
on_edit_finished: OnEditFinished,
|
|
||||||
) -> Self
|
|
||||||
where
|
|
||||||
OnEditFinished: Fn(si::Kilogram<f64>) + 'static,
|
|
||||||
{
|
|
||||||
let label = gtk::Label::builder()
|
|
||||||
.css_classes(["card", "weight-view"])
|
|
||||||
.can_focus(true)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
match weight {
|
|
||||||
Some(w) => label.set_text(&format!("{:?}", w.weight)),
|
|
||||||
None => label.set_text("No weight recorded"),
|
|
||||||
}
|
|
||||||
|
|
||||||
Self { label }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn widget(&self) -> gtk::Widget {
|
|
||||||
self.label.clone().upcast()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
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::{
|
|
||||||
app::App,
|
|
||||||
components::{DayDetail, Singleton, SingletonImpl},
|
|
||||||
};
|
|
||||||
use emseries::Record;
|
|
||||||
use ft_core::TraxRecord;
|
|
||||||
use glib::Object;
|
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct DayDetailViewPrivate {
|
|
||||||
container: Singleton,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for DayDetailViewPrivate {
|
|
||||||
const NAME: &'static str = "DayDetailView";
|
|
||||||
type Type = DayDetailView;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for DayDetailViewPrivate {}
|
|
||||||
impl WidgetImpl for DayDetailViewPrivate {}
|
|
||||||
impl BoxImpl for DayDetailViewPrivate {}
|
|
||||||
impl SingletonImpl for DayDetailViewPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct DayDetailView(ObjectSubclass<DayDetailViewPrivate>) @extends gtk::Box, gtk::Widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DayDetailView {
|
|
||||||
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>, app: App) -> Self {
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
|
|
||||||
s.append(&s.imp().container);
|
|
||||||
|
|
||||||
s.imp().container.swap(&DayDetail::new(
|
|
||||||
date,
|
|
||||||
records,
|
|
||||||
{
|
|
||||||
let app = app.clone();
|
|
||||||
move |record| {
|
|
||||||
let app = app.clone();
|
|
||||||
glib::spawn_future_local({
|
|
||||||
async move {
|
|
||||||
app.put_record(record).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
let app = app.clone();
|
|
||||||
move |record| {
|
|
||||||
let app = app.clone();
|
|
||||||
glib::spawn_future_local({
|
|
||||||
async move {
|
|
||||||
app.update_record(record).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
));
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,9 +16,6 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
||||||
mod day_detail_view;
|
|
||||||
pub use day_detail_view::DayDetailView;
|
|
||||||
|
|
||||||
mod historical_view;
|
mod historical_view;
|
||||||
pub use historical_view::HistoricalView;
|
pub use historical_view::HistoricalView;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue