Make Shrink have priority over Fill in layout

This commit is contained in:
Héctor Ramón Jiménez 2023-03-16 20:23:25 +01:00 committed by Héctor Ramón Jiménez
parent 68c0484b5c
commit 0655a20ad1
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
46 changed files with 264 additions and 273 deletions

View file

@ -146,7 +146,8 @@ impl Application for GameOfLife {
.view()
.map(move |message| Message::Grid(message, version)),
controls,
];
]
.height(Length::Fill);
container(content)
.width(Length::Fill)
@ -178,7 +179,6 @@ fn view_controls<'a>(
slider(1.0..=1000.0, speed as f32, Message::SpeedChanged),
text(format!("x{speed}")).size(16),
]
.width(Length::Fill)
.align_items(Alignment::Center)
.spacing(10);

View file

@ -30,7 +30,7 @@ mod rainbow {
_renderer: &Renderer,
limits: &layout::Limits,
) -> layout::Node {
let size = limits.width(Length::Fill).resolve(Size::ZERO);
let size = limits.resolve(Size::ZERO, Length::Fill, Length::Shrink);
layout::Node::new(Size::new(size.width, size.width))
}

View file

@ -81,32 +81,25 @@ impl Program for Controls {
);
Row::new()
.width(Length::Fill)
.height(Length::Fill)
.align_items(Alignment::End)
.push(
Column::new()
.width(Length::Fill)
.align_items(Alignment::End)
.push(
Column::new()
.padding(10)
.spacing(10)
.push(
Text::new("Background color")
.style(Color::WHITE),
)
.push(sliders)
.push(
Text::new(format!("{background_color:?}"))
.size(14)
.style(Color::WHITE),
)
.push(
text_input("Placeholder", text)
.on_input(Message::TextChanged),
),
),
Column::new().align_items(Alignment::End).push(
Column::new()
.padding(10)
.spacing(10)
.push(Text::new("Background color").style(Color::WHITE))
.push(sliders)
.push(
Text::new(format!("{background_color:?}"))
.size(14)
.style(Color::WHITE),
)
.push(
text_input("Placeholder", text)
.on_input(Message::TextChanged),
),
),
)
.into()
}

View file

@ -259,7 +259,7 @@ where
limits: &layout::Limits,
) -> layout::Node {
let limits = limits.width(self.size).height(self.size);
let size = limits.resolve(Size::ZERO);
let size = limits.resolve(Size::ZERO, self.size, self.size);
layout::Node::new(size)
}

View file

@ -180,7 +180,7 @@ where
limits: &layout::Limits,
) -> layout::Node {
let limits = limits.width(self.width).height(self.height);
let size = limits.resolve(Size::ZERO);
let size = limits.resolve(Size::ZERO, self.width, self.height);
layout::Node::new(size)
}

View file

@ -420,17 +420,14 @@ mod modal {
.width(Length::Fill)
.height(Length::Fill);
let mut child = self
let child = self
.content
.as_widget()
.layout(self.tree, renderer, &limits);
.layout(self.tree, renderer, &limits)
.align(Alignment::Center, Alignment::Center, limits.max());
child.align(Alignment::Center, Alignment::Center, limits.max());
let mut node = layout::Node::with_children(self.size, vec![child]);
node.move_to(position);
node
layout::Node::with_children(self.size, vec![child])
.move_to(position)
}
fn on_event(

View file

@ -297,7 +297,6 @@ fn view_content<'a>(
text(format!("{}x{}", size.width, size.height)).size(24),
controls,
]
.width(Length::Fill)
.spacing(10)
.align_items(Alignment::Center);

View file

@ -48,7 +48,6 @@ impl Sandbox for Example {
pick_list,
vertical_space(600),
]
.width(Length::Fill)
.align_items(Alignment::Center)
.spacing(10);

View file

@ -147,35 +147,30 @@ impl Application for ScrollableDemo {
text("Scroller width:"),
scroller_width_slider,
]
.spacing(10)
.width(Length::Fill);
.spacing(10);
let scroll_orientation_controls = column(vec![
text("Scrollbar direction:").into(),
let scroll_orientation_controls = column![
text("Scrollbar direction:"),
radio(
"Vertical",
Direction::Vertical,
Some(self.scrollable_direction),
Message::SwitchDirection,
)
.into(),
),
radio(
"Horizontal",
Direction::Horizontal,
Some(self.scrollable_direction),
Message::SwitchDirection,
)
.into(),
),
radio(
"Both!",
Direction::Multi,
Some(self.scrollable_direction),
Message::SwitchDirection,
)
.into(),
])
.spacing(10)
.width(Length::Fill);
),
]
.spacing(10);
let scroll_alignment_controls = column(vec![
text("Scrollable alignment:").into(),
@ -194,16 +189,14 @@ impl Application for ScrollableDemo {
)
.into(),
])
.spacing(10)
.width(Length::Fill);
.spacing(10);
let scroll_controls = row![
scroll_slider_controls,
scroll_orientation_controls,
scroll_alignment_controls
]
.spacing(20)
.width(Length::Fill);
.spacing(20);
let scroll_to_end_button = || {
button("Scroll to end")
@ -229,7 +222,6 @@ impl Application for ScrollableDemo {
text("End!"),
scroll_to_beginning_button(),
]
.width(Length::Fill)
.align_items(Alignment::Center)
.padding([40, 0, 40, 0])
.spacing(40),
@ -341,7 +333,6 @@ impl Application for ScrollableDemo {
let content: Element<Message> =
column![scroll_controls, scrollable_content, progress_bars]
.width(Length::Fill)
.height(Length::Fill)
.align_items(Alignment::Center)
.spacing(10)

View file

@ -79,12 +79,10 @@ impl Application for SierpinskiEmulator {
row![
text(format!("Iteration: {:?}", self.graph.iteration)),
slider(0..=10000, self.graph.iteration, Message::IterationSet)
.width(Length::Fill)
]
.padding(10)
.spacing(20),
]
.width(Length::Fill)
.align_items(iced::Alignment::Center)
.into()
}

View file

@ -104,10 +104,11 @@ impl Sandbox for Styling {
let progress_bar = progress_bar(0.0..=100.0, self.slider_value);
let scrollable = scrollable(
column!["Scroll me!", vertical_space(800), "You did it!"]
.width(Length::Fill),
)
let scrollable = scrollable(column![
"Scroll me!",
vertical_space(800),
"You did it!"
])
.width(Length::Fill)
.height(100);

View file

@ -63,7 +63,6 @@ impl Sandbox for Tiger {
container(apply_color_filter).width(Length::Fill).center_x()
]
.spacing(20)
.width(Length::Fill)
.height(Length::Fill),
)
.width(Length::Fill)

View file

@ -106,9 +106,7 @@ impl Application for App {
fn view<'a>(&'a self) -> Element<'a, Message> {
let subtitle = |title, content: Element<'a, Message>| {
column![text(title).size(14), content]
.width(Length::Fill)
.spacing(5)
column![text(title).size(14), content].spacing(5)
};
let mut add_toast = button("Add Toast");
@ -153,14 +151,11 @@ impl Application for App {
Message::Timeout
)
.step(1.0)
.width(Length::Fill)
]
.spacing(5)
.into()
),
column![add_toast]
.width(Length::Fill)
.align_items(Alignment::End)
column![add_toast].align_items(Alignment::End)
]
.spacing(10)
.max_width(200),
@ -513,14 +508,14 @@ mod toast {
position: Point,
_translation: Vector,
) -> layout::Node {
let limits = layout::Limits::new(Size::ZERO, bounds)
.width(Length::Fill)
.height(Length::Fill);
let limits = layout::Limits::new(Size::ZERO, bounds);
layout::flex::resolve(
layout::flex::Axis::Vertical,
renderer,
&limits,
Length::Fill,
Length::Fill,
10.into(),
10.0,
Alignment::End,

View file

@ -692,11 +692,7 @@ fn ferris<'a>(
}
fn button<'a, Message: Clone>(label: &str) -> Button<'a, Message> {
iced::widget::button(
text(label).horizontal_alignment(alignment::Horizontal::Center),
)
.padding(12)
.width(100)
iced::widget::button(text(label)).padding([12, 24])
}
fn color_slider<'a>(

View file

@ -116,7 +116,6 @@ impl Application for WebSocket {
.map(Element::from)
.collect(),
)
.width(Length::Fill)
.spacing(10),
)
.id(MESSAGE_LOG.clone())
@ -149,7 +148,6 @@ impl Application for WebSocket {
};
column![message_log, new_message_input]
.width(Length::Fill)
.height(Length::Fill)
.padding(20)
.spacing(10)