Use label UI macro in collection item rendering

This commit is contained in:
Reinout Meliesie 2025-02-07 13:54:44 +01:00
parent 38adb5f4b9
commit cd45d4303b
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
2 changed files with 30 additions and 28 deletions

View file

@ -168,35 +168,29 @@ async fn create_collection_item (
Texture :: from_filename (poster_file_path) . unwrap () Texture :: from_filename (poster_file_path) . unwrap ()
) . await . unwrap () ; ) . await . unwrap () ;
container . append ( container . append ( & image ! (
& image ! ( @ paintable : & poster_texture ;
@ paintable : & poster_texture ; @ width_request : 300 ;
@ width_request : 300 ; @ height_request : 300 ;
@ height_request : 300 ; @ margin_bottom : 10 ;
@ margin_bottom : 10 ; ) ) ;
)
) ;
} }
container . append ( container . append ( & label ! (
& Label :: builder () @ justify : Justification :: Center ;
. label (name) @ wrap : true ;
. attributes ( & pango_attributes ! ( @ scale : SCALE_LARGE ; @ weight : Bold ; ) ) @ max_width_chars : 1 ; // Not the actual limit, used instead to wrap more aggressively
. justify ( Justification :: Center ) @ attributes : & pango_attributes ! ( @ scale : SCALE_LARGE ; @ weight : Bold ; ) ;
. wrap (true) name ,
. max_width_chars (1) // Not the actual limit, used instead to wrap more aggressively ) ) ;
. build ()
) ;
if let Some (original_name) = original_name { if let Some (original_name) = original_name {
container . append ( container . append ( & label ! (
& Label :: builder () @ justify : Justification :: Center ;
. label (original_name) @ wrap : true ;
. justify ( Justification :: Center ) @ max_width_chars : 1 ; // Not the actual limit, used instead to wrap more aggressively
. wrap (true) original_name ,
. max_width_chars (1) // Not the actual limit, used instead to wrap more aggressively ) ) ;
. build ()
) ;
} }
container . append (details_widget) ; container . append (details_widget) ;

View file

@ -1,16 +1,24 @@
macro_rules ! label { ( macro_rules ! label { (
$ ( @ hexpand : $ hexpand : expr ;) ? $ ( @ hexpand : $ hexpand : expr ; ) ?
$ ( @ vexpand : $ vexpand : expr ; ) ? $ ( @ vexpand : $ vexpand : expr ; ) ?
$ ( @ halign : $ halign : expr ; ) ? $ ( @ halign : $ halign : expr ; ) ?
$ ( @ valign : $ valign : 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 () ; let label = gtk4 :: Label :: builder () . build () ;
$ ( label . set_hexpand ( $ hexpand ) ; ) ? $ ( label . set_hexpand ( $ hexpand ) ; ) ?
$ ( label . set_vexpand ( $ vexpand ) ; ) ? $ ( label . set_vexpand ( $ vexpand ) ; ) ?
$ ( label . set_halign ( $ halign ) ; ) ? $ ( label . set_halign ( $ halign ) ; ) ?
$ ( label . set_valign ( $ valign ) ; ) ? $ ( 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 label
} } } } } }