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 {
font-size: x-large;
font-size: larger;
padding: 8px;
}
@ -11,55 +11,20 @@
padding: 8px;
}
.welcome__footer {}
.historical {
margin: 32px;
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 {
padding: 8px;
}
.day-summary > *:not(:last-child) {
margin-bottom: 8px;
}
.day-summary__date {
font-size: x-large;
font-size: larger;
margin-bottom: 8px;
}
.day-summary__weight {
@ -74,12 +39,4 @@
.step-view {
padding: 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 main_menu = gio::Menu::new();
main_menu.append(Some("About"), Some("app.about"));
main_menu.append(Some("Quit"), Some("app.quit"));
let main_menu_button = gtk::MenuButton::builder()
.icon_name("open-menu")

View File

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

View File

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

View File

@ -49,7 +49,7 @@ pub fn time_distance_summary(
(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 {

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.
@ -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/>.
*/
mod about;
mod app;
mod app_window;
mod components;
@ -34,15 +33,6 @@ const APP_ID_PROD: &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.
fn setup_app_close_action(app: &adw::Application) {
let action = ActionEntry::builder("quit")
@ -90,7 +80,6 @@ fn main() {
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
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);
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());

View File

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

View File

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