2024-01-02 04:58:55 +00:00
|
|
|
/*
|
|
|
|
Copyright 2023, 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/>.
|
|
|
|
*/
|
|
|
|
|
2024-01-15 18:20:23 +00:00
|
|
|
use crate::components::{EditView, ParseError, Singleton, TextEntry};
|
2024-01-02 04:58:55 +00:00
|
|
|
use chrono::{Local, NaiveDate};
|
|
|
|
use dimensioned::si;
|
2024-01-15 20:53:01 +00:00
|
|
|
use glib::{object::ObjectRef, Object};
|
2024-01-02 04:58:55 +00:00
|
|
|
use gtk::{prelude::*, subclass::prelude::*};
|
2024-01-15 20:53:01 +00:00
|
|
|
use std::{borrow::Borrow, cell::RefCell};
|
2024-01-02 04:58:55 +00:00
|
|
|
|
2024-01-15 20:53:01 +00:00
|
|
|
#[derive(Default)]
|
2024-01-18 03:13:55 +00:00
|
|
|
pub struct WeightViewPrivate {}
|
2024-01-15 20:53:01 +00:00
|
|
|
|
|
|
|
pub struct Weight {
|
|
|
|
label: gtk::Label,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Weight {
|
2024-01-16 04:27:55 +00:00
|
|
|
pub fn new(weight: Option<ft_core::Weight>) -> Self {
|
2024-01-15 20:53:01 +00:00
|
|
|
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()
|
|
|
|
}
|
2024-01-02 04:58:55 +00:00
|
|
|
}
|
2024-01-16 04:27:55 +00:00
|
|
|
|
2024-01-18 03:35:13 +00:00
|
|
|
#[derive(Debug)]
|
2024-01-16 04:27:55 +00:00
|
|
|
pub struct WeightEdit {
|
|
|
|
entry: TextEntry<si::Kilogram<f64>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WeightEdit {
|
|
|
|
pub fn new(weight: Option<ft_core::Weight>) -> Self {
|
|
|
|
Self {
|
|
|
|
entry: TextEntry::new(
|
|
|
|
"0 kg",
|
|
|
|
weight.map(|w| w.weight),
|
|
|
|
|val: &si::Kilogram<f64>| val.to_string(),
|
|
|
|
|v: &str| v.parse::<f64>().map(|w| w * si::KG).map_err(|_| ParseError),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-18 03:35:13 +00:00
|
|
|
pub fn set_value(&self, value: Option<si::Kilogram<f64>>) {
|
|
|
|
self.entry.set_value(value);
|
|
|
|
}
|
|
|
|
|
2024-01-16 04:27:55 +00:00
|
|
|
pub fn value(&self) -> Option<si::Kilogram<f64>> {
|
|
|
|
self.entry.value()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn widget(&self) -> gtk::Widget {
|
|
|
|
self.entry.widget()
|
|
|
|
}
|
|
|
|
}
|