Compare commits

..

No commits in common. "9e7350b08713a66c2e5e4cb6214aae742b65e7e8" and "55b6327d423012f6d23dd6e0bd03a28706c2e48e" have entirely different histories.

10 changed files with 52 additions and 208 deletions

View File

@ -3,7 +3,7 @@
} }
.welcome__title { .welcome__title {
font-size: x-large; font-size: larger;
padding: 8px; padding: 8px;
} }
@ -11,55 +11,20 @@
padding: 8px; padding: 8px;
} }
.welcome__footer {}
.historical { .historical {
margin: 32px; margin: 32px;
border-radius: 8px; border-radius: 8px;
} }
.date-range-picker {
margin-bottom: 16px;
}
/*
.date-range-picker > box:not(:last-child) {
margin-bottom: 8px;
}
*/
.date-range-picker__date-field {
margin: 8px;
}
.date-range-picker__search-button {
margin: 8px;
}
.date-range-picker__range-button {
margin: 8px;
}
.date-field__year {
margin: 0px 4px 0px 0px;
}
.date-field__month {
margin: 0px 4px 0px 4px;
}
.date-field__day {
margin: 0px 0px 0px 4px;
}
.day-summary { .day-summary {
padding: 8px; padding: 8px;
} }
.day-summary > *:not(:last-child) {
margin-bottom: 8px;
}
.day-summary__date { .day-summary__date {
font-size: x-large; font-size: larger;
margin-bottom: 8px;
} }
.day-summary__weight { .day-summary__weight {
@ -74,12 +39,4 @@
.step-view { .step-view {
padding: 8px; padding: 8px;
margin: 8px; margin: 8px;
}
.about__content {
padding: 32px;
}
.about label {
margin-bottom: 16px;
} }

View File

@ -1,80 +0,0 @@
/*
Copyright 2023 - 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 glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
#[derive(Default)]
pub struct AboutWindowPrivate {}
#[glib::object_subclass]
impl ObjectSubclass for AboutWindowPrivate {
const NAME: &'static str = "AboutWindow";
type Type = AboutWindow;
type ParentType = gtk::Window;
}
impl ObjectImpl for AboutWindowPrivate {}
impl WidgetImpl for AboutWindowPrivate {}
impl WindowImpl for AboutWindowPrivate {}
glib::wrapper! {
pub struct AboutWindow(ObjectSubclass<AboutWindowPrivate>) @extends gtk::Window, gtk::Widget;
}
impl Default for AboutWindow {
fn default() -> Self {
let s: Self = Object::builder().build();
s.set_width_request(600);
s.set_height_request(700);
s.add_css_class("about");
s.set_title(Some("About Fitnesstrax"));
let copyright = gtk::Label::builder()
.label("Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>")
.halign(gtk::Align::Start)
.build();
let gtk_rs_thanks = gtk::Label::builder()
.label("I owe a huge debt of gratitude to the GTK-RS project (https://gtk-rs.org/), which makes it possible for me to write this application to begin with. Further, I owe a particular debt to Julian Hofer and his book, GUI development with Rust and GTK 4 (https://gtk-rs.org/gtk4-rs/stable/latest/book/). Without this book, I would have continued to stumble around writing bad user interfaces with even worse code.")
.halign(gtk::Align::Start).wrap(true)
.build();
let dependencies = gtk::Label::builder()
.label("This application depends on many libraries, most of which are licensed under the BSD-3 or GPL-3 licenses.")
.halign(gtk::Align::Start).wrap(true)
.build();
let content = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.css_classes(["about__content"])
.build();
content.append(&copyright);
content.append(&gtk_rs_thanks);
content.append(&dependencies);
let scroller = gtk::ScrolledWindow::builder()
.child(&content)
.hexpand(true)
.vexpand(true)
.hscrollbar_policy(gtk::PolicyType::Never)
.build();
s.set_child(Some(&scroller));
s
}
}

View File

@ -89,7 +89,6 @@ impl AppWindow {
let header_bar = adw::HeaderBar::new(); let header_bar = adw::HeaderBar::new();
let main_menu = gio::Menu::new(); let main_menu = gio::Menu::new();
main_menu.append(Some("About"), Some("app.about"));
main_menu.append(Some("Quit"), Some("app.quit")); main_menu.append(Some("Quit"), Some("app.quit"));
let main_menu_button = gtk::MenuButton::builder() let main_menu_button = gtk::MenuButton::builder()
.icon_name("open-menu") .icon_name("open-menu")

View File

@ -113,12 +113,11 @@ glib::wrapper! {
impl DateField { impl DateField {
pub fn new(date: chrono::NaiveDate) -> Self { pub fn new(date: chrono::NaiveDate) -> Self {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.add_css_class("date-field");
println!("{}", date);
s.append(&s.imp().year.widget()); s.append(&s.imp().year.widget());
s.append(&gtk::Label::new(Some("-")));
s.append(&s.imp().month.widget()); s.append(&s.imp().month.widget());
s.append(&gtk::Label::new(Some("-")));
s.append(&s.imp().day.widget()); s.append(&s.imp().day.widget());
s.set_date(date); s.set_date(date);
@ -147,7 +146,7 @@ impl DateField {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
// use crate::gtk_init::gtk_init; use crate::gtk_init::gtk_init;
// Enabling this test pushes tests on the TextField into an infinite loop. That likely indicates a bad interaction within the TextField itself, and that is going to need to be fixed. // Enabling this test pushes tests on the TextField into an infinite loop. That likely indicates a bad interaction within the TextField itself, and that is going to need to be fixed.
#[test] #[test]

View File

@ -14,11 +14,14 @@ 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::DateField, types::DayInterval}; use crate::{
components::{DateField},
types::DayInterval,
};
use chrono::{Duration, Local, Months}; use chrono::{Duration, Local, Months};
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell; use std::{cell::RefCell};
type OnSearch = dyn Fn(DayInterval) + 'static; type OnSearch = dyn Fn(DayInterval) + 'static;
@ -37,14 +40,9 @@ impl ObjectSubclass for DateRangePickerPrivate {
fn new() -> Self { fn new() -> Self {
let default_date = Local::now().date_naive(); let default_date = Local::now().date_naive();
let start = DateField::new(default_date);
start.add_css_class("date-range-picker__date-field");
let end = DateField::new(default_date);
end.add_css_class("date-range-picker__date-field");
Self { Self {
start, start: DateField::new(default_date),
end, end: DateField::new(default_date),
on_search: RefCell::new(Box::new(|_| {})), on_search: RefCell::new(Box::new(|_| {})),
} }
} }
@ -58,6 +56,7 @@ glib::wrapper! {
pub struct DateRangePicker(ObjectSubclass<DateRangePickerPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; pub struct DateRangePicker(ObjectSubclass<DateRangePickerPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
} }
impl DateRangePicker { impl DateRangePicker {
pub fn connect_on_search<OnSearch>(&self, f: OnSearch) pub fn connect_on_search<OnSearch>(&self, f: OnSearch)
where where
@ -66,12 +65,12 @@ impl DateRangePicker {
*self.imp().on_search.borrow_mut() = Box::new(f); *self.imp().on_search.borrow_mut() = Box::new(f);
} }
pub fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) { fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) {
self.imp().start.set_date(start); self.imp().start.set_date(start);
self.imp().end.set_date(end); self.imp().end.set_date(end);
} }
pub fn interval(&self) -> DayInterval { fn interval(&self) -> DayInterval {
DayInterval { DayInterval {
start: self.imp().start.date(), start: self.imp().start.date(),
end: self.imp().end.date(), end: self.imp().end.date(),
@ -79,25 +78,19 @@ impl DateRangePicker {
} }
} }
impl Default for DateRangePicker { impl Default for DateRangePicker {
fn default() -> Self { fn default() -> Self {
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.add_css_class("date-range-picker");
let search_button = gtk::Button::builder() let search_button = gtk::Button::with_label("Search");
.css_classes(["date-range-picker__search-button"])
.label("Search")
.build();
search_button.connect_clicked({ search_button.connect_clicked({
let s = s.clone(); let s = s.clone();
move |_| (s.imp().on_search.borrow())(s.interval()) move |_| (s.imp().on_search.borrow())(s.interval())
}); });
let last_week_button = gtk::Button::builder() let last_week_button = gtk::Button::builder().label("last week").build();
.css_classes(["date-range-picker__range-button"])
.label("week")
.build();
last_week_button.connect_clicked({ last_week_button.connect_clicked({
let s = s.clone(); let s = s.clone();
move |_| { move |_| {
@ -108,10 +101,7 @@ impl Default for DateRangePicker {
} }
}); });
let two_weeks_button = gtk::Button::builder() let two_weeks_button = gtk::Button::builder().label("last two weeks").build();
.css_classes(["date-range-picker__range-button"])
.label("two weeks")
.build();
two_weeks_button.connect_clicked({ two_weeks_button.connect_clicked({
let s = s.clone(); let s = s.clone();
move |_| { move |_| {
@ -122,10 +112,7 @@ impl Default for DateRangePicker {
} }
}); });
let last_month_button = gtk::Button::builder() let last_month_button = gtk::Button::builder().label("last month").build();
.css_classes(["date-range-picker__range-button"])
.label("month")
.build();
last_month_button.connect_clicked({ last_month_button.connect_clicked({
let s = s.clone(); let s = s.clone();
move |_| { move |_| {
@ -136,10 +123,7 @@ impl Default for DateRangePicker {
} }
}); });
let six_months_button = gtk::Button::builder() let six_months_button = gtk::Button::builder().label("last six months").build();
.css_classes(["date-range-picker__range-button"])
.label("six months")
.build();
six_months_button.connect_clicked({ six_months_button.connect_clicked({
let s = s.clone(); let s = s.clone();
move |_| { move |_| {
@ -150,10 +134,7 @@ impl Default for DateRangePicker {
} }
}); });
let last_year_button = gtk::Button::builder() let last_year_button = gtk::Button::builder().label("last year").build();
.css_classes(["date-range-picker__range-button"])
.label("year")
.build();
last_year_button.connect_clicked({ last_year_button.connect_clicked({
let s = s.clone(); let s = s.clone();
move |_| { move |_| {

View File

@ -84,24 +84,25 @@ impl DaySummary {
let row = gtk::Box::builder().build(); let row = gtk::Box::builder().build();
let weight_label = gtk::Label::builder() let label = gtk::Label::builder()
.halign(gtk::Align::Start) .halign(gtk::Align::Start)
.css_classes(["day-summary__weight"]) .css_classes(["day-summary__weight"])
.build(); .build();
if let Some(w) = view_model.weight() { if let Some(w) = view_model.weight() {
weight_label.set_label(&w.to_string()) label.set_label(&w.to_string())
} }
row.append(&label);
let steps_label = gtk::Label::builder() self.append(&label);
let label = gtk::Label::builder()
.halign(gtk::Align::Start) .halign(gtk::Align::Start)
.css_classes(["day-summary__steps"]) .css_classes(["day-summary__weight"])
.build(); .build();
if let Some(s) = view_model.steps() { if let Some(s) = view_model.steps() {
steps_label.set_label(&format!("{} steps", s)); label.set_label(&format!("{} steps", s));
} }
row.append(&label);
row.append(&weight_label);
row.append(&steps_label);
self.append(&row); self.append(&row);
for activity in TIME_DISTANCE_ACTIVITIES { for activity in TIME_DISTANCE_ACTIVITIES {

View File

@ -49,7 +49,7 @@ pub fn time_distance_summary(
(false, false) => None, (false, false) => None,
}; };
text.map(|text| gtk::Label::builder().halign(gtk::Align::Start).label(&text).build()) text.map(|text| gtk::Label::new(Some(&text)))
} }
pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box { pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box {

View File

@ -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.
@ -14,7 +14,6 @@ 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/>.
*/ */
mod about;
mod app; mod app;
mod app_window; mod app_window;
mod components; mod components;
@ -34,15 +33,6 @@ const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/"; const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/";
fn setup_app_about_action(app: &adw::Application) {
let action = ActionEntry::builder("about")
.activate(|app: &adw::Application, _, _| {
let window = about::AboutWindow::default();
window.present();
}).build();
app.add_action_entries([action]);
}
/// Sets up an application-global action, `app.quit`, which will terminate the application. /// Sets up an application-global action, `app.quit`, which will terminate the application.
fn setup_app_close_action(app: &adw::Application) { fn setup_app_close_action(app: &adw::Application) {
let action = ActionEntry::builder("quit") let action = ActionEntry::builder("quit")
@ -90,7 +80,6 @@ fn main() {
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap()); let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions")); icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions"));
setup_app_about_action(adw_app);
setup_app_close_action(adw_app); setup_app_close_action(adw_app);
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone()); AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());

View File

@ -79,12 +79,12 @@ impl TimeFormatter {
match parts.len() { match parts.len() {
0 => Err(ParseError), 0 => Err(ParseError),
1 => Err(ParseError), 1 => Err(ParseError),
2 => chrono::NaiveTime::from_hms_opt(parts[0], parts[1], 0) 2 => Ok(TimeFormatter(
.map(|v| TimeFormatter(v)) chrono::NaiveTime::from_hms_opt(parts[0], parts[1], 0).unwrap(),
.ok_or(ParseError), )),
3 => chrono::NaiveTime::from_hms_opt(parts[0], parts[1], parts[2]) 3 => Ok(TimeFormatter(
.map(|v| TimeFormatter(v)) chrono::NaiveTime::from_hms_opt(parts[0], parts[1], parts[2]).unwrap(),
.ok_or(ParseError), )),
_ => Err(ParseError), _ => Err(ParseError),
} }
} }

View File

@ -30,7 +30,6 @@ use std::{cell::RefCell, rc::Rc};
pub struct HistoricalViewPrivate { pub struct HistoricalViewPrivate {
app: Rc<RefCell<Option<App>>>, app: Rc<RefCell<Option<App>>>,
list_view: gtk::ListView, list_view: gtk::ListView,
date_range_picker: DateRangePicker,
} }
#[glib::object_subclass] #[glib::object_subclass]
@ -48,16 +47,12 @@ impl ObjectSubclass for HistoricalViewPrivate {
.set_child(Some(&DaySummary::new())); .set_child(Some(&DaySummary::new()));
}); });
let date_range_picker = DateRangePicker::default();
let s = Self { let s = Self {
app: Rc::new(RefCell::new(None)), app: Rc::new(RefCell::new(None)),
list_view: gtk::ListView::builder() list_view: gtk::ListView::builder()
.factory(&factory) .factory(&factory)
.single_click_activate(true) .single_click_activate(true)
.show_separators(true)
.build(), .build(),
date_range_picker,
}; };
factory.connect_bind({ factory.connect_bind({
@ -111,11 +106,17 @@ impl HistoricalView {
*s.imp().app.borrow_mut() = Some(app); *s.imp().app.borrow_mut() = Some(app);
s.imp().date_range_picker.connect_on_search({ let date_range_picker = DateRangePicker::default();
date_range_picker.connect_on_search({
let s = s.clone(); let s = s.clone();
move |interval| s.set_interval(interval) move |interval| s.set_interval(interval)
}); });
s.set_interval(interval);
let mut model = gio::ListStore::new::<Date>();
model.extend(interval.days().map(Date::new));
s.imp()
.list_view
.set_model(Some(&gtk::NoSelection::new(Some(model))));
s.imp().list_view.connect_activate({ s.imp().list_view.connect_activate({
let on_select_day = on_select_day.clone(); let on_select_day = on_select_day.clone();
@ -134,7 +135,7 @@ impl HistoricalView {
.hscrollbar_policy(gtk::PolicyType::Never) .hscrollbar_policy(gtk::PolicyType::Never)
.build(); .build();
s.append(&s.imp().date_range_picker); s.append(&date_range_picker);
s.append(&scroller); s.append(&scroller);
s s
@ -142,13 +143,10 @@ impl HistoricalView {
pub fn set_interval(&self, interval: DayInterval) { pub fn set_interval(&self, interval: DayInterval) {
let mut model = gio::ListStore::new::<Date>(); let mut model = gio::ListStore::new::<Date>();
let mut days = interval.days().map(Date::new).collect::<Vec<Date>>(); model.extend(interval.days().map(Date::new));
days.reverse();
model.extend(days.into_iter());
self.imp() self.imp()
.list_view .list_view
.set_model(Some(&gtk::NoSelection::new(Some(model)))); .set_model(Some(&gtk::NoSelection::new(Some(model))));
self.imp().date_range_picker.set_interval(interval.start, interval.end);
} }
} }