Compare commits

..

No commits in common. "ad9312df4ceaef179120194bd93d469057a35c12" and "af8f9b024434abff24bb9ca58712e94738edd50f" have entirely different histories.

10 changed files with 61 additions and 385 deletions

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
adw = { version = "0.5", package = "libadwaita", features = [ "v1_4" ] } adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
async-channel = { version = "2.1" } async-channel = { version = "2.1" }
chrono = { version = "0.4" } chrono = { version = "0.4" }
chrono-tz = { version = "0.8" } chrono-tz = { version = "0.8" }

View File

@ -2,57 +2,32 @@
margin: 64px; margin: 64px;
} }
.welcome__title { .welcome-title {
font-size: larger; font-size: larger;
padding: 8px; padding: 8px;
} }
.welcome__content { .welcome-content {
padding: 8px; padding: 8px;
} }
.welcome__footer { .welcome-footer {
} }
.modal { .dialog-row {
background-color: @dialog_bg_color;
border-radius: 8px;
margin: 64px;
}
.modal__header {
}
.modal__title {
font-size: larger;
padding: 8px;
}
.modal__content {
background-color: @view_bg_color;
margin: 16px;
}
.modal__row {
margin: 8px 0px 8px 0px; margin: 8px 0px 8px 0px;
padding: 8px; padding: 8px;
} }
.historical { .daysummary {
margin: 32px;
border-radius: 8px;
}
.day-summary {
padding: 8px; padding: 8px;
} }
.day-summary__date { .daysummary-date {
font-size: larger; font-size: larger;
margin-bottom: 8px; margin-bottom: 8px;
} }
.day-summary__weight { .daysummary-weight {
margin: 4px; margin: 4px;
} }

View File

