zoodex/src/ui/utility.rs

66 lines
1.5 KiB
Rust
Raw Normal View History

use gtk4 :: Widget ;
use gtk4 :: Orientation :: * ;
use gtk4 :: prelude :: * ;
use libadwaita :: Bin ;
// Convenience function to conditionally append child to a widget
2024-11-20 16:32:37 +01:00
pub trait OptChildExt {
fn append_opt ( & self , child : & Option < impl IsA <Widget> > ) ;
}
2024-11-20 16:32:37 +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 16:24:22 +01:00
2025-01-31 17:38:52 +01:00
// The `view` macro from Relm4 as an expression instead of a variable declaration
macro_rules ! view_expr { ( $ ( $ contents : tt ) * ) => { {
relm4_macros :: view ! { outer = $ ( $ contents ) * }
outer
} } }
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-01-31 18:11:06 +01:00
2025-02-04 14:45:57 +01:00
macro_rules ! pango_attributes { (
$ ( 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
# [ allow (unused_imports) ] pub (crate) use {
pango_attributes ,
view_expr ,
} ;