From cd45d4303bd2a7c5424b78306538cbc85305b01a Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Fri, 7 Feb 2025 13:54:44 +0100 Subject: [PATCH] Use label UI macro in collection item rendering --- src/ui/collatable_container/collated_grid.rs | 44 +++++++++----------- src/ui/utility.rs | 14 +++++-- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/ui/collatable_container/collated_grid.rs b/src/ui/collatable_container/collated_grid.rs index 1847864..7c42e8b 100644 --- a/src/ui/collatable_container/collated_grid.rs +++ b/src/ui/collatable_container/collated_grid.rs @@ -168,35 +168,29 @@ async fn create_collection_item ( Texture :: from_filename (poster_file_path) . unwrap () ) . await . unwrap () ; - container . append ( - & image ! ( - @ paintable : & poster_texture ; - @ width_request : 300 ; - @ height_request : 300 ; - @ margin_bottom : 10 ; - ) - ) ; + container . append ( & image ! ( + @ paintable : & poster_texture ; + @ width_request : 300 ; + @ height_request : 300 ; + @ margin_bottom : 10 ; + ) ) ; } - container . append ( - & Label :: builder () - . label (name) - . attributes ( & pango_attributes ! ( @ scale : SCALE_LARGE ; @ weight : Bold ; ) ) - . justify ( Justification :: Center ) - . wrap (true) - . max_width_chars (1) // Not the actual limit, used instead to wrap more aggressively - . build () - ) ; + container . append ( & label ! ( + @ justify : Justification :: Center ; + @ wrap : true ; + @ max_width_chars : 1 ; // Not the actual limit, used instead to wrap more aggressively + @ attributes : & pango_attributes ! ( @ scale : SCALE_LARGE ; @ weight : Bold ; ) ; + name , + ) ) ; if let Some (original_name) = original_name { - container . append ( - & Label :: builder () - . label (original_name) - . justify ( Justification :: Center ) - . wrap (true) - . max_width_chars (1) // Not the actual limit, used instead to wrap more aggressively - . build () - ) ; + container . append ( & label ! ( + @ justify : Justification :: Center ; + @ wrap : true ; + @ max_width_chars : 1 ; // Not the actual limit, used instead to wrap more aggressively + original_name , + ) ) ; } container . append (details_widget) ; diff --git a/src/ui/utility.rs b/src/ui/utility.rs index 4c2fca7..4b2a9c5 100644 --- a/src/ui/utility.rs +++ b/src/ui/utility.rs @@ -1,16 +1,24 @@ macro_rules ! label { ( - $ ( @ hexpand : $ hexpand : expr ;) ? + $ ( @ hexpand : $ hexpand : expr ; ) ? $ ( @ vexpand : $ vexpand : expr ; ) ? $ ( @ halign : $ halign : expr ; ) ? $ ( @ valign : $ valign : expr ; ) ? - $ label : expr $ (,) ? + $ ( @ justify : $ justify : expr ; ) ? + $ ( @ wrap : $ wrap : expr ; ) ? + $ ( @ max_width_chars : $ max_width_chars : expr ; ) ? + $ ( @ attributes : $ attributes : expr ; ) ? + $ ( $ label : expr ) ? $ (,) ? ) => { { let label = gtk4 :: Label :: builder () . build () ; $ ( label . set_hexpand ( $ hexpand ) ; ) ? $ ( label . set_vexpand ( $ vexpand ) ; ) ? $ ( label . set_halign ( $ halign ) ; ) ? $ ( label . set_valign ( $ valign ) ; ) ? - label . set_label ( $ label ) ; + $ ( label . set_label ( $ label ) ; ) ? + $ ( label . set_justify ( $ justify ) ; ) ? + $ ( label . set_max_width_chars ( $ max_width_chars ) ; ) ? + $ ( label . set_attributes ( Some ( $ attributes ) ) ; ) ? + $ ( label . set_wrap ( $ wrap ) ; ) ? label } } }