g_box UI macro can now take inline conditional children
This commit is contained in:
parent
cd45d4303b
commit
a9ec7bdcc9
2 changed files with 81 additions and 53 deletions
|
@ -156,46 +156,48 @@ async fn create_collection_item (
|
||||||
poster_file_path : Option < & Path > ,
|
poster_file_path : Option < & Path > ,
|
||||||
details_widget : & Box ,
|
details_widget : & Box ,
|
||||||
) -> Box {
|
) -> Box {
|
||||||
let container = g_box ! (
|
g_box ! (
|
||||||
|
@ option_children ;
|
||||||
@ orientation : Vertical ;
|
@ orientation : Vertical ;
|
||||||
@ margin_top : 20 ;
|
@ margin_top : 20 ;
|
||||||
@ margin_bottom : 20 ;
|
@ margin_bottom : 20 ;
|
||||||
) ;
|
|
||||||
|
|
||||||
if let Some (poster_file_path) = poster_file_path {
|
match poster_file_path {
|
||||||
let poster_file_path = PathBuf :: from (poster_file_path) ; // God forbid `Path` would work with `clone ! ()`
|
Some (poster_file_path) => {
|
||||||
let poster_texture = spawn_blocking ( move ||
|
let poster_file_path = PathBuf :: from (poster_file_path) ; // God forbid `Path` would work with `clone ! ()`
|
||||||
Texture :: from_filename (poster_file_path) . unwrap ()
|
let poster_texture = spawn_blocking ( move ||
|
||||||
) . await . unwrap () ;
|
Texture :: from_filename (poster_file_path) . unwrap ()
|
||||||
|
) . await . unwrap () ;
|
||||||
|
Some ( image ! (
|
||||||
|
@ paintable : & poster_texture ;
|
||||||
|
@ width_request : 300 ;
|
||||||
|
@ height_request : 300 ;
|
||||||
|
@ margin_bottom : 10 ;
|
||||||
|
) )
|
||||||
|
} ,
|
||||||
|
None => None ,
|
||||||
|
} . as_ref () ,
|
||||||
|
|
||||||
container . append ( & image ! (
|
Some ( & label ! (
|
||||||
@ paintable : & poster_texture ;
|
|
||||||
@ width_request : 300 ;
|
|
||||||
@ height_request : 300 ;
|
|
||||||
@ margin_bottom : 10 ;
|
|
||||||
) ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
container . append ( & label ! (
|
|
||||||
@ justify : Justification :: Center ;
|
|
||||||
@ wrap : true ;
|
|
||||||
@ max_width_chars : 1 ; // Not the actual limit, used instead to wrap more aggressively
|
|
||||||
@ attributes : & pango_attributes ! ( @ scale : SCALE_LARGE ; @ weight : Bold ; ) ;
|
|
||||||
name ,
|
|
||||||
) ) ;
|
|
||||||
|
|
||||||
if let Some (original_name) = original_name {
|
|
||||||
container . append ( & label ! (
|
|
||||||
@ 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
|
||||||
original_name ,
|
@ attributes : & pango_attributes ! ( @ scale : SCALE_LARGE ; @ weight : Bold ; ) ;
|
||||||
) ) ;
|
name ,
|
||||||
}
|
) ) ,
|
||||||
|
|
||||||
container . append (details_widget) ;
|
match original_name {
|
||||||
|
Some (original_name) => Some ( label ! (
|
||||||
|
@ justify : Justification :: Center ;
|
||||||
|
@ wrap : true ;
|
||||||
|
@ max_width_chars : 1 ; // Not the actual limit, used instead to wrap more aggressively
|
||||||
|
original_name ,
|
||||||
|
) ) ,
|
||||||
|
None => None ,
|
||||||
|
} . as_ref () ,
|
||||||
|
|
||||||
container
|
Some (details_widget) ,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_film_details ( film : & FilmOverview ) -> Box {
|
fn create_film_details ( film : & FilmOverview ) -> Box {
|
||||||
|
|
|
@ -22,29 +22,55 @@ macro_rules ! label { (
|
||||||
label
|
label
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
macro_rules ! g_box { (
|
macro_rules ! g_box {
|
||||||
$ ( @ orientation : $ orientation : expr ; ) ?
|
(
|
||||||
$ ( @ halign : $ halign : expr ; ) ?
|
$ ( @ orientation : $ orientation : expr ; ) ?
|
||||||
$ ( @ valign : $ valign : expr ; ) ?
|
$ ( @ halign : $ halign : expr ; ) ?
|
||||||
$ ( @ spacing : $ spacing : expr ; ) ?
|
$ ( @ valign : $ valign : expr ; ) ?
|
||||||
$ ( @ margin_top : $ margin_top : expr ; ) ?
|
$ ( @ spacing : $ spacing : expr ; ) ?
|
||||||
$ ( @ margin_bottom : $ margin_bottom : expr ; ) ?
|
$ ( @ margin_top : $ margin_top : expr ; ) ?
|
||||||
$ ( @ widget_name : $ widget_name : expr ; ) ?
|
$ ( @ margin_bottom : $ margin_bottom : expr ; ) ?
|
||||||
$ ( @ css_classes : $ css_classes : expr ; ) ?
|
$ ( @ widget_name : $ widget_name : expr ; ) ?
|
||||||
$ ( $ child : expr ) , * $ (,) ?
|
$ ( @ css_classes : $ css_classes : expr ; ) ?
|
||||||
) => { {
|
$ ( $ child : expr ) , * $ (,) ?
|
||||||
let container = gtk4 :: Box :: builder () . build () ;
|
) => { {
|
||||||
$ ( container . set_orientation ( $ orientation ) ; ) ?
|
let container = gtk4 :: Box :: builder () . build () ;
|
||||||
$ ( container . set_halign ( $ halign ) ; ) ?
|
$ ( container . set_orientation ( $ orientation ) ; ) ?
|
||||||
$ ( container . set_valign ( $ valign ) ; ) ?
|
$ ( container . set_halign ( $ halign ) ; ) ?
|
||||||
$ ( container . set_spacing ( $ spacing ) ; ) ?
|
$ ( container . set_valign ( $ valign ) ; ) ?
|
||||||
$ ( container . set_margin_top ( $ margin_top ) ; ) ?
|
$ ( container . set_spacing ( $ spacing ) ; ) ?
|
||||||
$ ( container . set_margin_bottom ( $ margin_bottom ) ; ) ?
|
$ ( container . set_margin_top ( $ margin_top ) ; ) ?
|
||||||
$ ( container . set_widget_name ( $ widget_name ) ; ) ?
|
$ ( container . set_margin_bottom ( $ margin_bottom ) ; ) ?
|
||||||
$ ( container . set_css_classes ( $ css_classes ) ; ) ?
|
$ ( container . set_widget_name ( $ widget_name ) ; ) ?
|
||||||
$ ( container . append ( $ child ) ; ) *
|
$ ( container . set_css_classes ( $ css_classes ) ; ) ?
|
||||||
container
|
$ ( 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 { (
|
macro_rules ! view_stack { (
|
||||||
$ ( ( $ title : expr , $ icon : expr , $ widget : expr $ (,) ? ) ) , * $ (,) ?
|
$ ( ( $ title : expr , $ icon : expr , $ widget : expr $ (,) ? ) ) , * $ (,) ?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue