From 0ae516e898803b7b755b0570614581772d7650b9 Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Fri, 31 Jan 2025 18:11:06 +0100 Subject: [PATCH] Introduce application_window UI macro --- src/ui/mod.rs | 29 +++++++++-------------------- src/ui/utility.rs | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 722fa33..4877a7e 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -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 () -} diff --git a/src/ui/utility.rs b/src/ui/utility.rs index 928dc54..105dff7 100644 --- a/src/ui/utility.rs +++ b/src/ui/utility.rs @@ -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 , } ;