Encapsulate window and its operations in struct
This commit is contained in:
parent
8bea2088a0
commit
90594514bd
2 changed files with 27 additions and 12 deletions
11
src/main.rs
11
src/main.rs
|
@ -8,7 +8,7 @@ use gtk4 :: style_context_add_provider_for_display ;
|
||||||
use gtk4 :: STYLE_PROVIDER_PRIORITY_APPLICATION ;
|
use gtk4 :: STYLE_PROVIDER_PRIORITY_APPLICATION ;
|
||||||
use gtk4 :: gdk :: * ;
|
use gtk4 :: gdk :: * ;
|
||||||
use gtk4 :: glib :: * ;
|
use gtk4 :: glib :: * ;
|
||||||
use libadwaita :: * ;
|
use libadwaita :: Application ;
|
||||||
use libadwaita :: prelude :: * ;
|
use libadwaita :: prelude :: * ;
|
||||||
|
|
||||||
use crate :: data_manager :: * ;
|
use crate :: data_manager :: * ;
|
||||||
|
@ -39,12 +39,7 @@ fn add_style_provider ( _ : & Application ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_window ( application : & Application ) {
|
fn show_window ( application : & Application ) {
|
||||||
let window = leak (
|
let window = leak ( Window :: new (application) ) ;
|
||||||
ApplicationWindow :: builder ()
|
|
||||||
. application (application)
|
|
||||||
. title ("Zoödex")
|
|
||||||
. build ()
|
|
||||||
) ;
|
|
||||||
|
|
||||||
spawn_future_local ( async move {
|
spawn_future_local ( async move {
|
||||||
async_result_context ! (
|
async_result_context ! (
|
||||||
|
@ -57,7 +52,7 @@ fn show_window ( application : & Application ) {
|
||||||
data_manager . get_film_details (film_uuid) . await . unwrap ()
|
data_manager . get_film_details (film_uuid) . await . unwrap ()
|
||||||
} ) ,
|
} ) ,
|
||||||
) ;
|
) ;
|
||||||
window . set_visible (true) ;
|
window . show () ;
|
||||||
|
|
||||||
let collection = data_manager . get_collection_overview () . await ? ;
|
let collection = data_manager . get_collection_overview () . await ? ;
|
||||||
ui . render_collection_overview (collection) . await ;
|
ui . render_collection_overview (collection) . await ;
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub struct UI {
|
||||||
|
|
||||||
impl UI {
|
impl UI {
|
||||||
pub fn new (
|
pub fn new (
|
||||||
window : & 'static ApplicationWindow ,
|
window : & 'static Window ,
|
||||||
get_film_details : impl Fn (String) -> BoxFuture < 'static , FilmDetails > + 'static ,
|
get_film_details : impl Fn (String) -> BoxFuture < 'static , FilmDetails > + 'static ,
|
||||||
) -> UI {
|
) -> UI {
|
||||||
let get_film_details = leak (get_film_details) ;
|
let get_film_details = leak (get_film_details) ;
|
||||||
|
@ -54,12 +54,12 @@ impl UI {
|
||||||
& format ! ( "Release date: {}" , film_details . release_date ) ,
|
& format ! ( "Release date: {}" , film_details . release_date ) ,
|
||||||
) ) . as_ref () ,
|
) ) . as_ref () ,
|
||||||
) ,
|
) ,
|
||||||
) . present ( Some (window) )
|
) . present ( Some ( & window . libadwaita_window ) )
|
||||||
|
|
||||||
} ) ;
|
} ) ;
|
||||||
} ) ;
|
} ) ;
|
||||||
let series_component = CollatableMediaContainer :: <SeriesAdapter> :: new (
|
let series_component = CollatableMediaContainer :: <SeriesAdapter> :: new (
|
||||||
|series| dialog ! () . present ( Some (window) ) ,
|
|series| dialog ! () . present ( Some ( & window . libadwaita_window ) ) ,
|
||||||
) ;
|
) ;
|
||||||
let switched = view_stack ! (
|
let switched = view_stack ! (
|
||||||
( "Films" , "camera-video-symbolic" , films_component . get_widget () ) ,
|
( "Films" , "camera-video-symbolic" , films_component . get_widget () ) ,
|
||||||
|
@ -69,7 +69,7 @@ impl UI {
|
||||||
& view_switcher ! ( @ policy : Wide ; & switched ) ,
|
& view_switcher ! ( @ policy : Wide ; & switched ) ,
|
||||||
) ;
|
) ;
|
||||||
|
|
||||||
window . set_content ( Some (
|
window . libadwaita_window . set_content ( Some (
|
||||||
& toolbar_view ! ( @ top_bar : & header_bar ; & switched ) ,
|
& 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 () }
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue