summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-05 17:24:43 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-01-10 10:01:49 +0100
commit22226394f7b1a0e0205b9bb5b3ef9b85a3b406f5 (patch)
tree22214a4ac6bca5033f6d5a227934288019f6ca60 /examples
parent0322e820eb40d36a7425246278b7bcb22b7010aa (diff)
downloadiced-22226394f7b1a0e0205b9bb5b3ef9b85a3b406f5.tar.gz
iced-22226394f7b1a0e0205b9bb5b3ef9b85a3b406f5.tar.bz2
iced-22226394f7b1a0e0205b9bb5b3ef9b85a3b406f5.zip
Introduce `Widget::size_hint` and fix further layout inconsistencies
Diffstat (limited to 'examples')
-rw-r--r--examples/download_progress/src/main.rs19
-rw-r--r--examples/events/src/main.rs3
-rw-r--r--examples/layout/src/main.rs2
-rw-r--r--examples/lazy/src/main.rs46
-rw-r--r--examples/loading_spinners/src/main.rs11
-rw-r--r--examples/scrollable/src/main.rs23
-rw-r--r--examples/tour/src/main.rs1
-rw-r--r--examples/websocket/src/main.rs11
8 files changed, 44 insertions, 72 deletions
diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs
index a2fcb275..675e9e26 100644
--- a/examples/download_progress/src/main.rs
+++ b/examples/download_progress/src/main.rs
@@ -73,16 +73,15 @@ impl Application for Example {
}
fn view(&self) -> Element<Message> {
- let downloads = Column::with_children(
- self.downloads.iter().map(Download::view).collect(),
- )
- .push(
- button("Add another download")
- .on_press(Message::Add)
- .padding(10),
- )
- .spacing(20)
- .align_items(Alignment::End);
+ let downloads =
+ Column::with_children(self.downloads.iter().map(Download::view))
+ .push(
+ button("Add another download")
+ .on_press(Message::Add)
+ .padding(10),
+ )
+ .spacing(20)
+ .align_items(Alignment::End);
container(downloads)
.width(Length::Fill)
diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs
index 334b012d..fc51ac4a 100644
--- a/examples/events/src/main.rs
+++ b/examples/events/src/main.rs
@@ -82,8 +82,7 @@ impl Application for Events {
self.last
.iter()
.map(|event| text(format!("{event:?}")).size(40))
- .map(Element::from)
- .collect(),
+ .map(Element::from),
);
let toggle = checkbox(
diff --git a/examples/layout/src/main.rs b/examples/layout/src/main.rs
index 1b0c0c94..eeaa76b6 100644
--- a/examples/layout/src/main.rs
+++ b/examples/layout/src/main.rs
@@ -106,7 +106,7 @@ impl Example {
column![text("Original text")].padding(10),
|quotes, i| {
column![
- row![vertical_rule(2), quotes],
+ row![vertical_rule(2), quotes].height(Length::Shrink),
text(format!("Reply {i}"))
]
.spacing(10)
diff --git a/examples/lazy/src/main.rs b/examples/lazy/src/main.rs
index 01560598..04df0744 100644
--- a/examples/lazy/src/main.rs
+++ b/examples/lazy/src/main.rs
@@ -178,35 +178,23 @@ impl Sandbox for App {
}
});
- column(
- items
- .into_iter()
- .map(|item| {
- let button = button("Delete")
- .on_press(Message::DeleteItem(item.clone()))
- .style(theme::Button::Destructive);
-
- row![
- text(&item.name)
- .style(theme::Text::Color(item.color.into())),
- horizontal_space(Length::Fill),
- pick_list(
- Color::ALL,
- Some(item.color),
- move |color| {
- Message::ItemColorChanged(
- item.clone(),
- color,
- )
- }
- ),
- button
- ]
- .spacing(20)
- .into()
- })
- .collect(),
- )
+ column(items.into_iter().map(|item| {
+ let button = button("Delete")
+ .on_press(Message::DeleteItem(item.clone()))
+ .style(theme::Button::Destructive);
+
+ row![
+ text(&item.name)
+ .style(theme::Text::Color(item.color.into())),
+ horizontal_space(Length::Fill),
+ pick_list(Color::ALL, Some(item.color), move |color| {
+ Message::ItemColorChanged(item.clone(), color)
+ }),
+ button
+ ]
+ .spacing(20)
+ .into()
+ }))
.spacing(10)
});
diff --git a/examples/loading_spinners/src/main.rs b/examples/loading_spinners/src/main.rs
index a78e9590..93a4605e 100644
--- a/examples/loading_spinners/src/main.rs
+++ b/examples/loading_spinners/src/main.rs
@@ -96,15 +96,14 @@ impl Application for LoadingSpinners {
container(
column.push(
- row(vec![
- text("Cycle duration:").into(),
+ row![
+ text("Cycle duration:"),
slider(1.0..=1000.0, self.cycle_duration * 100.0, |x| {
Message::CycleDurationChanged(x / 100.0)
})
- .width(200.0)
- .into(),
- text(format!("{:.2}s", self.cycle_duration)).into(),
- ])
+ .width(200.0),
+ text(format!("{:.2}s", self.cycle_duration)),
+ ]
.align_items(iced::Alignment::Center)
.spacing(20.0),
),
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index 1042e7a4..249bc2a5 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -172,23 +172,21 @@ impl Application for ScrollableDemo {
]
.spacing(10);
- let scroll_alignment_controls = column(vec![
- text("Scrollable alignment:").into(),
+ let scroll_alignment_controls = column![
+ text("Scrollable alignment:"),
radio(
"Start",
scrollable::Alignment::Start,
Some(self.alignment),
Message::AlignmentChanged,
- )
- .into(),
+ ),
radio(
"End",
scrollable::Alignment::End,
Some(self.alignment),
Message::AlignmentChanged,
)
- .into(),
- ])
+ ]
.spacing(10);
let scroll_controls = row![
@@ -226,6 +224,7 @@ impl Application for ScrollableDemo {
.padding([40, 0, 40, 0])
.spacing(40),
)
+ .width(Length::Fill)
.height(Length::Fill)
.direction(scrollable::Direction::Vertical(
Properties::new()
@@ -251,6 +250,7 @@ impl Application for ScrollableDemo {
.padding([0, 40, 0, 40])
.spacing(40),
)
+ .width(Length::Fill)
.height(Length::Fill)
.direction(scrollable::Direction::Horizontal(
Properties::new()
@@ -293,6 +293,7 @@ impl Application for ScrollableDemo {
.padding([0, 40, 0, 40])
.spacing(40),
)
+ .width(Length::Fill)
.height(Length::Fill)
.direction({
let properties = Properties::new()
@@ -333,19 +334,11 @@ impl Application for ScrollableDemo {
let content: Element<Message> =
column![scroll_controls, scrollable_content, progress_bars]
- .height(Length::Fill)
.align_items(Alignment::Center)
.spacing(10)
.into();
- Element::from(
- container(content)
- .width(Length::Fill)
- .height(Length::Fill)
- .padding(40)
- .center_x()
- .center_y(),
- )
+ Element::from(container(content).padding(40).center_x().center_y())
}
fn theme(&self) -> Self::Theme {
diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs
index b9ee1e61..8633bc0a 100644
--- a/examples/tour/src/main.rs
+++ b/examples/tour/src/main.rs
@@ -509,7 +509,6 @@ impl<'a> Step {
)
})
.map(Element::from)
- .collect()
)
.spacing(10)
]
diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs
index 5fdf6657..59488e69 100644
--- a/examples/websocket/src/main.rs
+++ b/examples/websocket/src/main.rs
@@ -3,7 +3,7 @@ mod echo;
use iced::alignment::{self, Alignment};
use iced::executor;
use iced::widget::{
- button, column, container, row, scrollable, text, text_input, Column,
+ button, column, container, row, scrollable, text, text_input,
};
use iced::{
Application, Color, Command, Element, Length, Settings, Subscription, Theme,
@@ -108,13 +108,8 @@ impl Application for WebSocket {
.into()
} else {
scrollable(
- Column::with_children(
- self.messages
- .iter()
- .cloned()
- .map(text)
- .map(Element::from)
- .collect(),
+ column(
+ self.messages.iter().cloned().map(text).map(Element::from),
)
.spacing(10),
)