zoodex/src/ui/mod.rs

72 lines
1.8 KiB
Rust
Raw Normal View History

mod application_header_bar ;
mod collatable_container ;
mod collection_view_stack ;
mod component ;
2024-11-20 16:32:37 +01:00
mod utility ;
use {
gtk4 :: { Orientation :: * , prelude :: * } ,
libadwaita :: * ,
} ;
2024-11-20 16:32:37 +01:00
use crate :: {
collection :: * ,
ui :: {
application_header_bar :: * ,
collatable_container :: * ,
collection_view_stack :: * ,
component :: * ,
} ,
} ;
2024-11-20 16:32:37 +01:00
pub struct UI {
window : ApplicationWindow ,
films_component : CollatableFilmsContainer ,
series_component : CollatableSeriesContainer ,
2024-11-20 16:32:37 +01:00
}
impl UI {
pub fn new ( application : & Application ) -> UI {
let films_component = CollatableFilmsContainer :: new ( vec ! () ) ;
let series_component = CollatableSeriesContainer :: new ( vec ! () ) ;
let switch_component = CollectionViewStack :: new (
& films_component , & series_component ) ;
let header_bar = ApplicationHeaderBar :: new ( & switch_component ) ;
let window = create_window (
application ,
header_bar . get_widget () ,
switch_component . get_widget () ,
2024-11-20 16:32:37 +01:00
) ;
UI { window , films_component , series_component }
2024-11-20 16:32:37 +01:00
}
pub fn show_window ( & self ) { self . window . set_visible (true) }
2024-11-29 21:06:14 +01:00
pub fn close_window ( & self ) { self . window . close () }
pub fn render_collection ( & self , collection : Collection ) {
self . films_component . set_films ( collection . films ) ;
self . series_component . set_series ( collection . series ) ;
2024-11-20 16:32:37 +01:00
}
}
fn create_window (
application : & Application ,
header_bar : & HeaderBar ,
collection_view_stack : & ViewStack ,
) -> ApplicationWindow {
let content = gtk4 :: Box :: builder () . orientation (Vertical) . build () ;
content . append (header_bar) ;
content . append (collection_view_stack) ;
ApplicationWindow :: builder ()
. application (application)
. content ( & content )
. title ("Zoödex")
. build ()
}