pub trait MultiChildLayoutDelegate: Debug + 'static {
// Required methods
fn perform_layout(
&self,
app: &mut App,
children: &mut MultiChildLayoutChildren,
size: Size,
);
fn should_relayout(
&self,
old_delegate: &dyn MultiChildLayoutDelegate,
) -> bool;
fn as_any(&self) -> &dyn Any;
// Provided methods
fn relayout(&self) -> Option<&Rc<dyn Listenable>> { ... }
fn get_size(&self, constraints: BoxConstraints) -> Size { ... }
}Expand description
A delegate that controls the layout of multiple children.
Used with CustomMultiChildLayout (in the widgets library) and
RenderCustomMultiChildLayoutBox (in the rendering library).
Delegates must be idempotent. Specifically, if two delegates are equal, then they must
produce the same layout. To change the layout, replace the delegate with a different
instance whose should_relayout returns true when given the
previous instance.
Override get_size to control the overall size of the layout. The size of
the layout cannot depend on layout properties of the children. This was a design decision to
simplify the delegate implementations: this way, the delegate implementations do not have to
also handle various intrinsic sizing functions if the parent’s size depended on the children.
Override perform_layout to size and position the children. An
implementation of perform_layout must call
MultiChildLayoutChildren::layout_child exactly once for each child, but it may lay out
children in an arbitrary order.
Override should_relayout to determine when the layout of the
children needs to be recomputed when the delegate changes.
The most efficient way to trigger a relayout is to answer a relayout
listenable. The custom layout listens to that value and relays out whenever it notifies its
listeners, such as when an animation ticks. This allows the custom layout to avoid the build
phase of the pipeline.
Each child must be wrapped in a LayoutId widget to assign the id that identifies it to the
delegate. The id needs to be unique among the children that the CustomMultiChildLayout
manages.
Required Methods§
Sourcefn perform_layout(
&self,
app: &mut App,
children: &mut MultiChildLayoutChildren,
size: Size,
)
fn perform_layout( &self, app: &mut App, children: &mut MultiChildLayoutChildren, size: Size, )
Override this method to lay out and position all children given this widget’s size.
This method must call MultiChildLayoutChildren::layout_child for each child. It
should also specify the final position of each child with
MultiChildLayoutChildren::position_child.
Sourcefn should_relayout(&self, old_delegate: &dyn MultiChildLayoutDelegate) -> bool
fn should_relayout(&self, old_delegate: &dyn MultiChildLayoutDelegate) -> bool
Override this method to return true when the children need to be laid out.
This should compare the fields of the current delegate and the given old_delegate and
return true if the fields are such that the layout would be different. old_delegate is
of the same concrete type, Dart’s covariant: narrow it with
as_any.
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
The concrete delegate, for Dart’s runtimeType comparison and its covariant
narrowing of should_relayout’s argument.
Provided Methods§
Sourcefn relayout(&self) -> Option<&Rc<dyn Listenable>>
fn relayout(&self) -> Option<&Rc<dyn Listenable>>
The Listenable the layout will update on, Dart’s relayout constructor argument.
Defaults to None.
Sourcefn get_size(&self, constraints: BoxConstraints) -> Size
fn get_size(&self, constraints: BoxConstraints) -> Size
Override this method to return the size of this object given the incoming constraints.
The size cannot reflect the sizes of the children. If this layout has a fixed width or height the returned size can reflect that; the size will be constrained to the given constraints.
By default, attempts to size the box to the biggest size possible given the constraints.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".