2026-01-02 13:41:27 +01:00
|
|
|
use gtk4 :: Widget ;
|
|
|
|
|
use gtk4 :: Orientation :: * ;
|
|
|
|
|
use gtk4 :: prelude :: * ;
|
|
|
|
|
use libadwaita :: Bin ;
|
2025-02-12 14:32:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-02 13:41:27 +01:00
|
|
|
// Convenience function to conditionally append child to a widget
|
2024-11-20 16:32:37 +01:00
|
|
|
|
2026-01-02 13:41:27 +01:00
|
|
|
pub trait OptChildExt {
|
|
|
|
|
fn append_opt ( & self , child : & Option < impl IsA <Widget> > ) ;
|
2025-02-07 15:19:41 +01:00
|
|
|
}
|
2024-11-20 16:32:37 +01:00
|
|
|
|
2026-01-02 13:41:27 +01:00
|
|
|
impl OptChildExt for gtk4 :: Box {
|
|
|
|
|
fn append_opt ( & self , child : & Option < impl IsA <Widget> > ) {
|
|
|
|
|
if let Some (child) = child {
|
|
|
|
|
self . append (child) ;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-31 15:34:09 +01:00
|
|
|
|
2025-01-31 16:24:22 +01:00
|
|
|
|
2025-01-31 17:38:52 +01:00
|
|
|
|
2026-01-02 13:41:27 +01:00
|
|
|
// The `view` macro from Relm4 as an expression instead of a variable declaration
|
2025-02-12 14:32:16 +01:00
|
|
|
|
2026-01-02 13:41:27 +01:00
|
|
|
macro_rules ! view_expr { ( $ ( $ contents : tt ) * ) => { {
|
|
|
|
|
relm4_macros :: view ! { outer = $ ( $ contents ) * }
|
|
|
|
|
outer
|
2025-02-12 14:32:16 +01:00
|
|
|
} } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-02 13:41:27 +01:00
|
|
|
pub fn vertical_filler ( child : & impl IsA <Widget> ) -> gtk4 :: Box {
|
|
|
|
|
view_expr ! {
|
|
|
|
|
gtk4 :: Box {
|
|
|
|
|
set_orientation : Vertical ,
|
|
|
|
|
append : child ,
|
|
|
|
|
append : & view_expr ! {
|
|
|
|
|
Bin { set_vexpand : true }
|
|
|
|
|
} ,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-02-12 14:32:16 +01:00
|
|
|
|
2025-01-31 18:11:06 +01:00
|
|
|
|
|
|
|
|
|
2025-02-04 14:45:57 +01:00
|
|
|
macro_rules ! pango_attributes { (
|
2026-01-02 13:41:27 +01:00
|
|
|
$ ( scale : $ scale : expr ) ?
|
|
|
|
|
$ ( , weight : $ weight : expr $ (,) ? ) ?
|
2025-02-04 14:45:57 +01:00
|
|
|
) => { {
|
|
|
|
|
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
|
|
|
|
|
} } }
|
|
|
|
|
|
2024-11-20 16:32:37 +01:00
|
|
|
|
|
|
|
|
|
2025-02-18 17:40:37 +01:00
|
|
|
# [ allow (unused_imports) ] pub (crate) use {
|
2025-02-12 14:32:16 +01:00
|
|
|
pango_attributes ,
|
2026-01-02 13:41:27 +01:00
|
|
|
view_expr ,
|
2025-01-31 11:38:06 +01:00
|
|
|
} ;
|