@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License along with Fit
use crate::{ use crate::{
app::{AppInvocation, AppResponse}, app::{AppInvocation, AppResponse},
components::day_detail,
views::{HistoricalView, PlaceholderView, View, ViewName, WelcomeView}, views::{HistoricalView, PlaceholderView, View, ViewName, WelcomeView},
}; };
use adw::prelude::*; use adw::prelude::*;
@ -39,7 +38,6 @@ pub struct AppWindow {
layout: gtk::Box, layout: gtk::Box,
current_view: Rc<RefCell<View>>, current_view: Rc<RefCell<View>>,
settings: gio::Settings, settings: gio::Settings,
navigation: adw::NavigationView,
} }
impl AppWindow { impl AppWindow {
@ -79,13 +77,9 @@ impl AppWindow {
#[allow(deprecated)] #[allow(deprecated)]
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER); context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
let navigation = adw::NavigationView::new();
/*
let header = adw::HeaderBar::builder() let header = adw::HeaderBar::builder()
.title_widget(&gtk::Label::new(Some("FitnessTrax"))) .title_widget(&gtk::Label::new(Some("FitnessTrax")))
.build(); .build();
*/
let layout = gtk::Box::builder() let layout = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)
@ -93,33 +87,17 @@ impl AppWindow {
let initial_view = View::Placeholder(PlaceholderView::new().upcast()); let initial_view = View::Placeholder(PlaceholderView::new().upcast());
// layout.append(&header); layout.append(&header);
layout.append(initial_view.widget()); layout.append(initial_view.widget());
let nav_layout = gtk::Box::new(gtk::Orientation::Vertical, 0); window.set_content(Some(&layout));
nav_layout.append(&adw::HeaderBar::new());
nav_layout.append(&layout);
navigation.push(
&adw::NavigationPage::builder()
.can_pop(false)
.title("FitnessTrax")
.child(&nav_layout)
.build(),
);
window.set_content(Some(&navigation));
window.present(); window.present();
let gesture = gtk::GestureClick::new();
gesture.connect_released(|_, _, _, _| println!("detected gesture"));
layout.add_controller(gesture);
let s = Self { let s = Self {
app_tx, app_tx,
layout, layout,
current_view: Rc::new(RefCell::new(initial_view)), current_view: Rc::new(RefCell::new(initial_view)),
settings: gio::Settings::new(app_id), settings: gio::Settings::new(app_id),
navigation,
}; };
s s
@ -172,51 +150,36 @@ impl AppWindow {
.upcast(), .upcast(),
), ),
ViewName::Historical => View::Historical( ViewName::Historical => View::Historical(
HistoricalView::new( HistoricalView::new(vec![
vec![ TraxRecord::Steps(Steps {
TraxRecord::Steps(Steps { date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(), count: 1500,
count: 1500, }),
}), TraxRecord::Weight(Weight {
TraxRecord::Weight(Weight { date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(), weight: 85. * KG,
weight: 85. * KG, }),
}), TraxRecord::Weight(Weight {
TraxRecord::Weight(Weight { date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(), weight: 86. * KG,
weight: 86. * KG, }),
}), TraxRecord::BikeRide(TimeDistance {
TraxRecord::BikeRide(TimeDistance { datetime: DateTimeTz(
datetime: DateTimeTz( Anchorage.with_ymd_and_hms(2019, 6, 15, 12, 0, 0).unwrap(),
Anchorage.with_ymd_and_hms(2019, 6, 15, 12, 0, 0).unwrap(), ),
), distance: Some(1000. * M),
distance: Some(1000. * M), duration: Some(150. * S),
duration: Some(150. * S), comments: Some("Test Comments".to_owned()),
comments: Some("Test Comments".to_owned()), }),
}), TraxRecord::BikeRide(TimeDistance {
TraxRecord::BikeRide(TimeDistance { datetime: DateTimeTz(
datetime: DateTimeTz( Anchorage.with_ymd_and_hms(2019, 6, 15, 23, 0, 0).unwrap(),
Anchorage.with_ymd_and_hms(2019, 6, 15, 23, 0, 0).unwrap(), ),
), distance: Some(1000. * M),
distance: Some(1000. * M), duration: Some(150. * S),
duration: Some(150. * S), comments: Some("Test Comments".to_owned()),
comments: Some("Test Comments".to_owned()), }),
}), ])
],
{
let s = self.clone();
Rc::new(move |date: chrono::NaiveDate, records| {
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
layout.append(&adw::HeaderBar::new());
layout.append(&day_detail(date, records));
let page = &adw::NavigationPage::builder()
.title(date.format("%Y-%m-%d").to_string())
.child(&layout)
.build();
s.navigation.push(page);
})
},
)
.upcast(), .upcast(),
), ),
} }

View File

@ -16,12 +16,12 @@ 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::Modal;
use ft_core::TraxRecord; use ft_core::TraxRecord;
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell; use std::cell::RefCell;
#[derive(Default)]
pub struct DaySummaryPrivate { pub struct DaySummaryPrivate {
date: gtk::Label, date: gtk::Label,
weight: RefCell<Option<gtk::Label>>, weight: RefCell<Option<gtk::Label>>,
@ -35,7 +35,7 @@ impl ObjectSubclass for DaySummaryPrivate {
fn new() -> Self { fn new() -> Self {
let date = gtk::Label::builder() let date = gtk::Label::builder()
.css_classes(["day-summary__date"]) .css_classes(["daysummary-date"])
.halign(gtk::Align::Start) .halign(gtk::Align::Start)
.build(); .build();
Self { Self {
@ -59,7 +59,7 @@ impl DaySummary {
pub fn new() -> Self { pub fn new() -> 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.set_css_classes(&["day-summary"]); s.set_css_classes(&["daysummary"]);
s.append(&s.imp().date); s.append(&s.imp().date);
@ -81,85 +81,10 @@ impl DaySummary {
let label = gtk::Label::builder() let label = gtk::Label::builder()
.halign(gtk::Align::Start) .halign(gtk::Align::Start)
.label(&format!("{}", weight_record.weight)) .label(&format!("{}", weight_record.weight))
.css_classes(["day-summary__weight"]) .css_classes(["daysummary-weight"])
.build(); .build();
self.append(&label); self.append(&label);
*self.imp().weight.borrow_mut() = Some(label); *self.imp().weight.borrow_mut() = Some(label);
} }
} }
} }
/*
pub struct DayDetailPrivate {
date: gtk::Label,
weight: RefCell<Option<gtk::Label>>,
}
#[glib::object_subclass]
impl ObjectSubclass for DayDetailPrivate {
const NAME: &'static str = "DayDetail";
type Type = DayDetail;
type ParentType = gtk::Box;
fn new() -> Self {
let date = gtk::Label::builder()
.css_classes(["daysummary-date"])
.halign(gtk::Align::Start)
.build();
Self {
date,
weight: RefCell::new(None),
}
}
}
impl ObjectImpl for DayDetailPrivate {}
impl WidgetImpl for DayDetailPrivate {}
impl BoxImpl for DayDetailPrivate {}
glib::wrapper! {
pub struct DayDetail(ObjectSubclass<DayDetailPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
}
impl DayDetail {
pub fn new() -> Self {
let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Vertical);
s.set_css_classes(&["modal"]);
s.append(&gtk::Label::new(Some("abcdefg")));
s
}
}
*/
pub fn day_detail(date: chrono::NaiveDate, records: Vec<TraxRecord>) -> gtk::Widget {
let modal = Modal::new(&date.format("%Y-%m-%d").to_string(), || {});
let content = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
records.into_iter().for_each(|record| {
let record_view = match record {
TraxRecord::BikeRide(_) => gtk::Label::new(Some("BikeRide")),
TraxRecord::Row(_) => gtk::Label::new(Some("Row")),
TraxRecord::Run(_) => gtk::Label::new(Some("Run")),
TraxRecord::Steps(_) => gtk::Label::new(Some("Steps")),
TraxRecord::Swim(_) => gtk::Label::new(Some("Swim")),
TraxRecord::Walk(_) => gtk::Label::new(Some("Walk")),
TraxRecord::Weight(_) => gtk::Label::new(Some("Weight")),
};
record_view.add_css_class("day-detail");
record_view.set_halign(gtk::Align::Start);
content.append(&record_view);
});
modal.set_content(content.upcast());
modal.set_primary_action(gtk::Button::builder().label("Save").build());
modal.set_secondary_action(gtk::Button::builder().label("Cancel").build());
modal.upcast()
}

View File

@ -15,11 +15,8 @@ You should have received a copy of the GNU General Public License along with Fit
*/ */
mod day; mod day;
pub use day::{day_detail, DaySummary};
mod modal;
pub use modal::{Modal, ModalImpl};
pub use day::DaySummary;
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, path::PathBuf, rc::Rc}; use std::{cell::RefCell, path::PathBuf, rc::Rc};

View File

@ -1,178 +0,0 @@
//! The Modal is a reusable component with a title, arbitrary content, and up to three action
//! buttons. It does not itself enforce being a modal, but is meant to become a child of an Overlay
//! component.
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell;
pub struct ModalPrivate {
header: ModalHeader,
content: RefCell<gtk::Widget>,
primary_action: RefCell<gtk::Button>,
secondary_action: RefCell<Option<gtk::Button>>,
// tertiary_action: RefCell<Option<gtk::Button>>,
footer: gtk::Box,
}
#[glib::object_subclass]
impl ObjectSubclass for ModalPrivate {
const NAME: &'static str = "Modal";
type Type = Modal;
type ParentType = gtk::Box;
fn new() -> Self {
let header = ModalHeader::new("Modal");
let content = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.vexpand(true)
.css_classes(["modal__content"])
.build();
let primary_action = gtk::Button::builder().label("Primary").build();
let footer = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.hexpand(true)
.halign(gtk::Align::End)
.build();
footer.append(&primary_action);
Self {
header,
content: RefCell::new(content.upcast()),
primary_action: RefCell::new(primary_action),
secondary_action: RefCell::new(None),
// tertiary_action: RefCell::new(None),
footer,
}
}
}
impl ObjectImpl for ModalPrivate {}
impl WidgetImpl for ModalPrivate {}
impl BoxImpl for ModalPrivate {}
glib::wrapper! {
pub struct Modal(ObjectSubclass<ModalPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
}
pub trait ModalImpl: BoxImpl {}
unsafe impl<T: ModalImpl> IsSubclassable<T> for Modal {}
impl Modal {
pub fn new<OnCancel>(title: &str, on_cancel: OnCancel) -> Self
where
OnCancel: FnOnce() + 'static,
{
let s: Self = Object::builder().build();
s.set_css_classes(&["modal"]);
s.set_orientation(gtk::Orientation::Vertical);
s.set_hexpand(true);
s.imp().header.set_title(title);
s.imp().header.set_on_cancel(on_cancel);
s.append(&s.imp().header);
s.append(&*s.imp().content.borrow());
s.append(&s.imp().footer);
let gesture = gtk::GestureClick::new();
gesture.connect_released(|s, _, _, _| println!("released on {:?}", s));
s.add_controller(gesture.clone());
s
}
pub fn set_title(&self, text: &str) {
self.imp().header.set_title(text);
}
pub fn set_content(&self, content: gtk::Widget) {
self.remove(&*self.imp().content.borrow());
content.set_halign(gtk::Align::Fill);
content.set_vexpand(true);
content.add_css_class("modal__content");
self.insert_child_after(&content, Some(&self.imp().header));
*self.imp().content.borrow_mut() = content;
}
pub fn set_primary_action(&self, action: gtk::Button) {
*self.imp().primary_action.borrow_mut() = action;
self.render_footer();
}
pub fn set_secondary_action(&self, action: gtk::Button) {
*self.imp().secondary_action.borrow_mut() = Some(action);
self.render_footer();
}
fn render_footer(&self) {
while let Some(ref child) = self.imp().footer.first_child() {
self.imp().footer.remove(child);
}
if let Some(ref button) = *self.imp().secondary_action.borrow() {
self.imp().footer.append(button);
}
self.imp()
.footer
.append(&*self.imp().primary_action.borrow());
}
}
pub struct ModalHeaderPrivate {
title: gtk::Label,
on_cancel: RefCell<Box<dyn FnOnce()>>,
}
#[glib::object_subclass]
impl ObjectSubclass for ModalHeaderPrivate {
const NAME: &'static str = "ModalHeader";
type Type = ModalHeader;
type ParentType = gtk::Box;
fn new() -> Self {
Self {
title: gtk::Label::builder().css_classes(["modal__title"]).build(),
on_cancel: RefCell::new(Box::new(|| {})),
}
}
}
impl ObjectImpl for ModalHeaderPrivate {}
impl WidgetImpl for ModalHeaderPrivate {}
impl BoxImpl for ModalHeaderPrivate {}
glib::wrapper! {
pub struct ModalHeader(ObjectSubclass<ModalHeaderPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
}
impl ModalHeader {
pub fn new(title: &str) -> Self {
let s: Self = Object::builder().build();
s.add_css_class("modal__header");
s.set_homogeneous(true);
s.imp().title.set_text(title);
let left = gtk::Box::builder().build();
let center = gtk::Box::builder().halign(gtk::Align::Center).build();
let right = gtk::Box::builder().halign(gtk::Align::End).build();
center.append(&s.imp().title);
s.append(&left);
s.append(&center);
s.append(&right);
s
}
pub fn set_title(&self, title: &str) {
self.imp().title.set_text(title);
}
pub fn set_on_cancel<OnCancel>(&self, on_cancel: OnCancel)
where
OnCancel: FnOnce() + 'static,
{
*self.imp().on_cancel.borrow_mut() = Box::new(on_cancel);
}
}

View File

@ -19,7 +19,7 @@ use emseries::{Recordable, Timestamp};
use ft_core::TraxRecord; use ft_core::TraxRecord;
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, collections::HashMap, rc::Rc}; use std::{cell::RefCell, collections::HashMap};
/// The historical view will show a window into the main database. It will show some version of /// The historical view will show a window into the main database. It will show some version of
/// daily summaries, daily details, and will provide all functions the user may need for editing /// daily summaries, daily details, and will provide all functions the user may need for editing
@ -46,13 +46,9 @@ glib::wrapper! {
} }
impl HistoricalView { impl HistoricalView {
pub fn new<SelectFn>(records: Vec<TraxRecord>, on_select_day: Rc<SelectFn>) -> Self pub fn new(records: Vec<TraxRecord>) -> Self {
where
SelectFn: Fn(chrono::NaiveDate, Vec<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_css_classes(&["historical"]);
let day_records: GroupedRecords = GroupedRecords::from(records); let day_records: GroupedRecords = GroupedRecords::from(records);
@ -90,16 +86,13 @@ impl HistoricalView {
.factory(&factory) .factory(&factory)
.single_click_activate(true) .single_click_activate(true)
.build(); .build();
lst.connect_activate({ lst.connect_activate(|s, idx| {
let on_select_day = on_select_day.clone(); // This gets triggered whenever the user clicks on an item on the list. What we
move |s, idx| { // actually want to do here is to open a modal dialog that shows all of the details of
// This gets triggered whenever the user clicks on an item on the list. What we // the day and which allows the user to edit items within that dialog.
// actually want to do here is to open a modal dialog that shows all of the details of let item = s.model().unwrap().item(idx).unwrap();
// the day and which allows the user to edit items within that dialog. let records = item.downcast_ref::<DayRecords>().unwrap();
let item = s.model().unwrap().item(idx).unwrap(); println!("list item activated: [{:?}] {:?}", idx, records.date());
let records = item.downcast_ref::<DayRecords>().unwrap();
on_select_day(records.date(), records.records());
}
}); });
s.append(&lst); s.append(&lst);

View File

@ -55,10 +55,11 @@ impl WelcomeView {
// branch. // branch.
let title = gtk::Label::builder() let title = gtk::Label::builder()
.label("Welcome to FitnessTrax") .label("Welcome to FitnessTrax")
.css_classes(["welcome__title"]) .css_classes(["welcome-title"])
.build(); .build();
let content = gtk::Box::builder() let content = gtk::Box::builder()
.css_classes(["model-content"])
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)
.vexpand(true) .vexpand(true)
.build(); .build();

View File

@ -51,16 +51,16 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1703200384, "lastModified": 1691421349,
"narHash": "sha256-q5j06XOsy0qHOarsYPfZYJPWbTbc8sryRxianlEPJN0=", "narHash": "sha256-RRJyX0CUrs4uW4gMhd/X4rcDG8PTgaaCQM5rXEJOx6g=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "0b3d618173114c64ab666f557504d6982665d328", "rev": "011567f35433879aae5024fc6ec53f2a0568a6c4",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "nixos-23.11", "ref": "nixos-23.05",
"type": "indirect" "type": "indirect"
} }
}, },

View File

@ -2,7 +2,7 @@
description = "Lumenescent Dreams Tools"; description = "Lumenescent Dreams Tools";
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixos-23.11"; nixpkgs.url = "nixpkgs/nixos-23.05";
unstable.url = "nixpkgs/nixos-unstable"; unstable.url = "nixpkgs/nixos-unstable";
pkgs-cargo2nix.url = "github:cargo2nix/cargo2nix"; pkgs-cargo2nix.url = "github:cargo2nix/cargo2nix";
typeshare.url = "github:1Password/typeshare"; typeshare.url = "github:1Password/typeshare";