180 lines
5.2 KiB
Rust
180 lines
5.2 KiB
Rust
macro_rules ! label { (
|
|
$ ( @ hexpand : $ hexpand : expr ;) ?
|
|
$ ( @ vexpand : $ vexpand : expr ; ) ?
|
|
$ ( @ halign : $ halign : expr ; ) ?
|
|
$ ( @ valign : $ valign : 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
|
|
} } }
|
|
|
|
macro_rules ! g_box { (
|
|
$ ( @ orientation : $ orientation : expr ; ) ?
|
|
$ ( @ halign : $ halign : expr ; ) ?
|
|
$ ( @ valign : $ valign : expr ; ) ?
|
|
$ ( @ spacing : $ spacing : expr ; ) ?
|
|
$ ( @ margin_top : $ margin_top : expr ; ) ?
|
|
$ ( @ margin_bottom : $ margin_bottom : expr ; ) ?
|
|
$ ( @ widget_name : $ widget_name : expr ; ) ?
|
|
$ ( @ css_classes : $ css_classes : expr ; ) ?
|
|
$ ( $ child : expr ) , * $ (,) ?
|
|
) => { {
|
|
let container = gtk4 :: Box :: builder () . build () ;
|
|
$ ( container . set_orientation ( $ orientation ) ; ) ?
|
|
$ ( container . set_halign ( $ halign ) ; ) ?
|
|
$ ( container . set_valign ( $ valign ) ; ) ?
|
|
$ ( container . set_spacing ( $ spacing ) ; ) ?
|
|
$ ( container . set_margin_top ( $ margin_top ) ; ) ?
|
|
$ ( container . set_margin_bottom ( $ margin_bottom ) ; ) ?
|
|
$ ( container . set_widget_name ( & $ widget_name ) ; ) ?
|
|
$ ( container . set_css_classes ( & $ css_classes ) ; ) ?
|
|
$ ( container . append ( & $ child ) ; ) *
|
|
container
|
|
} } }
|
|
|
|
macro_rules ! view_stack { (
|
|
$ ( ( $ title : expr , $ icon : expr , $ widget : expr $ (,) ? ) ) , * $ (,) ?
|
|
) => { {
|
|
let container = libadwaita :: ViewStack :: new () ;
|
|
$ ( container . add_titled_with_icon ( $ widget , None , $ title , $ icon ) ; ) *
|
|
container
|
|
} } }
|
|
|
|
macro_rules ! list_box { (
|
|
$ ( @ connect_row_activated : $ connect_row_activated : expr ; ) ?
|
|
$ ( $ child : expr ) , * $ (,) ?
|
|
) => { {
|
|
let container = gtk4 :: ListBox :: new () ;
|
|
$ ( container . connect_row_activated ( $ connect_row_activated ) ; ) ?
|
|
$ ( container . append ( & $ child ) ; ) *
|
|
container
|
|
} } }
|
|
|
|
macro_rules ! split_button { (
|
|
$ ( @ popover : $ popover : expr ; ) ?
|
|
$ child : expr $ (,) ?
|
|
) => { {
|
|
let widget = libadwaita :: SplitButton :: new () ;
|
|
$ ( widget . set_popover ( Some ( & $ popover ) ) ; ) ?
|
|
widget . set_child ( Some ( & $ child ) ) ;
|
|
widget
|
|
} } }
|
|
|
|
macro_rules ! popover { (
|
|
$ ( @ css_classes : $ css_classes : expr ; ) ?
|
|
$ child : expr $ (,) ?
|
|
) => { {
|
|
let widget = gtk4 :: Popover :: new () ;
|
|
$ ( widget . set_css_classes ( & $ css_classes ) ; ) ?
|
|
widget . set_child ( Some ( & $ child ) ) ;
|
|
widget
|
|
} } }
|
|
|
|
macro_rules ! icon { ( $ icon_name : expr ) => {
|
|
gtk4 :: Image :: from_icon_name ( $ icon_name )
|
|
} }
|
|
|
|
macro_rules ! scrolled_window { (
|
|
$ ( @ propagate_natural_height : $ propagate_natural_height : expr ; ) ?
|
|
$ child : expr $ (,) ?
|
|
) => { {
|
|
let widget = gtk4 :: ScrolledWindow :: new () ;
|
|
$ ( widget . set_propagate_natural_height ( $ propagate_natural_height ) ; ) ?
|
|
widget . set_child ( Some ( & $ child ) ) ;
|
|
widget
|
|
} } }
|
|
|
|
macro_rules ! flow_box { (
|
|
$ ( @ orientation : $ orientation : expr ; ) ?
|
|
$ ( @ homogeneous : $ homogeneous : expr ; ) ?
|
|
$ ( @ selection_mode : $ selection_mode : expr ; ) ?
|
|
) => { {
|
|
let widget = gtk4 :: FlowBox :: new () ;
|
|
$ ( widget . set_orientation ( $ orientation ) ; ) ?
|
|
$ ( widget . set_homogeneous ( $ homogeneous ) ; ) ?
|
|
$ ( widget . set_selection_mode ( $ selection_mode ) ; ) ?
|
|
widget
|
|
} } }
|
|
|
|
macro_rules ! view_switcher { (
|
|
$ ( @ policy : $ policy : expr ; ) ?
|
|
$ stack : expr $ (,) ?
|
|
) => { {
|
|
let widget = libadwaita :: ViewSwitcher :: new () ;
|
|
$ ( widget . set_policy ( $ policy ) ; ) ?
|
|
widget . set_stack ( Some ( & $ stack ) ) ;
|
|
widget
|
|
} } }
|
|
|
|
macro_rules ! header_bar { ( $ title_widget : expr $ (,) ? ) => { {
|
|
let widget = libadwaita :: HeaderBar :: new () ;
|
|
widget . set_title_widget ( Some ( & $ title_widget ) ) ;
|
|
widget
|
|
} } }
|
|
|
|
macro_rules ! bin { ( $ ( @ vexpand : $ vexpand : expr ; ) ? ) => { {
|
|
let widget = libadwaita :: Bin :: new () ;
|
|
$ ( widget . set_vexpand ( $ vexpand ) ; ) ?
|
|
widget
|
|
} } }
|
|
|
|
macro_rules ! application_window { (
|
|
@ application : $ application : expr ;
|
|
@ title : $ title : expr ;
|
|
$ content : expr $ (,) ?
|
|
) => { {
|
|
use libadwaita :: prelude :: * ;
|
|
|
|
let window = libadwaita :: ApplicationWindow :: new ( $ application ) ;
|
|
window . set_title ( Some ( $ title ) ) ;
|
|
window . set_content ( Some ( & $ content ) ) ;
|
|
window
|
|
} } }
|
|
|
|
macro_rules ! vertically_filling { ( $ child : expr ) => {
|
|
g_box ! (
|
|
@ orientation : gtk4 :: Orientation :: Vertical ;
|
|
$ child ,
|
|
bin ! ( @ vexpand : true ; ) ,
|
|
)
|
|
} }
|
|
|
|
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 {
|
|
label ,
|
|
g_box ,
|
|
view_stack ,
|
|
list_box ,
|
|
split_button ,
|
|
popover ,
|
|
icon ,
|
|
scrolled_window ,
|
|
flow_box ,
|
|
view_switcher ,
|
|
header_bar ,
|
|
bin ,
|
|
application_window ,
|
|
vertically_filling ,
|
|
pango_attributes ,
|
|
} ;
|