g_box UI macro can now take inline conditional children

This commit is contained in:
Reinout Meliesie 2025-02-07 15:19:41 +01:00
commit a9ec7bdcc9
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
2 changed files with 81 additions and 53 deletions

View file

@ -22,29 +22,55 @@ macro_rules ! 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 ! 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
} } ;
(
@ option_children ;
$ ( @ 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 ) ; ) ?
$ ( if let Some (child) = $ child { container . append (child) ; } ) *
container
} } ;
}
macro_rules ! view_stack { (
$ ( ( $ title : expr , $ icon : expr , $ widget : expr $ (,) ? ) ) , * $ (,) ?