Touching up the application #200
|
@ -3,7 +3,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome__title {
|
.welcome__title {
|
||||||
font-size: larger;
|
font-size: x-large;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,22 +11,57 @@
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome__footer {}
|
|
||||||
|
|
||||||
.historical {
|
.historical {
|
||||||
margin: 32px;
|
margin: 32px;
|
||||||
border-radius: 8px;
|
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 {
|
.day-summary {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.day-summary__date {
|
.day-summary > *:not(:last-child) {
|
||||||
font-size: larger;
|
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.day-summary__date {
|
||||||
|
font-size: x-large;
|
||||||
|
}
|
||||||
|
|
||||||
.day-summary__weight {
|
.day-summary__weight {
|
||||||
margin: 4px;
|
margin: 4px;
|
||||||
}
|
}
|
||||||
|
@ -40,3 +75,11 @@
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
margin: 8px;
|
margin: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.about__content {
|
||||||
|
padding: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.about label {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
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(©right);
|
||||||
|
content.append(>k_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
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,6 +89,7 @@ impl AppWindow {
|
||||||
let header_bar = adw::HeaderBar::new();
|
let header_bar = adw::HeaderBar::new();
|
||||||
|
|
||||||
let main_menu = gio::Menu::new();
|
let main_menu = gio::Menu::new();
|
||||||
|
main_menu.append(Some("About"), Some("app.about"));
|
||||||
main_menu.append(Some("Quit"), Some("app.quit"));
|
main_menu.append(Some("Quit"), Some("app.quit"));
|
||||||
let main_menu_button = gtk::MenuButton::builder()
|
let main_menu_button = gtk::MenuButton::builder()
|
||||||
.icon_name("open-menu")
|
.icon_name("open-menu")
|
||||||
|
|
|
@ -113,11 +113,12 @@ glib::wrapper! {
|
||||||
impl DateField {
|
impl DateField {
|
||||||
pub fn new(date: chrono::NaiveDate) -> Self {
|
pub fn new(date: chrono::NaiveDate) -> Self {
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
|
s.add_css_class("date-field");
|
||||||
println!("{}", date);
|
|
||||||
|
|
||||||
s.append(&s.imp().year.widget());
|
s.append(&s.imp().year.widget());
|
||||||
|
s.append(>k::Label::new(Some("-")));
|
||||||
s.append(&s.imp().month.widget());
|
s.append(&s.imp().month.widget());
|
||||||
|
s.append(>k::Label::new(Some("-")));
|
||||||
s.append(&s.imp().day.widget());
|
s.append(&s.imp().day.widget());
|
||||||
|
|
||||||
s.set_date(date);
|
s.set_date(date);
|
||||||
|
@ -146,7 +147,7 @@ impl DateField {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
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.
|
// 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]
|
#[test]
|
||||||
|
|
|
@ -14,14 +14,11 @@ 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/>.
|
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::{
|
use crate::{components::DateField, types::DayInterval};
|
||||||
components::{DateField},
|
|
||||||
types::DayInterval,
|
|
||||||
};
|
|
||||||
use chrono::{Duration, Local, Months};
|
use chrono::{Duration, Local, Months};
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::{cell::RefCell};
|
use std::cell::RefCell;
|
||||||
|
|
||||||
type OnSearch = dyn Fn(DayInterval) + 'static;
|
type OnSearch = dyn Fn(DayInterval) + 'static;
|
||||||
|
|
||||||
|
@ -40,9 +37,14 @@ impl ObjectSubclass for DateRangePickerPrivate {
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let default_date = Local::now().date_naive();
|
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 {
|
Self {
|
||||||
start: DateField::new(default_date),
|
start,
|
||||||
end: DateField::new(default_date),
|
end,
|
||||||
on_search: RefCell::new(Box::new(|_| {})),
|
on_search: RefCell::new(Box::new(|_| {})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +58,6 @@ glib::wrapper! {
|
||||||
pub struct DateRangePicker(ObjectSubclass<DateRangePickerPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
pub struct DateRangePicker(ObjectSubclass<DateRangePickerPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl DateRangePicker {
|
impl DateRangePicker {
|
||||||
pub fn connect_on_search<OnSearch>(&self, f: OnSearch)
|
pub fn connect_on_search<OnSearch>(&self, f: OnSearch)
|
||||||
where
|
where
|
||||||
|
@ -65,12 +66,12 @@ impl DateRangePicker {
|
||||||
*self.imp().on_search.borrow_mut() = Box::new(f);
|
*self.imp().on_search.borrow_mut() = Box::new(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) {
|
pub fn set_interval(&self, start: chrono::NaiveDate, end: chrono::NaiveDate) {
|
||||||
self.imp().start.set_date(start);
|
self.imp().start.set_date(start);
|
||||||
self.imp().end.set_date(end);
|
self.imp().end.set_date(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interval(&self) -> DayInterval {
|
pub fn interval(&self) -> DayInterval {
|
||||||
DayInterval {
|
DayInterval {
|
||||||
start: self.imp().start.date(),
|
start: self.imp().start.date(),
|
||||||
end: self.imp().end.date(),
|
end: self.imp().end.date(),
|
||||||
|
@ -78,19 +79,25 @@ impl DateRangePicker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Default for DateRangePicker {
|
impl Default for DateRangePicker {
|
||||||
fn default() -> Self {
|
fn default() -> 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.add_css_class("date-range-picker");
|
||||||
|
|
||||||
let search_button = gtk::Button::with_label("Search");
|
let search_button = gtk::Button::builder()
|
||||||
|
.css_classes(["date-range-picker__search-button"])
|
||||||
|
.label("Search")
|
||||||
|
.build();
|
||||||
search_button.connect_clicked({
|
search_button.connect_clicked({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |_| (s.imp().on_search.borrow())(s.interval())
|
move |_| (s.imp().on_search.borrow())(s.interval())
|
||||||
});
|
});
|
||||||
|
|
||||||
let last_week_button = gtk::Button::builder().label("last week").build();
|
let last_week_button = gtk::Button::builder()
|
||||||
|
.css_classes(["date-range-picker__range-button"])
|
||||||
|
.label("week")
|
||||||
|
.build();
|
||||||
last_week_button.connect_clicked({
|
last_week_button.connect_clicked({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
|
@ -101,7 +108,10 @@ impl Default for DateRangePicker {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let two_weeks_button = gtk::Button::builder().label("last two weeks").build();
|
let two_weeks_button = gtk::Button::builder()
|
||||||
|
.css_classes(["date-range-picker__range-button"])
|
||||||
|
.label("two weeks")
|
||||||
|
.build();
|
||||||
two_weeks_button.connect_clicked({
|
two_weeks_button.connect_clicked({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
|
@ -112,7 +122,10 @@ impl Default for DateRangePicker {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let last_month_button = gtk::Button::builder().label("last month").build();
|
let last_month_button = gtk::Button::builder()
|
||||||
|
.css_classes(["date-range-picker__range-button"])
|
||||||
|
.label("month")
|
||||||
|
.build();
|
||||||
last_month_button.connect_clicked({
|
last_month_button.connect_clicked({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
|
@ -123,7 +136,10 @@ impl Default for DateRangePicker {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let six_months_button = gtk::Button::builder().label("last six months").build();
|
let six_months_button = gtk::Button::builder()
|
||||||
|
.css_classes(["date-range-picker__range-button"])
|
||||||
|
.label("six months")
|
||||||
|
.build();
|
||||||
six_months_button.connect_clicked({
|
six_months_button.connect_clicked({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
|
@ -134,7 +150,10 @@ impl Default for DateRangePicker {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let last_year_button = gtk::Button::builder().label("last year").build();
|
let last_year_button = gtk::Button::builder()
|
||||||
|
.css_classes(["date-range-picker__range-button"])
|
||||||
|
.label("year")
|
||||||
|
.build();
|
||||||
last_year_button.connect_clicked({
|
last_year_button.connect_clicked({
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |_| {
|
move |_| {
|
||||||
|
|
|
@ -84,25 +84,24 @@ impl DaySummary {
|
||||||
|
|
||||||
let row = gtk::Box::builder().build();
|
let row = gtk::Box::builder().build();
|
||||||
|
|
||||||
let label = gtk::Label::builder()
|
let weight_label = gtk::Label::builder()
|
||||||
.halign(gtk::Align::Start)
|
.halign(gtk::Align::Start)
|
||||||
.css_classes(["day-summary__weight"])
|
.css_classes(["day-summary__weight"])
|
||||||
.build();
|
.build();
|
||||||
if let Some(w) = view_model.weight() {
|
if let Some(w) = view_model.weight() {
|
||||||
label.set_label(&w.to_string())
|
weight_label.set_label(&w.to_string())
|
||||||
}
|
}
|
||||||
row.append(&label);
|
|
||||||
|
|
||||||
self.append(&label);
|
let steps_label = gtk::Label::builder()
|
||||||
|
|
||||||
let label = gtk::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
.halign(gtk::Align::Start)
|
||||||
.css_classes(["day-summary__weight"])
|
.css_classes(["day-summary__steps"])
|
||||||
.build();
|
.build();
|
||||||
if let Some(s) = view_model.steps() {
|
if let Some(s) = view_model.steps() {
|
||||||
label.set_label(&format!("{} steps", s));
|
steps_label.set_label(&format!("{} steps", s));
|
||||||
}
|
}
|
||||||
row.append(&label);
|
|
||||||
|
row.append(&weight_label);
|
||||||
|
row.append(&steps_label);
|
||||||
self.append(&row);
|
self.append(&row);
|
||||||
|
|
||||||
for activity in TIME_DISTANCE_ACTIVITIES {
|
for activity in TIME_DISTANCE_ACTIVITIES {
|
||||||
|
|
|
@ -49,7 +49,7 @@ pub fn time_distance_summary(
|
||||||
(false, false) => None,
|
(false, false) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
text.map(|text| gtk::Label::new(Some(&text)))
|
text.map(|text| gtk::Label::builder().halign(gtk::Align::Start).label(&text).build())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box {
|
pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
Copyright 2023 - 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||||
|
|
||||||
This file is part of FitnessTrax.
|
This file is part of FitnessTrax.
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ 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/>.
|
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;
|
||||||
mod app_window;
|
mod app_window;
|
||||||
mod components;
|
mod components;
|
||||||
|
@ -33,6 +34,15 @@ const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
|
||||||
|
|
||||||
const RESOURCE_BASE_PATH: &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.
|
/// Sets up an application-global action, `app.quit`, which will terminate the application.
|
||||||
fn setup_app_close_action(app: &adw::Application) {
|
fn setup_app_close_action(app: &adw::Application) {
|
||||||
let action = ActionEntry::builder("quit")
|
let action = ActionEntry::builder("quit")
|
||||||
|
@ -80,6 +90,7 @@ fn main() {
|
||||||
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
|
let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap());
|
||||||
icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions"));
|
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);
|
setup_app_close_action(adw_app);
|
||||||
|
|
||||||
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());
|
AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone());
|
||||||
|
|
|
@ -79,12 +79,12 @@ impl TimeFormatter {
|
||||||
match parts.len() {
|
match parts.len() {
|
||||||
0 => Err(ParseError),
|
0 => Err(ParseError),
|
||||||
1 => Err(ParseError),
|
1 => Err(ParseError),
|
||||||
2 => Ok(TimeFormatter(
|
2 => chrono::NaiveTime::from_hms_opt(parts[0], parts[1], 0)
|
||||||
chrono::NaiveTime::from_hms_opt(parts[0], parts[1], 0).unwrap(),
|
.map(|v| TimeFormatter(v))
|
||||||
)),
|
.ok_or(ParseError),
|
||||||
3 => Ok(TimeFormatter(
|
3 => chrono::NaiveTime::from_hms_opt(parts[0], parts[1], parts[2])
|
||||||
chrono::NaiveTime::from_hms_opt(parts[0], parts[1], parts[2]).unwrap(),
|
.map(|v| TimeFormatter(v))
|
||||||
)),
|
.ok_or(ParseError),
|
||||||
_ => Err(ParseError),
|
_ => Err(ParseError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ use std::{cell::RefCell, rc::Rc};
|
||||||
pub struct HistoricalViewPrivate {
|
pub struct HistoricalViewPrivate {
|
||||||
app: Rc<RefCell<Option<App>>>,
|
app: Rc<RefCell<Option<App>>>,
|
||||||
list_view: gtk::ListView,
|
list_view: gtk::ListView,
|
||||||
|
date_range_picker: DateRangePicker,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -47,12 +48,16 @@ impl ObjectSubclass for HistoricalViewPrivate {
|
||||||
.set_child(Some(&DaySummary::new()));
|
.set_child(Some(&DaySummary::new()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let date_range_picker = DateRangePicker::default();
|
||||||
|
|
||||||
let s = Self {
|
let s = Self {
|
||||||
app: Rc::new(RefCell::new(None)),
|
app: Rc::new(RefCell::new(None)),
|
||||||
list_view: gtk::ListView::builder()
|
list_view: gtk::ListView::builder()
|
||||||
.factory(&factory)
|
.factory(&factory)
|
||||||
.single_click_activate(true)
|
.single_click_activate(true)
|
||||||
|
.show_separators(true)
|
||||||
.build(),
|
.build(),
|
||||||
|
date_range_picker,
|
||||||
};
|
};
|
||||||
|
|
||||||
factory.connect_bind({
|
factory.connect_bind({
|
||||||
|
@ -106,17 +111,11 @@ impl HistoricalView {
|
||||||
|
|
||||||
*s.imp().app.borrow_mut() = Some(app);
|
*s.imp().app.borrow_mut() = Some(app);
|
||||||
|
|
||||||
let date_range_picker = DateRangePicker::default();
|
s.imp().date_range_picker.connect_on_search({
|
||||||
date_range_picker.connect_on_search({
|
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |interval| s.set_interval(interval)
|
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(>k::NoSelection::new(Some(model))));
|
|
||||||
|
|
||||||
s.imp().list_view.connect_activate({
|
s.imp().list_view.connect_activate({
|
||||||
let on_select_day = on_select_day.clone();
|
let on_select_day = on_select_day.clone();
|
||||||
|
@ -135,7 +134,7 @@ impl HistoricalView {
|
||||||
.hscrollbar_policy(gtk::PolicyType::Never)
|
.hscrollbar_policy(gtk::PolicyType::Never)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
s.append(&date_range_picker);
|
s.append(&s.imp().date_range_picker);
|
||||||
s.append(&scroller);
|
s.append(&scroller);
|
||||||
|
|
||||||
s
|
s
|
||||||
|
@ -143,10 +142,13 @@ impl HistoricalView {
|
||||||
|
|
||||||
pub fn set_interval(&self, interval: DayInterval) {
|
pub fn set_interval(&self, interval: DayInterval) {
|
||||||
let mut model = gio::ListStore::new::<Date>();
|
let mut model = gio::ListStore::new::<Date>();
|
||||||
model.extend(interval.days().map(Date::new));
|
let mut days = interval.days().map(Date::new).collect::<Vec<Date>>();
|
||||||
|
days.reverse();
|
||||||
|
model.extend(days.into_iter());
|
||||||
self.imp()
|
self.imp()
|
||||||
.list_view
|
.list_view
|
||||||
.set_model(Some(>k::NoSelection::new(Some(model))));
|
.set_model(Some(>k::NoSelection::new(Some(model))));
|
||||||
|
self.imp().date_range_picker.set_interval(interval.start, interval.end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue