Introduce flow_box macro
This commit is contained in:
parent
01bfa16481
commit
a845c0c1fa
3 changed files with 55 additions and 37 deletions
|
@ -24,7 +24,11 @@ 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 = create_flow_box () ;
|
let grid_widget = flow_box ! (
|
||||||
|
@ orientation : Horizontal ,
|
||||||
|
@ homogeneous : true ,
|
||||||
|
@ selection_mode : SelectionMode :: None ,
|
||||||
|
) ;
|
||||||
let film_widget_pairs = RefCell :: new ( vec ! () ) ;
|
let film_widget_pairs = RefCell :: new ( vec ! () ) ;
|
||||||
|
|
||||||
let component = Self { film_widget_pairs , grid_widget } ;
|
let component = Self { film_widget_pairs , grid_widget } ;
|
||||||
|
@ -73,7 +77,11 @@ 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 = create_flow_box () ;
|
let grid_widget = flow_box ! (
|
||||||
|
@ orientation : Horizontal ,
|
||||||
|
@ homogeneous : true ,
|
||||||
|
@ selection_mode : SelectionMode :: None ,
|
||||||
|
) ;
|
||||||
let series_widget_pairs = RefCell :: new ( vec ! () ) ;
|
let series_widget_pairs = RefCell :: new ( vec ! () ) ;
|
||||||
|
|
||||||
let component = Self { series_widget_pairs , grid_widget } ;
|
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 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 {
|
pub fn create_film_entry ( film : & Film ) -> Box {
|
||||||
create_collection_item (
|
create_collection_item (
|
||||||
film . name . as_str () ,
|
film . name . as_str () ,
|
||||||
|
@ -202,29 +202,20 @@ fn create_collection_item (
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_film_details ( film : & Film ) -> Box {
|
fn create_film_details ( film : & Film ) -> Box {
|
||||||
let container = Box :: builder ()
|
g_box ! (
|
||||||
. orientation (Horizontal)
|
@ orientation : Horizontal ,
|
||||||
. halign (Center)
|
@ halign : Center ,
|
||||||
. spacing (20)
|
@ spacing : 20 ,
|
||||||
. build () ;
|
label ! ( film . release_date . as_str () ) ,
|
||||||
|
label ! ( format ! ( "{}m" , film . runtime_minutes ) . as_str () ) ,
|
||||||
container . append (
|
)
|
||||||
& Label :: builder () . label ( & film . release_date ) . build ()
|
|
||||||
) ;
|
|
||||||
container . append (
|
|
||||||
& Label :: builder () . label ( format ! ( "{}m" , film . runtime_minutes ) ) . build ()
|
|
||||||
) ;
|
|
||||||
|
|
||||||
container
|
|
||||||
}
|
}
|
||||||
fn create_series_details ( series : & Series ) -> Box {
|
fn create_series_details ( series : & Series ) -> Box {
|
||||||
let container = Box :: builder ()
|
g_box ! (
|
||||||
. orientation (Horizontal)
|
@ orientation : Horizontal ,
|
||||||
. halign (Center)
|
@ halign : Center ,
|
||||||
. spacing (20)
|
@ spacing : 20 ,
|
||||||
. build () ;
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
label ! ("????") ,
|
||||||
container
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,24 @@ use crate :: {
|
||||||
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SeriesProperty { Name , FirstReleaseDate }
|
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SeriesProperty { Name , FirstReleaseDate }
|
||||||
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SortingDirection { Ascending , Descending }
|
# [ derive ( Clone , Copy , PartialEq ) ] pub enum SortingDirection { Ascending , Descending }
|
||||||
|
|
||||||
# [ derive ( Clone , Copy ) ] pub struct FilmsSorting { property : FilmProperty , direction : SortingDirection }
|
# [ derive ( Clone , Copy ) ] pub struct FilmsSorting {
|
||||||
# [ derive ( Clone , Copy ) ] pub struct SeriesSorting { property : SeriesProperty , direction : SortingDirection }
|
property : FilmProperty ,
|
||||||
|
direction : SortingDirection ,
|
||||||
|
}
|
||||||
|
# [ derive ( Clone , Copy ) ] pub struct SeriesSorting {
|
||||||
|
property : SeriesProperty ,
|
||||||
|
direction : SortingDirection ,
|
||||||
|
}
|
||||||
|
|
||||||
impl FilmsSorting {
|
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 {
|
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 {
|
impl Default for FilmsSorting {
|
||||||
|
|
|
@ -19,6 +19,8 @@ macro_rules ! g_box { (
|
||||||
$ ( @ halign : $ halign : expr , ) ?
|
$ ( @ halign : $ halign : expr , ) ?
|
||||||
$ ( @ valign : $ valign : expr , ) ?
|
$ ( @ valign : $ valign : expr , ) ?
|
||||||
$ ( @ spacing : $ spacing : expr , ) ?
|
$ ( @ spacing : $ spacing : expr , ) ?
|
||||||
|
$ ( @ margin_top : $ margin_top : 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 ) , + $ (,) ?
|
||||||
|
@ -28,6 +30,8 @@ macro_rules ! g_box { (
|
||||||
$ ( container . set_halign ( $ halign ) ; ) ?
|
$ ( container . set_halign ( $ halign ) ; ) ?
|
||||||
$ ( container . set_valign ( $ valign ) ; ) ?
|
$ ( container . set_valign ( $ valign ) ; ) ?
|
||||||
$ ( container . set_spacing ( $ spacing ) ; ) ?
|
$ ( container . set_spacing ( $ spacing ) ; ) ?
|
||||||
|
$ ( container . set_margin_top ( $ margin_top ) ; ) ?
|
||||||
|
$ ( container . set_margin_bottom ( $ margin_bottom ) ; ) ?
|
||||||
$ ( container . set_widget_name ( & $ widget_name ) ; ) ?
|
$ ( container . set_widget_name ( & $ widget_name ) ; ) ?
|
||||||
$ ( container . set_css_classes ( & $ css_classes ) ; ) ?
|
$ ( container . set_css_classes ( & $ css_classes ) ; ) ?
|
||||||
$ ( container . append ( & $ child ) ; ) *
|
$ ( container . append ( & $ child ) ; ) *
|
||||||
|
@ -86,6 +90,18 @@ macro_rules ! scrolled_window { (
|
||||||
widget
|
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 ) => {
|
macro_rules ! vertically_filling { ( $ child : expr ) => {
|
||||||
g_box ! (
|
g_box ! (
|
||||||
@ orientation : gtk4 :: Orientation :: Vertical ,
|
@ orientation : gtk4 :: Orientation :: Vertical ,
|
||||||
|
@ -108,5 +124,6 @@ pub (crate) use {
|
||||||
popover ,
|
popover ,
|
||||||
icon ,
|
icon ,
|
||||||
scrolled_window ,
|
scrolled_window ,
|
||||||
|
flow_box ,
|
||||||
vertically_filling ,
|
vertically_filling ,
|
||||||
} ;
|
} ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue