Show the weight for each day as a summary in some hard-coded records. #128
|
@ -19,3 +19,15 @@
|
|||
padding: 8px;
|
||||
}
|
||||
|
||||
.daysummary {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.daysummary-date {
|
||||
font-size: larger;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.daysummary-weight {
|
||||
margin: 4px;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<DaySummaryPrivate>) @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<TraxRecord>) {
|
||||
self.imp()
|
||||
.date
|
||||
.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() {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<DayRecords> = vec![DayRecords::new(
|
||||
chrono::NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
||||
vec![TraxRecord::Weight(Weight {
|
||||
|
@ -89,14 +84,22 @@ impl HistoricalView {
|
|||
.and_downcast::<DaySummary>()
|
||||
.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::<DayRecords>().unwrap();
|
||||
println!("list item activated: [{:?}] {:?}", idx, records.date());
|
||||
});
|
||||
|
||||
s.append(&lst);
|
||||
|
||||
|
|
Loading…
Reference in New Issue