Make Widget::layout and operate mutable
... and bless `responsive`!
This commit is contained in:
parent
9490d735c5
commit
31bc6d48cd
54 changed files with 284 additions and 519 deletions
|
|
@ -291,7 +291,7 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -300,7 +300,7 @@ where
|
|||
}
|
||||
|
||||
fn operate(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
|
|
@ -426,7 +426,7 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -435,7 +435,7 @@ where
|
|||
}
|
||||
|
||||
fn operate(
|
||||
&self,
|
||||
&mut self,
|
||||
state: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
renderer: &Renderer,
|
||||
|
|
@ -554,7 +554,7 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
_tree: &mut Tree,
|
||||
_renderer: &Renderer,
|
||||
_limits: &layout::Limits,
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub fn resolve<Message, Theme, Renderer>(
|
|||
padding: Padding,
|
||||
spacing: f32,
|
||||
align_items: Alignment,
|
||||
items: &[Element<'_, Message, Theme, Renderer>],
|
||||
items: &mut [Element<'_, Message, Theme, Renderer>],
|
||||
trees: &mut [widget::Tree],
|
||||
) -> Node
|
||||
where
|
||||
|
|
@ -95,7 +95,8 @@ where
|
|||
// We lay out non-fluid elements in the main axis.
|
||||
// If we need to compress the cross axis, then we skip any of these elements
|
||||
// that are also fluid in the cross axis.
|
||||
for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate() {
|
||||
for (i, (child, tree)) in items.iter_mut().zip(trees.iter_mut()).enumerate()
|
||||
{
|
||||
let (fill_main_factor, fill_cross_factor) = {
|
||||
let size = child.as_widget().size();
|
||||
|
||||
|
|
@ -117,7 +118,7 @@ where
|
|||
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||
|
||||
let layout =
|
||||
child.as_widget().layout(tree, renderer, &child_limits);
|
||||
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
||||
let size = layout.size();
|
||||
|
||||
available -= axis.main(size);
|
||||
|
|
@ -141,7 +142,8 @@ where
|
|||
// We can defer the layout of any elements that have a fixed size in the main axis,
|
||||
// allowing them to use the cross calculations of the next pass.
|
||||
if cross_compress && some_fill_cross {
|
||||
for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate()
|
||||
for (i, (child, tree)) in
|
||||
items.iter_mut().zip(trees.iter_mut()).enumerate()
|
||||
{
|
||||
let (main_size, cross_size) = {
|
||||
let size = child.as_widget().size();
|
||||
|
|
@ -161,7 +163,7 @@ where
|
|||
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||
|
||||
let layout =
|
||||
child.as_widget().layout(tree, renderer, &child_limits);
|
||||
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
||||
let size = layout.size();
|
||||
|
||||
available -= axis.main(size);
|
||||
|
|
@ -186,7 +188,8 @@ where
|
|||
// THIRD PASS
|
||||
// We lay out the elements that are fluid in the main axis.
|
||||
// We use the remaining space to evenly allocate space based on fill factors.
|
||||
for (i, (child, tree)) in items.iter().zip(trees.iter_mut()).enumerate() {
|
||||
for (i, (child, tree)) in items.iter_mut().zip(trees.iter_mut()).enumerate()
|
||||
{
|
||||
let (fill_main_factor, fill_cross_factor) = {
|
||||
let size = child.as_widget().size();
|
||||
|
||||
|
|
@ -225,7 +228,7 @@ where
|
|||
);
|
||||
|
||||
let layout =
|
||||
child.as_widget().layout(tree, renderer, &child_limits);
|
||||
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
||||
cross = cross.max(axis.cross(layout.size()));
|
||||
|
||||
nodes[i] = layout;
|
||||
|
|
@ -237,7 +240,7 @@ where
|
|||
// These are elements that must be compressed in their cross axis and have
|
||||
// a fixed length in the main axis.
|
||||
if cross_compress && some_fill_cross {
|
||||
for (i, (child, tree)) in items.iter().zip(trees).enumerate() {
|
||||
for (i, (child, tree)) in items.iter_mut().zip(trees).enumerate() {
|
||||
let (main_size, cross_size) = {
|
||||
let size = child.as_widget().size();
|
||||
|
||||
|
|
@ -255,7 +258,7 @@ where
|
|||
Limits::new(Size::ZERO, Size::new(max_width, max_height));
|
||||
|
||||
let layout =
|
||||
child.as_widget().layout(tree, renderer, &child_limits);
|
||||
child.as_widget_mut().layout(tree, renderer, &child_limits);
|
||||
let size = layout.size();
|
||||
|
||||
cross = cross.max(axis.cross(size));
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ where
|
|||
/// This [`layout::Node`] is used by the runtime to compute the [`Layout`] of the
|
||||
/// user interface.
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -102,7 +102,7 @@ where
|
|||
|
||||
/// Applies an [`Operation`] to the [`Widget`].
|
||||
fn operate(
|
||||
&self,
|
||||
&mut self,
|
||||
_state: &mut Tree,
|
||||
_layout: Layout<'_>,
|
||||
_renderer: &Renderer,
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ where
|
|||
}
|
||||
|
||||
fn layout(
|
||||
&self,
|
||||
&mut self,
|
||||
tree: &mut Tree,
|
||||
renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
|
|
@ -245,7 +245,7 @@ where
|
|||
}
|
||||
|
||||
fn operate(
|
||||
&self,
|
||||
&mut self,
|
||||
_state: &mut Tree,
|
||||
layout: Layout<'_>,
|
||||
_renderer: &Renderer,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue