Introduce Widget::size_hint and fix further layout inconsistencies

This commit is contained in:
Héctor Ramón Jiménez 2024-01-05 17:24:43 +01:00
parent 0322e820eb
commit 22226394f7
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
17 changed files with 210 additions and 123 deletions

View file

@ -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)

View file

@ -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(

View file

@ -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)

View file

@ -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);
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(),
)
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)
});

View file

@ -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),
),

View file

@ -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 {

View file

@ -509,7 +509,6 @@ impl<'a> Step {
)
})
.map(Element::from)
.collect()
)
.spacing(10)
]

View file

@ -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),
)