Skip to main content

SingleChildLayoutDelegate

Trait SingleChildLayoutDelegate 

Source
pub trait SingleChildLayoutDelegate: Debug + 'static {
    // Required methods
    fn should_relayout(
        &self,
        old_delegate: &dyn SingleChildLayoutDelegate,
    ) -> bool;
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn relayout(&self) -> Option<&Rc<dyn Listenable>> { ... }
    fn get_size(&self, constraints: BoxConstraints) -> Size { ... }
    fn get_constraints_for_child(
        &self,
        constraints: BoxConstraints,
    ) -> BoxConstraints { ... }
    fn get_position_for_child(&self, size: Size, child_size: Size) -> Offset { ... }
}
Expand description

A delegate for computing the layout of a render object with a single child.

Used by RenderCustomSingleChildLayoutBox and CustomSingleChildLayout (in the widgets library).

When asked to layout, RenderCustomSingleChildLayoutBox first calls get_size with its incoming constraints to determine its size. It then uses get_constraints_for_child to determine the constraints to apply to the child. After the child completes its layout, RenderCustomSingleChildLayoutBox calls get_position_for_child to determine the child’s position.

The relayout listenable causes the layout to update whenever it notifies its listeners.

Required Methods§

Source

fn should_relayout(&self, old_delegate: &dyn SingleChildLayoutDelegate) -> bool

Called whenever a new instance of the custom layout delegate class is provided to the RenderCustomSingleChildLayoutBox object, or any time that a new CustomSingleChildLayout object is created with a new instance of the custom layout delegate class (which amounts to the same thing, because the latter is implemented in terms of the former).

If the new instance represents different information than the old instance, then the method should return true, otherwise it should return false.

If the method returns false, then the get_size, get_constraints_for_child, and get_position_for_child calls might be optimized away.

It’s possible that the layout methods will get called even if should_relayout returns false (e.g. if an ancestor changed its layout). It’s also possible that the layout method will get called without should_relayout being called at all (e.g. if the parent changes size).

old_delegate is of the same concrete type, Dart’s covariant: narrow it with as_any.

Source

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§

Source

fn relayout(&self) -> Option<&Rc<dyn Listenable>>

The Listenable the layout will update on, Dart’s relayout constructor argument.

Defaults to None.

Source

fn get_size(&self, constraints: BoxConstraints) -> Size

The size of this object given the incoming constraints.

Defaults to the biggest size that satisfies the given constraints.

Source

fn get_constraints_for_child( &self, constraints: BoxConstraints, ) -> BoxConstraints

The constraints for the child given the incoming constraints.

During layout, the child is given the layout constraints returned by this function. The child is required to pick a size for itself that satisfies these constraints.

Defaults to the given constraints.

Source

fn get_position_for_child(&self, size: Size, child_size: Size) -> Offset

The position where the child should be placed.

The size argument is the size of the parent, which might be different from the value returned by get_size if that size doesn’t satisfy the constraints passed to get_size. The child_size argument is the size of the child, which will satisfy the constraints returned by get_constraints_for_child.

Defaults to positioning the child in the upper left corner of the parent.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§