aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/app.rs3
-rw-r--r--src/gui/calendar.rs59
-rw-r--r--src/gui/form/mod.rs7
3 files changed, 52 insertions, 17 deletions
diff --git a/src/gui/app.rs b/src/gui/app.rs
index c0fc038..e48c93a 100644
--- a/src/gui/app.rs
+++ b/src/gui/app.rs
@@ -44,7 +44,8 @@ impl App {
let today = chrono::offset::Local::now().naive_utc().date();
// TODO: error handling
let start_date =
- NaiveDate::from_isoywd_opt(today.year(), today.iso_week().week(), Weekday::Mon).unwrap();
+ NaiveDate::from_isoywd_opt(today.year(), today.iso_week().week(), Weekday::Mon)
+ .unwrap();
let end_date = start_date + Duration::days(7 * 4 - 1);
let events = db::events::list_non_recurring_between(&conn, start_date, end_date)?;
diff --git a/src/gui/calendar.rs b/src/gui/calendar.rs
index c80efef..7a040f5 100644
--- a/src/gui/calendar.rs
+++ b/src/gui/calendar.rs
@@ -6,7 +6,10 @@ use gtk::glib;
use gtk::prelude::*;
use std::collections::HashMap;
-use crate::{gui::update, gui::update::Msg, gui::App, model::event, model::event::Event, model::category::Category};
+use crate::{
+ gui::update, gui::update::Msg, gui::App, model::category::Category, model::event,
+ model::event::Event,
+};
static DAYS: [&str; 7] = ["LUN", "MAR", "MER", "JEU", "VEN", "SAM", "DIM"];
static MONTHES: [&str; 12] = [
@@ -59,7 +62,15 @@ fn attach_days(
for row in 1..5 {
for col in 0..7 {
grid.attach(
- &day_entry(tx.clone(), d, today, events, repetitions, categories, default_color),
+ &day_entry(
+ tx.clone(),
+ d,
+ today,
+ events,
+ repetitions,
+ categories,
+ default_color,
+ ),
col,
row,
1,
@@ -72,12 +83,11 @@ fn attach_days(
}
pub fn refresh_date(
- app: &App,
- date: NaiveDate,
- repetitions: &HashMap<NaiveDate,
- Vec<Event>>,
+ app: &App,
+ date: NaiveDate,
+ repetitions: &HashMap<NaiveDate, Vec<Event>>,
categories: &[Category],
- default_color: &str
+ default_color: &str,
) {
let d = date.signed_duration_since(app.start_date).num_days();
@@ -85,7 +95,15 @@ pub fn refresh_date(
let row = 1 + (d / 7) as i32;
app.calendar.attach(
- &day_entry(app.tx.clone(), date, app.today, &app.events, repetitions, categories, default_color),
+ &day_entry(
+ app.tx.clone(),
+ date,
+ app.today,
+ &app.events,
+ repetitions,
+ categories,
+ default_color,
+ ),
col,
row,
1,
@@ -179,9 +197,9 @@ fn day_label(today: NaiveDate, date: NaiveDate) -> gtk::Label {
}
fn day_events(
- date: NaiveDate,
- tx: Sender<Msg>,
- events: Vec<&Event>,
+ date: NaiveDate,
+ tx: Sender<Msg>,
+ events: Vec<&Event>,
categories: &[Category],
default_color: &str,
) -> gtk::Box {
@@ -195,10 +213,16 @@ fn day_events(
.hexpand(true)
.build();
- let background_color = categories.iter().find(|c| event.category == Some(c.id)).map(|c| c.color.clone()).unwrap_or_else(|| default_color.to_string());
+ let background_color = categories
+ .iter()
+ .find(|c| event.category == Some(c.id))
+ .map(|c| c.color.clone())
+ .unwrap_or_else(|| default_color.to_string());
let provider = gtk::CssProvider::new();
- provider.load_from_data(format!("
+ provider.load_from_data(
+ format!(
+ "
.event {{
background-color: {};
color: white;
@@ -210,8 +234,13 @@ fn day_events(
.event:hover {{
filter: brightness(120%);
}}
- ", background_color).as_bytes());
- hbox.style_context().add_provider(&provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
+ ",
+ background_color
+ )
+ .as_bytes(),
+ );
+ hbox.style_context()
+ .add_provider(&provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
hbox.style_context().add_class("event");
let gesture = gtk::GestureClick::new();
diff --git a/src/gui/form/mod.rs b/src/gui/form/mod.rs
index cc77a19..0b63dea 100644
--- a/src/gui/form/mod.rs
+++ b/src/gui/form/mod.rs
@@ -157,7 +157,12 @@ pub async fn show(app: &App, target: Target) {
);
category_dropdown.set_margin_bottom(10);
let selected = get_selected_category(&event, &app.categories).unwrap_or_else(|| "".to_string());
- category_dropdown.set_selected(dropdown_categories.iter().position(|d| d == &selected).unwrap_or(0) as u32);
+ category_dropdown.set_selected(
+ dropdown_categories
+ .iter()
+ .position(|d| d == &selected)
+ .unwrap_or(0) as u32,
+ );
column1.append(&utils::label("Catégorie"));
column1.append(&category_dropdown);