Introduce view_switcher, header_bar, bin UI macros
This commit is contained in:
parent
a845c0c1fa
commit
eb10495670
2 changed files with 30 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
||||||
use libadwaita :: { * , ViewSwitcherPolicy :: * } ;
|
use libadwaita :: { * , ViewSwitcherPolicy :: * } ;
|
||||||
|
|
||||||
use crate :: ui :: { collection_view_stack :: * , component :: * } ;
|
use crate :: ui :: { collection_view_stack :: * , component :: * , utility :: * } ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,11 +8,9 @@ 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 = HeaderBar :: builder ()
|
let widget = header_bar ! (
|
||||||
. title_widget ( & create_collection_view_switcher (
|
view_switcher ! ( @ policy : Wide , collection_view_stack . get_widget () ) ,
|
||||||
collection_view_stack . get_widget () ) )
|
) ;
|
||||||
. build () ;
|
|
||||||
|
|
||||||
Self { widget }
|
Self { widget }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +18,3 @@ impl ApplicationHeaderBar {
|
||||||
impl Component <HeaderBar> for ApplicationHeaderBar {
|
impl Component <HeaderBar> for ApplicationHeaderBar {
|
||||||
fn get_widget ( & self ) -> & HeaderBar { & self . widget }
|
fn get_widget ( & self ) -> & HeaderBar { & self . widget }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_collection_view_switcher ( stack : & ViewStack ) -> ViewSwitcher {
|
|
||||||
ViewSwitcher :: builder ()
|
|
||||||
. policy (Wide)
|
|
||||||
. stack (stack)
|
|
||||||
. build ()
|
|
||||||
}
|
|
||||||
|
|
|
@ -102,14 +102,33 @@ macro_rules ! flow_box { (
|
||||||
widget
|
widget
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
macro_rules ! view_switcher { (
|
||||||
|
$ ( @ policy : $ policy : expr , ) ?
|
||||||
|
$ stack : expr $ (,) ?
|
||||||
|
) => { {
|
||||||
|
let widget = libadwaita :: ViewSwitcher :: new () ;
|
||||||
|
$ ( widget . set_policy ( $ policy ) ; ) ?
|
||||||
|
widget . set_stack ( Some ( & $ stack ) ) ;
|
||||||
|
widget
|
||||||
|
} } }
|
||||||
|
|
||||||
|
macro_rules ! header_bar { ( $ title_widget : expr $ (,) ? ) => { {
|
||||||
|
let widget = libadwaita :: HeaderBar :: new () ;
|
||||||
|
widget . set_title_widget ( Some ( & $ title_widget ) ) ;
|
||||||
|
widget
|
||||||
|
} } }
|
||||||
|
|
||||||
|
macro_rules ! bin { ( $ ( @ vexpand : $ vexpand : expr ) ? $ (,) ? ) => { {
|
||||||
|
let widget = libadwaita :: Bin :: new () ;
|
||||||
|
$ ( widget . set_vexpand ( $ vexpand ) ; ) ?
|
||||||
|
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 ,
|
||||||
$ child ,
|
$ child ,
|
||||||
libadwaita :: Bin :: builder ()
|
bin ! ( @ vexpand : true ) ,
|
||||||
. css_name ("filler")
|
|
||||||
. vexpand (true)
|
|
||||||
. build () ,
|
|
||||||
)
|
)
|
||||||
} }
|
} }
|
||||||
|
|
||||||
|
@ -125,5 +144,8 @@ pub (crate) use {
|
||||||
icon ,
|
icon ,
|
||||||
scrolled_window ,
|
scrolled_window ,
|
||||||
flow_box ,
|
flow_box ,
|
||||||
|
view_switcher ,
|
||||||
|
header_bar ,
|
||||||
|
bin ,
|
||||||
vertically_filling ,
|
vertically_filling ,
|
||||||
} ;
|
} ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue