Add list_row macro to simplify alternative list items

This commit is contained in:
Jeremy Soller 2022-09-30 11:04:56 -06:00
parent f09a3109e8
commit 153437b3b0
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
2 changed files with 19 additions and 8 deletions

View file

@ -3,6 +3,7 @@ use cosmic::{
button, button,
icon, icon,
list_item, list_item,
list_row,
list_section, list_section,
list_view, list_view,
nav_bar, nav_bar,
@ -123,7 +124,7 @@ impl Sandbox for Window {
), ),
list_section!( list_section!(
"Buttons", "Buttons",
row!( list_row!(
button!("Primary") button!("Primary")
.style(theme::Button::Primary) .style(theme::Button::Primary)
.on_press(Message::ButtonPressed) .on_press(Message::ButtonPressed)
@ -144,8 +145,8 @@ impl Sandbox for Window {
.style(theme::Button::Text) .style(theme::Button::Text)
.on_press(Message::ButtonPressed) .on_press(Message::ButtonPressed)
, ,
).spacing(12), ),
row!( list_row!(
button!("Primary") button!("Primary")
.style(theme::Button::Primary) .style(theme::Button::Primary)
.padding([8, 16]) .padding([8, 16])
@ -166,7 +167,7 @@ impl Sandbox for Window {
.style(theme::Button::Text) .style(theme::Button::Text)
.padding([8, 16]) .padding([8, 16])
, ,
).spacing(12), ),
), ),
list_section!( list_section!(
"Controls", "Controls",

View file

@ -8,11 +8,21 @@ use iced::{
#[macro_export] #[macro_export]
macro_rules! list_item { macro_rules! list_item {
($title:expr, $($x:expr),+ $(,)?) => ( ($title:expr, $($x:expr),+ $(,)?) => (
$crate::iced::widget::Row::with_children(vec![ $crate::widget::list_row!(
$crate::iced::widget::Text::new($title).into(), $crate::iced::widget::Text::new($title),
$crate::iced::widget::horizontal_space( $crate::iced::widget::horizontal_space(
$crate::iced::Length::Fill $crate::iced::Length::Fill
).into(), ),
$($x),+
)
);
}
pub use list_item;
#[macro_export]
macro_rules! list_row {
($($x:expr),+ $(,)?) => (
$crate::iced::widget::Row::with_children(vec![
$($crate::iced::Element::from($x)),+ $($crate::iced::Element::from($x)),+
]) ])
.align_items(Alignment::Center) .align_items(Alignment::Center)
@ -20,7 +30,7 @@ macro_rules! list_item {
.spacing(12) .spacing(12)
); );
} }
pub use list_item; pub use list_row;
#[macro_export] #[macro_export]
macro_rules! list_section { macro_rules! list_section {