UI macro syntax now differentiates at-properties from arguments

This commit is contained in:
Reinout Meliesie 2025-02-04 15:02:58 +01:00
parent ed18e738eb
commit ce70725b60
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
8 changed files with 80 additions and 80 deletions

View file

@ -9,7 +9,7 @@ pub struct ApplicationHeaderBar { widget : HeaderBar }
impl ApplicationHeaderBar { impl ApplicationHeaderBar {
pub fn new ( collection_view_stack : & CollectionViewStack ) -> Self { pub fn new ( collection_view_stack : & CollectionViewStack ) -> Self {
let widget = header_bar ! ( let widget = header_bar ! (
view_switcher ! ( @ policy : Wide , collection_view_stack . get_widget () ) , view_switcher ! ( @ policy : Wide ; collection_view_stack . get_widget () ) ,
) ; ) ;
Self { widget } Self { widget }
} }

View file

@ -25,9 +25,9 @@ pub struct CollatedSeriesGrid {
impl CollatedFilmsGrid { impl CollatedFilmsGrid {
pub fn new ( films : Vec <Film> , sorting : FilmsSorting ) -> Self { pub fn new ( films : Vec <Film> , sorting : FilmsSorting ) -> Self {
let grid_widget = flow_box ! ( let grid_widget = flow_box ! (
@ orientation : Horizontal , @ orientation : Horizontal ;
@ homogeneous : true , @ homogeneous : true ;
@ selection_mode : SelectionMode :: None , @ selection_mode : SelectionMode :: None ;
) ; ) ;
let film_widget_pairs = RefCell :: new ( vec ! () ) ; let film_widget_pairs = RefCell :: new ( vec ! () ) ;
@ -78,9 +78,9 @@ impl CollatedFilmsGrid {
impl CollatedSeriesGrid { impl CollatedSeriesGrid {
pub fn new ( series : Vec <Series> , sorting : SeriesSorting ) -> Self { pub fn new ( series : Vec <Series> , sorting : SeriesSorting ) -> Self {
let grid_widget = flow_box ! ( let grid_widget = flow_box ! (
@ orientation : Horizontal , @ orientation : Horizontal ;
@ homogeneous : true , @ homogeneous : true ;
@ selection_mode : SelectionMode :: None , @ selection_mode : SelectionMode :: None ;
) ; ) ;
let series_widget_pairs = RefCell :: new ( vec ! () ) ; let series_widget_pairs = RefCell :: new ( vec ! () ) ;
@ -178,7 +178,7 @@ fn create_collection_item (
container . append ( container . append (
& Label :: builder () & Label :: builder ()
. label (name) . label (name)
. attributes ( & pango_attributes ! ( @ scale : SCALE_LARGE , @ weight : Bold , ) ) . attributes ( & pango_attributes ! ( @ scale : SCALE_LARGE ; @ weight : Bold ; ) )
. justify ( Justification :: Center ) . justify ( Justification :: Center )
. wrap (true) . wrap (true)
. max_width_chars (1) // Not the actual limit, used instead to wrap more aggressively . max_width_chars (1) // Not the actual limit, used instead to wrap more aggressively
@ -203,18 +203,18 @@ fn create_collection_item (
fn create_film_details ( film : & Film ) -> Box { fn create_film_details ( film : & Film ) -> Box {
g_box ! ( g_box ! (
@ orientation : Horizontal , @ orientation : Horizontal ;
@ halign : Center , @ halign : Center ;
@ spacing : 20 , @ spacing : 20 ;
label ! ( film . release_date . as_str () ) , label ! ( film . release_date . as_str () ) ,
label ! ( format ! ( "{}m" , film . runtime_minutes ) . as_str () ) , label ! ( format ! ( "{}m" , film . runtime_minutes ) . as_str () ) ,
) )
} }
fn create_series_details ( series : & Series ) -> Box { fn create_series_details ( series : & Series ) -> Box {
g_box ! ( g_box ! (
@ orientation : Horizontal , @ orientation : Horizontal ;
@ halign : Center , @ halign : Center ;
@ spacing : 20 , @ spacing : 20 ;
// TODO // TODO
label ! ("????") , label ! ("????") ,
) )

View file

@ -20,11 +20,11 @@ impl FilmCollationMenu {
let film_sort_button = FilmSortButton :: new (on_sort) ; let film_sort_button = FilmSortButton :: new (on_sort) ;
let widget = g_box ! ( let widget = g_box ! (
@ orientation : Horizontal , @ orientation : Horizontal ;
@ halign : Center , @ halign : Center ;
@ spacing : 20 , @ spacing : 20 ;
@ widget_name : "film-collation-menu" , @ widget_name : "film-collation-menu" ;
@ css_classes : [ "toolbar" ] , @ css_classes : [ "toolbar" ] ;
* film_sort_button . get_widget () , * film_sort_button . get_widget () ,
) ; ) ;
@ -36,11 +36,11 @@ impl SeriesCollationMenu {
let series_sort_button = SeriesSortButton :: new (on_sort) ; let series_sort_button = SeriesSortButton :: new (on_sort) ;
let widget = g_box ! ( let widget = g_box ! (
@ orientation : Horizontal , @ orientation : Horizontal ;
@ halign : Center , @ halign : Center ;
@ spacing : 20 , @ spacing : 20 ;
@ widget_name : "series-collation-menu" , @ widget_name : "series-collation-menu" ;
@ css_classes : [ "toolbar" ] , @ css_classes : [ "toolbar" ] ;
* series_sort_button . get_widget () , * series_sort_button . get_widget () ,
) ; ) ;

View file

@ -32,28 +32,28 @@ impl FilmSortButton {
let widget = split_button ! ( let widget = split_button ! (
@ popover : popover ! ( @ popover : popover ! (
@ css_classes : [ "menu" ] , @ css_classes : [ "menu" ] ;
list_box ! ( list_box ! (
@ connect_row_activated : move | _ , row | { @ connect_row_activated : move | _ , row | {
on_film_sort_activated ( row , previous_sorting , & on_sort , sort_icons ) ; on_film_sort_activated ( row , previous_sorting , & on_sort , sort_icons ) ;
} , } ;
g_box ! ( g_box ! (
@ orientation : Horizontal , @ spacing : 20 , @ orientation : Horizontal ; @ spacing : 20 ;
label ! ( @ hexpand : true , @ halign : Start , "Name" ) , label ! ( @ hexpand : true ; @ halign : Start ; "Name" ) ,
sort_icons [0] , sort_icons [0] ,
) , ) ,
g_box ! ( g_box ! (
@ orientation : Horizontal , @ spacing : 20 , @ orientation : Horizontal ; @ spacing : 20 ;
label ! ( @ hexpand : true , @ halign : Start , "Release date" ) , label ! ( @ hexpand : true ; @ halign : Start ; "Release date" ) ,
sort_icons [1] , sort_icons [1] ,
) , ) ,
g_box ! ( g_box ! (
@ orientation : Horizontal , @ spacing : 20 , @ orientation : Horizontal ; @ spacing : 20 ;
label ! ( @ hexpand : true , @ halign : Start , "Runtime" ) , label ! ( @ hexpand : true ; @ halign : Start ; "Runtime" ) ,
sort_icons [2] , sort_icons [2] ,
) , ) ,
) , ) ,
) , ) ;
label ! ("Sort") , label ! ("Sort") ,
) ; ) ;
@ -71,23 +71,23 @@ impl SeriesSortButton {
let widget = split_button ! ( let widget = split_button ! (
@ popover : popover ! ( @ popover : popover ! (
@ css_classes : [ "menu" ] , @ css_classes : [ "menu" ] ;
list_box ! ( list_box ! (
@ connect_row_activated : move | _ , row | { @ connect_row_activated : move | _ , row | {
on_series_sort_activated ( row , previous_sorting , & on_sort , sort_icons ) ; on_series_sort_activated ( row , previous_sorting , & on_sort , sort_icons ) ;
} , } ;
g_box ! ( g_box ! (
@ orientation : Horizontal , @ spacing : 20 , @ orientation : Horizontal ; @ spacing : 20 ;
label ! ( @ hexpand : true , @ halign : Start , "Name" ) , label ! ( @ hexpand : true ; @ halign : Start ; "Name" ) ,
sort_icons [0] , sort_icons [0] ,
) , ) ,
g_box ! ( g_box ! (
@ orientation : Horizontal , @ spacing : 20 , @ orientation : Horizontal ; @ spacing : 20 ;
label ! ( @ hexpand : true , @ halign : Start , "First release date" ) , label ! ( @ hexpand : true ; @ halign : Start ; "First release date" ) ,
sort_icons [1] , sort_icons [1] ,
) , ) ,
) , ) ,
) , ) ;
label ! ("Sort") , label ! ("Sort") ,
) ; ) ;

View file

@ -70,10 +70,10 @@ impl CollatableFilmsContainer {
collated_grid . set_sorting (sorting) ) ; collated_grid . set_sorting (sorting) ) ;
let widget = g_box ! ( let widget = g_box ! (
@ orientation : Vertical , @ orientation : Vertical ;
* film_collation_menu . get_widget () , * film_collation_menu . get_widget () ,
scrolled_window ! ( scrolled_window ! (
@ propagate_natural_height : true , @ propagate_natural_height : true ;
vertically_filling ! ( * collated_grid . get_widget () ) , vertically_filling ! ( * collated_grid . get_widget () ) ,
) , ) ,
) ; ) ;
@ -94,10 +94,10 @@ impl CollatableSeriesContainer {
} ) ; } ) ;
let widget = g_box ! ( let widget = g_box ! (
@ orientation : Vertical , @ orientation : Vertical ;
* series_collation_menu . get_widget () , * series_collation_menu . get_widget () ,
scrolled_window ! ( scrolled_window ! (
@ propagate_natural_height : true , @ propagate_natural_height : true ;
vertically_filling ! ( * collated_grid . get_widget () ) , vertically_filling ! ( * collated_grid . get_widget () ) ,
) , ) ,
) ; ) ;

View file

@ -12,8 +12,8 @@ impl CollectionViewStack {
series_container : & CollatableSeriesContainer , series_container : & CollatableSeriesContainer ,
) -> Self { ) -> Self {
let widget = view_stack ! ( let widget = view_stack ! (
"Films" , "camera-video-symbolic" , films_container . get_widget () , ( "Films" , "camera-video-symbolic" , films_container . get_widget () ) ,
"Series" , "video-display-symbolic" , series_container . get_widget () , ( "Series" , "video-display-symbolic" , series_container . get_widget () ) ,
) ; ) ;
Self { widget } Self { widget }

View file

@ -37,10 +37,10 @@ impl UI {
let header_bar = ApplicationHeaderBar :: new ( & switch_component ) ; let header_bar = ApplicationHeaderBar :: new ( & switch_component ) ;
let window = application_window ! ( let window = application_window ! (
@ application : application , @ application : application ;
@ title : "Zoödex" , @ title : "Zoödex" ;
g_box ! ( g_box ! (
@ orientation : Vertical , @ orientation : Vertical ;
* header_bar . get_widget () , * header_bar . get_widget () ,
* switch_component . get_widget () , * switch_component . get_widget () ,
) , ) ,

View file

@ -1,8 +1,8 @@
macro_rules ! label { ( macro_rules ! label { (
$ ( @ hexpand : $ hexpand : expr , ) ? $ ( @ hexpand : $ hexpand : expr ;) ?
$ ( @ vexpand : $ vexpand : expr , ) ? $ ( @ vexpand : $ vexpand : expr ; ) ?
$ ( @ halign : $ halign : expr , ) ? $ ( @ halign : $ halign : expr ; ) ?
$ ( @ valign : $ valign : expr , ) ? $ ( @ valign : $ valign : expr ; ) ?
$ label : expr $ (,) ? $ label : expr $ (,) ?
) => { { ) => { {
let label = gtk4 :: Label :: builder () . build () ; let label = gtk4 :: Label :: builder () . build () ;
@ -15,15 +15,15 @@ macro_rules ! label { (
} } } } } }
macro_rules ! g_box { ( macro_rules ! g_box { (
$ ( @ orientation : $ orientation : expr , ) ? $ ( @ orientation : $ orientation : expr ; ) ?
$ ( @ halign : $ halign : expr , ) ? $ ( @ halign : $ halign : expr ; ) ?
$ ( @ valign : $ valign : expr , ) ? $ ( @ valign : $ valign : expr ; ) ?
$ ( @ spacing : $ spacing : expr , ) ? $ ( @ spacing : $ spacing : expr ; ) ?
$ ( @ margin_top : $ margin_top : expr , ) ? $ ( @ margin_top : $ margin_top : expr ; ) ?
$ ( @ margin_bottom : $ margin_bottom : expr , ) ? $ ( @ margin_bottom : $ margin_bottom : expr ; ) ?
$ ( @ widget_name : $ widget_name : expr , ) ? $ ( @ widget_name : $ widget_name : expr ; ) ?
$ ( @ css_classes : $ css_classes : expr , ) ? $ ( @ css_classes : $ css_classes : expr ; ) ?
$ ( $ child : expr ) , + $ (,) ? $ ( $ child : expr ) , * $ (,) ?
) => { { ) => { {
let container = gtk4 :: Box :: builder () . build () ; let container = gtk4 :: Box :: builder () . build () ;
$ ( container . set_orientation ( $ orientation ) ; ) ? $ ( container . set_orientation ( $ orientation ) ; ) ?
@ -39,7 +39,7 @@ macro_rules ! g_box { (
} } } } } }
macro_rules ! view_stack { ( macro_rules ! view_stack { (
$ ( $ title : expr , $ icon : expr , $ widget : expr , ) * $ ( ( $ title : expr , $ icon : expr , $ widget : expr $ (,) ? ) ) , * $ (,) ?
) => { { ) => { {
let container = libadwaita :: ViewStack :: new () ; let container = libadwaita :: ViewStack :: new () ;
$ ( container . add_titled_with_icon ( $ widget , None , $ title , $ icon ) ; ) * $ ( container . add_titled_with_icon ( $ widget , None , $ title , $ icon ) ; ) *
@ -47,17 +47,17 @@ macro_rules ! view_stack { (
} } } } } }
macro_rules ! list_box { ( macro_rules ! list_box { (
$ ( @ connect_row_activated : $ connect_row_activated : expr , ) ? $ ( @ connect_row_activated : $ connect_row_activated : expr ; ) ?
$ ( $ child : expr ) , + $ (,) ? $ ( $ child : expr ) , * $ (,) ?
) => { { ) => { {
let container = gtk4 :: ListBox :: new () ; let container = gtk4 :: ListBox :: new () ;
$ ( container . connect_row_activated ( $ connect_row_activated ) ; ) ? $ ( container . connect_row_activated ( $ connect_row_activated ) ; ) ?
$ ( container . append ( & $ child ) ; ) + $ ( container . append ( & $ child ) ; ) *
container container
} } } } } }
macro_rules ! split_button { ( macro_rules ! split_button { (
$ ( @ popover : $ popover : expr , ) ? $ ( @ popover : $ popover : expr ; ) ?
$ child : expr $ (,) ? $ child : expr $ (,) ?
) => { { ) => { {
let widget = libadwaita :: SplitButton :: new () ; let widget = libadwaita :: SplitButton :: new () ;
@ -67,7 +67,7 @@ macro_rules ! split_button { (
} } } } } }
macro_rules ! popover { ( macro_rules ! popover { (
$ ( @ css_classes : $ css_classes : expr , ) ? $ ( @ css_classes : $ css_classes : expr ; ) ?
$ child : expr $ (,) ? $ child : expr $ (,) ?
) => { { ) => { {
let widget = gtk4 :: Popover :: new () ; let widget = gtk4 :: Popover :: new () ;
@ -81,7 +81,7 @@ macro_rules ! icon { ( $ icon_name : expr ) => {
} } } }
macro_rules ! scrolled_window { ( macro_rules ! scrolled_window { (
$ ( @ propagate_natural_height : $ propagate_natural_height : expr , ) ? $ ( @ propagate_natural_height : $ propagate_natural_height : expr ; ) ?
$ child : expr $ (,) ? $ child : expr $ (,) ?
) => { { ) => { {
let widget = gtk4 :: ScrolledWindow :: new () ; let widget = gtk4 :: ScrolledWindow :: new () ;
@ -91,9 +91,9 @@ macro_rules ! scrolled_window { (
} } } } } }
macro_rules ! flow_box { ( macro_rules ! flow_box { (
$ ( @ orientation : $ orientation : expr , ) ? $ ( @ orientation : $ orientation : expr ; ) ?
$ ( @ homogeneous : $ homogeneous : expr , ) ? $ ( @ homogeneous : $ homogeneous : expr ; ) ?
$ ( @ selection_mode : $ selection_mode : expr , ) ? $ ( @ selection_mode : $ selection_mode : expr ; ) ?
) => { { ) => { {
let widget = gtk4 :: FlowBox :: new () ; let widget = gtk4 :: FlowBox :: new () ;
$ ( widget . set_orientation ( $ orientation ) ; ) ? $ ( widget . set_orientation ( $ orientation ) ; ) ?
@ -103,7 +103,7 @@ macro_rules ! flow_box { (
} } } } } }
macro_rules ! view_switcher { ( macro_rules ! view_switcher { (
$ ( @ policy : $ policy : expr , ) ? $ ( @ policy : $ policy : expr ; ) ?
$ stack : expr $ (,) ? $ stack : expr $ (,) ?
) => { { ) => { {
let widget = libadwaita :: ViewSwitcher :: new () ; let widget = libadwaita :: ViewSwitcher :: new () ;
@ -118,15 +118,15 @@ macro_rules ! header_bar { ( $ title_widget : expr $ (,) ? ) => { {
widget widget
} } } } } }
macro_rules ! bin { ( $ ( @ vexpand : $ vexpand : expr ) ? $ (,) ? ) => { { macro_rules ! bin { ( $ ( @ vexpand : $ vexpand : expr ; ) ? ) => { {
let widget = libadwaita :: Bin :: new () ; let widget = libadwaita :: Bin :: new () ;
$ ( widget . set_vexpand ( $ vexpand ) ; ) ? $ ( widget . set_vexpand ( $ vexpand ) ; ) ?
widget widget
} } } } } }
macro_rules ! application_window { ( macro_rules ! application_window { (
@ application : $ application : expr , @ application : $ application : expr ;
@ title : $ title : expr , @ title : $ title : expr ;
$ content : expr $ (,) ? $ content : expr $ (,) ?
) => { { ) => { {
use libadwaita :: prelude :: * ; use libadwaita :: prelude :: * ;
@ -139,15 +139,15 @@ macro_rules ! application_window { (
macro_rules ! vertically_filling { ( $ child : expr ) => { macro_rules ! vertically_filling { ( $ child : expr ) => {
g_box ! ( g_box ! (
@ orientation : gtk4 :: Orientation :: Vertical , @ orientation : gtk4 :: Orientation :: Vertical ;
$ child , $ child ,
bin ! ( @ vexpand : true ) , bin ! ( @ vexpand : true ; ) ,
) )
} } } }
macro_rules ! pango_attributes { ( macro_rules ! pango_attributes { (
$ ( @ scale : $ scale : expr , ) ? $ ( @ scale : $ scale : expr ; ) ?
$ ( @ weight : $ weight : expr , ) ? $ ( @ weight : $ weight : expr ; ) ?
) => { { ) => { {
let attributes = gtk4 :: pango :: AttrList :: new () ; let attributes = gtk4 :: pango :: AttrList :: new () ;
# [ allow (unused_mut) ] let mut font_description = gtk4 :: pango :: FontDescription :: new () ; # [ allow (unused_mut) ] let mut font_description = gtk4 :: pango :: FontDescription :: new () ;