diff --git a/src/main.rs b/src/main.rs index 8e1f4b6..2586cb7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use gtk4 :: style_context_add_provider_for_display ; use gtk4 :: STYLE_PROVIDER_PRIORITY_APPLICATION ; use gtk4 :: gdk :: * ; use gtk4 :: glib :: * ; -use libadwaita :: * ; +use libadwaita :: Application ; use libadwaita :: prelude :: * ; use crate :: data_manager :: * ; @@ -39,12 +39,7 @@ fn add_style_provider ( _ : & Application ) { } fn show_window ( application : & Application ) { - let window = leak ( - ApplicationWindow :: builder () - . application (application) - . title ("Zoödex") - . build () - ) ; + let window = leak ( Window :: new (application) ) ; spawn_future_local ( async move { async_result_context ! ( @@ -57,7 +52,7 @@ fn show_window ( application : & Application ) { data_manager . get_film_details (film_uuid) . await . unwrap () } ) , ) ; - window . set_visible (true) ; + window . show () ; let collection = data_manager . get_collection_overview () . await ? ; ui . render_collection_overview (collection) . await ; diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 07c0e86..9c26cfe 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -25,7 +25,7 @@ pub struct UI { impl UI { pub fn new ( - window : & 'static ApplicationWindow , + window : & 'static Window , get_film_details : impl Fn (String) -> BoxFuture < 'static , FilmDetails > + 'static , ) -> UI { let get_film_details = leak (get_film_details) ; @@ -54,12 +54,12 @@ impl UI { & format ! ( "Release date: {}" , film_details . release_date ) , ) ) . as_ref () , ) , - ) . present ( Some (window) ) + ) . present ( Some ( & window . libadwaita_window ) ) } ) ; } ) ; let series_component = CollatableMediaContainer :: :: new ( - |series| dialog ! () . present ( Some (window) ) , + |series| dialog ! () . present ( Some ( & window . libadwaita_window ) ) , ) ; let switched = view_stack ! ( ( "Films" , "camera-video-symbolic" , films_component . get_widget () ) , @@ -69,7 +69,7 @@ impl UI { & view_switcher ! ( @ policy : Wide ; & switched ) , ) ; - window . set_content ( Some ( + window . libadwaita_window . set_content ( Some ( & toolbar_view ! ( @ top_bar : & header_bar ; & switched ) , ) ) ; @@ -83,3 +83,23 @@ impl UI { ) ; } } + + + +pub struct Window { + libadwaita_window : ApplicationWindow , +} + +impl Window { + pub fn new (application : & Application ) -> Self { + let libadwaita_window = ApplicationWindow :: builder () + . application (application) + . title ("Zoödex") + . build () ; + Self { libadwaita_window } + } + + pub fn show ( & self ) { self . libadwaita_window . set_visible (true) } + + pub fn close ( & self ) { self . libadwaita_window . close () } +}