zoodex/src/ui/utility.rs

98 lines
2.6 KiB
Rust
Raw Normal View History

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
2024-11-20 16:32:37 +01:00
} } }
macro_rules ! g_box { (
$ ( @ orientation : $ orientation : expr , ) ?
$ ( @ halign : $ halign : expr , ) ?
$ ( @ valign : $ valign : expr , ) ?
$ ( @ spacing : $ spacing : 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_widget_name ( & $ widget_name ) ; ) ?
$ ( container . set_css_classes ( & $ css_classes ) ; ) ?
$ ( container . append ( & $ child ) ; ) *
2024-11-20 16:32:37 +01:00
container
} } }
macro_rules ! view_stack { (
2024-11-20 16:32:37 +01:00
$ ( $ title : expr , $ icon : expr , $ widget : expr , ) *
) => { {
let container = libadwaita :: ViewStack :: new () ;
2024-11-20 16:32:37 +01:00
$ ( container . add_titled_with_icon ( $ widget , None , $ title , $ icon ) ; ) *
container
} } }
macro_rules ! list_box { ( $ ( $ child : expr ) , * $ (,) ? ) => { {
let container = gtk4 :: ListBox :: new () ;
$ ( 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 ! vertically_filling { ( $ child : expr ) => {
g_box ! (
@ orientation : gtk4 :: Orientation :: Vertical ,
$ child ,
libadwaita :: Bin :: builder ()
2024-11-20 16:32:37 +01:00
. css_name ("filler")
. vexpand (true)
. build () ,
)
} }
2024-11-20 16:32:37 +01:00
pub (crate) use {
label ,
g_box ,
view_stack ,
list_box ,
split_button ,
popover ,
icon ,
vertically_filling ,
} ;