Introduce flow_box macro

This commit is contained in:
Reinout Meliesie 2025-01-31 17:38:52 +01:00
parent 01bfa16481
commit a845c0c1fa
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
3 changed files with 55 additions and 37 deletions

View file

@ -24,7 +24,11 @@ pub struct CollatedSeriesGrid {
impl CollatedFilmsGrid {
pub fn new ( films : Vec <Film> , sorting : FilmsSorting ) -> Self {
let grid_widget = create_flow_box () ;
let grid_widget = flow_box ! (
@ orientation : Horizontal ,
@ homogeneous : true ,
@ selection_mode : SelectionMode :: None ,
) ;
let film_widget_pairs = RefCell :: new ( vec ! () ) ;
let component = Self { film_widget_pairs , grid_widget } ;
@ -73,7 +77,11 @@ impl CollatedFilmsGrid {
}
impl CollatedSeriesGrid {
pub fn new ( series : Vec <Series> , sorting : SeriesSorting ) -> Self {
let grid_widget = create_flow_box () ;
let grid_widget = flow_box ! (
@ orientation : Horizontal ,
@ homogeneous : true ,
@ selection_mode : SelectionMode :: None ,
) ;
let series_widget_pairs = RefCell :: new ( vec ! () ) ;
let component = Self { series_widget_pairs , grid_widget } ;
@ -126,14 +134,6 @@ impl Component <FlowBox> for CollatedSeriesGrid {
fn get_widget ( & self ) -> & FlowBox { & self . grid_widget }
}
fn create_flow_box () -> FlowBox {
FlowBox :: builder ()
. orientation (Horizontal)
. homogeneous (true)
. selection_mode ( SelectionMode :: None )
. build ()
}
pub fn create_film_entry ( film : & Film ) -> Box {
create_collection_item (
film . name . as_str () ,
@ -202,29 +202,20 @@ fn create_collection_item (
}
fn create_film_details ( film : & Film ) -> Box {
let container = Box :: builder ()
. orientation (Horizontal)
. halign (Center)
. spacing (20)
. build () ;
container . append (
& Label :: builder () . label ( & film . release_date ) . build ()
) ;
container . append (
& Label :: builder () . label ( format ! ( "{}m" , film . runtime_minutes ) ) . build ()
) ;
container
g_box ! (
@ orientation : Horizontal ,
@ halign : Center ,
@ spacing : 20 ,
label ! ( film . release_date . as_str () ) ,
label ! ( format ! ( "{}m" , film . runtime_minutes ) . as_str () ) ,
)
}
fn create_series_details ( series : & Series ) -> Box {
let container = Box :: builder ()
. orientation (Horizontal)
. halign (Center)
. spacing (20)
. build () ;
// TODO
container
g_box ! (
@ orientation : Horizontal ,
@ halign : Center ,
@ spacing : 20 ,
// TODO
label ! ("????") ,
)
}

View file

@ -18,14 +18,24 @@ use crate :: {
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SeriesProperty { Name , FirstReleaseDate }
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SortingDirection { Ascending , Descending }
# [ derive ( Clone , Copy ) ] pub struct FilmsSorting { property : FilmProperty , direction : SortingDirection }
# [ derive ( Clone , Copy ) ] pub struct SeriesSorting { property : SeriesProperty , direction : SortingDirection }
# [ derive ( Clone , Copy ) ] pub struct FilmsSorting {
property : FilmProperty ,
direction : SortingDirection ,
}
# [ derive ( Clone , Copy ) ] pub struct SeriesSorting {
property : SeriesProperty ,
direction : SortingDirection ,
}
impl FilmsSorting {
pub fn new ( property : FilmProperty , direction : SortingDirection ) -> Self { Self { property , direction } }
pub fn new ( property : FilmProperty , direction : SortingDirection ) -> Self {
Self { property , direction }
}
}
impl SeriesSorting {
pub fn new ( property : SeriesProperty , direction : SortingDirection ) -> Self { Self { property , direction } }
pub fn new ( property : SeriesProperty , direction : SortingDirection ) -> Self {
Self { property , direction }
}
}
impl Default for FilmsSorting {

View file

@ -19,6 +19,8 @@ macro_rules ! g_box { (
$ ( @ 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 ) , + $ (,) ?
@ -28,6 +30,8 @@ macro_rules ! g_box { (
$ ( 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 ) ; ) *
@ -86,6 +90,18 @@ macro_rules ! scrolled_window { (
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 ! vertically_filling { ( $ child : expr ) => {
g_box ! (
@ orientation : gtk4 :: Orientation :: Vertical ,
@ -108,5 +124,6 @@ pub (crate) use {
popover ,
icon ,
scrolled_window ,
flow_box ,
vertically_filling ,
} ;