Add styling to the day summary

This commit is contained in:
Savanni D'Gerinel 2023-12-24 12:00:12 -05:00
parent 3dc8be0d26
commit 1b3ca7439d
4 changed files with 37 additions and 13 deletions

View File

@ -19,3 +19,15 @@
padding: 8px; padding: 8px;
} }
.daysummary {
padding: 8px;
}
.daysummary-date {
font-size: larger;
margin-bottom: 8px;
}
.daysummary-weight {
margin: 4px;
}

View File

@ -41,7 +41,7 @@ impl AppWindow {
/// adw_app is an Adwaita application. Application windows need to have access to this, but /// adw_app is an Adwaita application. Application windows need to have access to this, but
/// otherwise we don't use this. /// 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( pub fn new(
app_id: &str, app_id: &str,
resource_path: &str, resource_path: &str,

View File

@ -34,8 +34,12 @@ impl ObjectSubclass for DaySummaryPrivate {
type ParentType = gtk::Box; type ParentType = gtk::Box;
fn new() -> Self { fn new() -> Self {
let date = gtk::Label::builder()
.css_classes(["daysummary-date"])
.halign(gtk::Align::Start)
.build();
Self { Self {
date: gtk::Label::new(None), date,
weight: RefCell::new(None), weight: RefCell::new(None),
} }
} }
@ -46,6 +50,8 @@ impl WidgetImpl for DaySummaryPrivate {}
impl BoxImpl for DaySummaryPrivate {} impl BoxImpl for DaySummaryPrivate {}
glib::wrapper! { 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<DaySummaryPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable; pub struct DaySummary(ObjectSubclass<DaySummaryPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
} }
@ -53,19 +59,18 @@ 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(&["daysummary"]);
s.append(&s.imp().date); s.append(&s.imp().date);
s s
} }
pub fn set_date(&self, date: chrono::NaiveDate) { pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<TraxRecord>) {
self.imp() self.imp()
.date .date
.set_text(&date.format("%y-%m-%d").to_string()); .set_text(&date.format("%y-%m-%d").to_string());
}
pub fn set_records(&self, records: Vec<TraxRecord>) {
if let Some(ref weight_label) = *self.imp().weight.borrow() { if let Some(ref weight_label) = *self.imp().weight.borrow() {
self.remove(weight_label); self.remove(weight_label);
} }
@ -73,7 +78,11 @@ impl DaySummary {
if let Some(TraxRecord::Weight(weight_record)) = if let Some(TraxRecord::Weight(weight_record)) =
records.iter().filter(|f| f.is_weight()).next() 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.append(&label);
*self.imp().weight.borrow_mut() = Some(label); *self.imp().weight.borrow_mut() = Some(label);
} }

View File

@ -50,11 +50,6 @@ impl HistoricalView {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Vertical); 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<DayRecords> = vec![DayRecords::new( let day_records: Vec<DayRecords> = vec![DayRecords::new(
chrono::NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(), chrono::NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
vec![TraxRecord::Weight(Weight { vec![TraxRecord::Weight(Weight {
@ -89,14 +84,22 @@ impl HistoricalView {
.and_downcast::<DaySummary>() .and_downcast::<DaySummary>()
.expect("should be a DaySummary"); .expect("should be a DaySummary");
summary.set_date(records.date()); summary.set_data(records.date(), records.records());
summary.set_records(records.records());
}); });
let lst = gtk::ListView::builder() let lst = gtk::ListView::builder()
.model(&gtk::NoSelection::new(Some(model))) .model(&gtk::NoSelection::new(Some(model)))
.factory(&factory) .factory(&factory)
.single_click_activate(true)
.build(); .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::<DayRecords>().unwrap();
println!("list item activated: [{:?}] {:?}", idx, records.date());
});
s.append(&lst); s.append(&lst);