1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:ui';
6
7import 'box.dart';
8
9/// Signature for a function that takes a [RenderBox] and returns the [Size]
10/// that the [RenderBox] would have if it were laid out with the given
11/// [BoxConstraints].
12///
13/// The methods of [ChildLayoutHelper] adhere to this signature.
14typedef ChildLayouter = Size Function(RenderBox child, BoxConstraints constraints);
15
16/// A collection of static functions to layout a [RenderBox] child with the
17/// given set of [BoxConstraints].
18///
19/// All of the functions adhere to the [ChildLayouter] signature.
20abstract final class ChildLayoutHelper {
21 /// Returns the [Size] that the [RenderBox] would have if it were to
22 /// be laid out with the given [BoxConstraints].
23 ///
24 /// This method calls [RenderBox.getDryLayout] on the given [RenderBox].
25 ///
26 /// This method should only be called by the parent of the provided
27 /// [RenderBox] child as it binds parent and child together (if the child
28 /// is marked as dirty, the child will also be marked as dirty).
29 ///
30 /// See also:
31 ///
32 /// * [layoutChild], which actually lays out the child with the given
33 /// constraints.
34 static Size dryLayoutChild(RenderBox child, BoxConstraints constraints) {
35 return child.getDryLayout(constraints);
36 }
37
38 /// Lays out the [RenderBox] with the given constraints and returns its
39 /// [Size].
40 ///
41 /// This method calls [RenderBox.layout] on the given [RenderBox] with
42 /// `parentUsesSize` set to true to receive its [Size].
43 ///
44 /// This method should only be called by the parent of the provided
45 /// [RenderBox] child as it binds parent and child together (if the child
46 /// is marked as dirty, the child will also be marked as dirty).
47 ///
48 /// See also:
49 ///
50 /// * [dryLayoutChild], which does not perform a real layout of the child.
51 static Size layoutChild(RenderBox child, BoxConstraints constraints) {
52 child.layout(constraints, parentUsesSize: true);
53 return child.size;
54 }
55}
56