From f9f49285c5ecc76d3edfb0a54ffab53c2e296d7f Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 26 Feb 2022 18:57:55 +0100 Subject: Apply linter advices --- src/gui/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/gui/mod.rs (limited to 'src/gui/mod.rs') diff --git a/src/gui/mod.rs b/src/gui/mod.rs new file mode 100644 index 0000000..a8a025c --- /dev/null +++ b/src/gui/mod.rs @@ -0,0 +1,38 @@ +mod app; +mod calendar; +mod form; +mod update; +mod utils; + +use gtk4 as gtk; + +use gtk::gdk::Display; +use gtk::prelude::*; +use rusqlite::Connection; +use std::rc::Rc; + +use app::App; + +pub fn run(conn: Connection) { + let conn = Rc::new(conn); + let app = gtk::Application::new(Some("me.guyonvarch.calendar"), Default::default()); + app.connect_startup(|_| load_style()); + app.connect_activate(move |app| build_ui(conn.clone(), app)); + app.run(); +} + +fn build_ui(conn: Rc, app: >k::Application) { + let (tx, rx) = async_channel::unbounded(); + let app = App::new(conn, app, tx); + utils::spawn(update::event_handler(rx, app)) +} + +fn load_style() { + let provider = gtk::CssProvider::new(); + provider.load_from_data(include_bytes!("style.css")); + gtk::StyleContext::add_provider_for_display( + &Display::default().expect("Error initializing gtk css provider."), + &provider, + gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, + ); +} -- cgit v1.2.3