Simplify use of list item
This commit is contained in:
parent
ae3f5b9b2e
commit
f09a3109e8
2 changed files with 41 additions and 37 deletions
|
|
@ -123,69 +123,67 @@ impl Sandbox for Window {
|
||||||
),
|
),
|
||||||
list_section!(
|
list_section!(
|
||||||
"Buttons",
|
"Buttons",
|
||||||
list_item!(
|
row!(
|
||||||
button!("Primary")
|
button!("Primary")
|
||||||
.style(theme::Button::Primary)
|
.style(theme::Button::Primary)
|
||||||
.on_press(Message::ButtonPressed)
|
.on_press(Message::ButtonPressed)
|
||||||
,
|
,
|
||||||
button!("Secondary")
|
button!("Secondary")
|
||||||
.style(theme::Button::Secondary)
|
.style(theme::Button::Secondary)
|
||||||
.on_press(Message::ButtonPressed)
|
.on_press(Message::ButtonPressed)
|
||||||
,
|
,
|
||||||
button!("Positive")
|
button!("Positive")
|
||||||
.style(theme::Button::Positive)
|
.style(theme::Button::Positive)
|
||||||
.on_press(Message::ButtonPressed)
|
.on_press(Message::ButtonPressed)
|
||||||
,
|
,
|
||||||
button!("Destructive")
|
button!("Destructive")
|
||||||
.style(theme::Button::Destructive)
|
.style(theme::Button::Destructive)
|
||||||
.on_press(Message::ButtonPressed)
|
.on_press(Message::ButtonPressed)
|
||||||
,
|
,
|
||||||
button!("Text")
|
button!("Text")
|
||||||
.style(theme::Button::Text)
|
.style(theme::Button::Text)
|
||||||
.on_press(Message::ButtonPressed)
|
.on_press(Message::ButtonPressed)
|
||||||
,
|
,
|
||||||
),
|
).spacing(12),
|
||||||
list_item!(
|
row!(
|
||||||
button!("Primary")
|
button!("Primary")
|
||||||
.style(theme::Button::Primary)
|
.style(theme::Button::Primary)
|
||||||
.padding([8, 16])
|
.padding([8, 16])
|
||||||
,
|
,
|
||||||
button!("Secondary")
|
button!("Secondary")
|
||||||
.style(theme::Button::Secondary)
|
.style(theme::Button::Secondary)
|
||||||
.padding([8, 16])
|
.padding([8, 16])
|
||||||
,
|
,
|
||||||
button!("Positive")
|
button!("Positive")
|
||||||
.style(theme::Button::Positive)
|
.style(theme::Button::Positive)
|
||||||
.padding([8, 16])
|
.padding([8, 16])
|
||||||
,
|
,
|
||||||
button!("Destructive")
|
button!("Destructive")
|
||||||
.style(theme::Button::Destructive)
|
.style(theme::Button::Destructive)
|
||||||
.padding([8, 16])
|
.padding([8, 16])
|
||||||
,
|
,
|
||||||
button!("Text")
|
button!("Text")
|
||||||
.style(theme::Button::Text)
|
.style(theme::Button::Text)
|
||||||
.padding([8, 16])
|
.padding([8, 16])
|
||||||
,
|
,
|
||||||
),
|
).spacing(12),
|
||||||
),
|
),
|
||||||
list_section!(
|
list_section!(
|
||||||
"Controls",
|
"Controls",
|
||||||
list_item!(
|
list_item!(
|
||||||
text("Toggler"),
|
"Toggler",
|
||||||
horizontal_space(Length::Fill),
|
|
||||||
toggler(None, self.toggler_value, Message::TogglerToggled)
|
toggler(None, self.toggler_value, Message::TogglerToggled)
|
||||||
),
|
),
|
||||||
list_item!(
|
list_item!(
|
||||||
text("Slider"),
|
"Slider",
|
||||||
horizontal_space(Length::Fill),
|
|
||||||
slider(0.0..=100.0, self.slider_value, Message::SliderChanged)
|
slider(0.0..=100.0, self.slider_value, Message::SliderChanged)
|
||||||
.width(Length::Units(250)),
|
.width(Length::Units(250))
|
||||||
),
|
),
|
||||||
list_item!(
|
list_item!(
|
||||||
text("Progress"),
|
"Progress",
|
||||||
horizontal_space(Length::Fill),
|
progress_bar(0.0..=100.0, self.slider_value)
|
||||||
progress_bar(0.0..=100.0, self.slider_value).height(Length::Units(4))
|
.width(Length::Units(250))
|
||||||
.width(Length::Units(250)),
|
.height(Length::Units(4))
|
||||||
),
|
),
|
||||||
checkbox("Checkbox", self.checkbox_value, Message::CheckboxToggled),
|
checkbox("Checkbox", self.checkbox_value, Message::CheckboxToggled),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,14 @@ use iced::{
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! list_item {
|
macro_rules! list_item {
|
||||||
($($x:expr),+ $(,)?) => (
|
($title:expr, $($x:expr),+ $(,)?) => (
|
||||||
$crate::iced::widget::Row::with_children(vec![$($crate::iced::Element::from($x)),+])
|
$crate::iced::widget::Row::with_children(vec![
|
||||||
|
$crate::iced::widget::Text::new($title).into(),
|
||||||
|
$crate::iced::widget::horizontal_space(
|
||||||
|
$crate::iced::Length::Fill
|
||||||
|
).into(),
|
||||||
|
$($crate::iced::Element::from($x)),+
|
||||||
|
])
|
||||||
.align_items(Alignment::Center)
|
.align_items(Alignment::Center)
|
||||||
.padding([0, 8])
|
.padding([0, 8])
|
||||||
.spacing(12)
|
.spacing(12)
|
||||||
|
|
@ -18,9 +24,9 @@ pub use list_item;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! list_section {
|
macro_rules! list_section {
|
||||||
($heading:expr, $($x:expr),+ $(,)?) => (
|
($title:expr, $($x:expr),+ $(,)?) => (
|
||||||
$crate::iced::widget::Column::with_children(vec![
|
$crate::iced::widget::Column::with_children(vec![
|
||||||
$crate::iced::widget::Text::new($heading)
|
$crate::iced::widget::Text::new($title)
|
||||||
.font($crate::font::FONT_SEMIBOLD)
|
.font($crate::font::FONT_SEMIBOLD)
|
||||||
.into()
|
.into()
|
||||||
,
|
,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue