From 1b3ca7439dc2d35e59e9a785413196eeca93fd42 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 24 Dec 2023 12:00:12 -0500 Subject: [PATCH] Add styling to the day summary --- fitnesstrax/app/resources/style.css | 12 ++++++++++++ fitnesstrax/app/src/app_window.rs | 2 +- fitnesstrax/app/src/components/day.rs | 19 ++++++++++++++----- fitnesstrax/app/src/views/historical_view.rs | 17 ++++++++++------- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/fitnesstrax/app/resources/style.css b/fitnesstrax/app/resources/style.css index 314fd86..1f3aea4 100644 --- a/fitnesstrax/app/resources/style.css +++ b/fitnesstrax/app/resources/style.css @@ -19,3 +19,15 @@ padding: 8px; } +.daysummary { + padding: 8px; +} + +.daysummary-date { + font-size: larger; + margin-bottom: 8px; +} + +.daysummary-weight { + margin: 4px; +} diff --git a/fitnesstrax/app/src/app_window.rs b/fitnesstrax/app/src/app_window.rs index a7651ae..4268277 100644 --- a/fitnesstrax/app/src/app_window.rs +++ b/fitnesstrax/app/src/app_window.rs @@ -41,7 +41,7 @@ impl AppWindow { /// adw_app is an Adwaita application. Application windows need to have access to this, but /// otherwise we don't use this. /// - /// app is a core [App] object which encapsulates all of the basic logic. + /// app is a core [crate::app::App] object which encapsulates all of the basic logic. pub fn new( app_id: &str, resource_path: &str, diff --git a/fitnesstrax/app/src/components/day.rs b/fitnesstrax/app/src/components/day.rs index db87773..0899262 100644 --- a/fitnesstrax/app/src/components/day.rs +++ b/fitnesstrax/app/src/components/day.rs @@ -34,8 +34,12 @@ impl ObjectSubclass for DaySummaryPrivate { type ParentType = gtk::Box; fn new() -> Self { + let date = gtk::Label::builder() + .css_classes(["daysummary-date"]) + .halign(gtk::Align::Start) + .build(); Self { - date: gtk::Label::new(None), + date, weight: RefCell::new(None), } } @@ -46,6 +50,8 @@ impl WidgetImpl for DaySummaryPrivate {} impl BoxImpl for DaySummaryPrivate {} glib::wrapper! { + /// The DaySummary displays one day's activities in a narrative style. This is meant to give + /// an overall feel of everything that happened during the day without going into details. pub struct DaySummary(ObjectSubclass) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; } @@ -53,19 +59,18 @@ impl DaySummary { pub fn new() -> Self { let s: Self = Object::builder().build(); s.set_orientation(gtk::Orientation::Vertical); + s.set_css_classes(&["daysummary"]); s.append(&s.imp().date); s } - pub fn set_date(&self, date: chrono::NaiveDate) { + pub fn set_data(&self, date: chrono::NaiveDate, records: Vec) { self.imp() .date .set_text(&date.format("%y-%m-%d").to_string()); - } - pub fn set_records(&self, records: Vec) { if let Some(ref weight_label) = *self.imp().weight.borrow() { self.remove(weight_label); } @@ -73,7 +78,11 @@ impl DaySummary { if let Some(TraxRecord::Weight(weight_record)) = records.iter().filter(|f| f.is_weight()).next() { - let label = gtk::Label::new(Some(&format!("{}", weight_record.weight))); + let label = gtk::Label::builder() + .halign(gtk::Align::Start) + .label(&format!("{}", weight_record.weight)) + .css_classes(["daysummary-weight"]) + .build(); self.append(&label); *self.imp().weight.borrow_mut() = Some(label); } diff --git a/fitnesstrax/app/src/views/historical_view.rs b/fitnesstrax/app/src/views/historical_view.rs index 3ad535e..07ace8d 100644 --- a/fitnesstrax/app/src/views/historical_view.rs +++ b/fitnesstrax/app/src/views/historical_view.rs @@ -50,11 +50,6 @@ impl HistoricalView { let s: Self = Object::builder().build(); s.set_orientation(gtk::Orientation::Vertical); - let label = gtk::Label::builder() - .label("Database has been configured and now it is time to show data") - .build(); - s.append(&label); - let day_records: Vec = vec![DayRecords::new( chrono::NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(), vec![TraxRecord::Weight(Weight { @@ -89,14 +84,22 @@ impl HistoricalView { .and_downcast::() .expect("should be a DaySummary"); - summary.set_date(records.date()); - summary.set_records(records.records()); + summary.set_data(records.date(), records.records()); }); let lst = gtk::ListView::builder() .model(>k::NoSelection::new(Some(model))) .factory(&factory) + .single_click_activate(true) .build(); + lst.connect_activate(|s, idx| { + // This gets triggered whenever the user clicks on an item on the list. What we + // actually want to do here is to open a modal dialog that shows all of the details of + // the day and which allows the user to edit items within that dialog. + let item = s.model().unwrap().item(idx).unwrap(); + let records = item.downcast_ref::().unwrap(); + println!("list item activated: [{:?}] {:?}", idx, records.date()); + }); s.append(&lst);