Introduce application_window UI macro

This commit is contained in:
Reinout Meliesie 2025-01-31 18:11:06 +01:00
parent eb10495670
commit 0ae516e898
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
2 changed files with 23 additions and 20 deletions

View file

@ -16,6 +16,7 @@ use crate :: {
collatable_container :: * ,
collection_view_stack :: * ,
component :: * ,
utility :: * ,
} ,
} ;
@ -35,10 +36,14 @@ impl UI {
& films_component , & series_component ) ;
let header_bar = ApplicationHeaderBar :: new ( & switch_component ) ;
let window = create_window (
application ,
header_bar . get_widget () ,
switch_component . get_widget () ,
let window = application_window ! (
@ application : application ,
@ title : "Zoödex" ,
g_box ! (
@ orientation : Vertical ,
* header_bar . get_widget () ,
* switch_component . get_widget () ,
) ,
) ;
UI { window , films_component , series_component }
@ -53,19 +58,3 @@ impl UI {
self . series_component . set_series ( collection . series ) ;
}
}
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 ()
}

View file

@ -124,6 +124,19 @@ macro_rules ! bin { ( $ ( @ vexpand : $ vexpand : expr ) ? $ (,) ? ) => { {
widget
} } }
macro_rules ! application_window { (
@ application : $ application : expr ,
@ title : $ title : expr ,
$ content : expr $ (,) ?
) => { {
use libadwaita :: prelude :: * ;
let window = libadwaita :: ApplicationWindow :: new ( $ application ) ;
window . set_title ( Some ( $ title ) ) ;
window . set_content ( Some ( & $ content ) ) ;
window
} } }
macro_rules ! vertically_filling { ( $ child : expr ) => {
g_box ! (
@ orientation : gtk4 :: Orientation :: Vertical ,
@ -147,5 +160,6 @@ pub (crate) use {
view_switcher ,
header_bar ,
bin ,
application_window ,
vertically_filling ,
} ;