From ed18e738eb512e0ed29e6da38ad57397c23ea91d Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Tue, 4 Feb 2025 14:45:57 +0100 Subject: [PATCH] Fix collection item title Pango syntax --- src/ui/collatable_container/collated_grid.rs | 10 +++++----- src/ui/utility.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ui/collatable_container/collated_grid.rs b/src/ui/collatable_container/collated_grid.rs index c7aeeb9..4150bd7 100644 --- a/src/ui/collatable_container/collated_grid.rs +++ b/src/ui/collatable_container/collated_grid.rs @@ -1,9 +1,9 @@ use { gtk4 :: { * , - Align :: * , - Orientation :: * , - gdk :: Texture , + Align :: * , Orientation :: * , + gdk :: * , + pango :: { * , Weight :: * } , prelude :: * , } , std :: { cell :: * , iter :: * , path :: Path } , @@ -177,8 +177,8 @@ fn create_collection_item ( container . append ( & Label :: builder () - . label ( format ! ( "{}" , name ) ) - . use_markup (true) + . 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 diff --git a/src/ui/utility.rs b/src/ui/utility.rs index 105dff7..45d76bb 100644 --- a/src/ui/utility.rs +++ b/src/ui/utility.rs @@ -145,6 +145,20 @@ macro_rules ! vertically_filling { ( $ child : expr ) => { ) } } +macro_rules ! pango_attributes { ( + $ ( @ scale : $ scale : expr , ) ? + $ ( @ weight : $ weight : expr , ) ? +) => { { + let attributes = gtk4 :: pango :: AttrList :: new () ; + # [ allow (unused_mut) ] let mut font_description = gtk4 :: pango :: FontDescription :: new () ; + + $ ( attributes . insert ( gtk4 :: pango :: AttrFloat :: new_scale ( $ scale ) ) ; ) ? + $ ( font_description . set_weight ( $ weight ) ; ) ? + + attributes . insert ( gtk4 :: pango :: AttrFontDesc :: new ( & font_description ) ) ; + attributes +} } } + pub (crate) use { @@ -162,4 +176,5 @@ pub (crate) use { bin , application_window , vertically_filling , + pango_attributes , } ;