format method

  1. @override
GroupElement format(
  1. double availableWidth
)
override

Implementation

@override
GroupElement format(double availableWidth) {
  final out = <TextElement>[];
  final blockWidth = availableWidth;
  final padding = style.padding;

  var verticalOffset = 0.0;
  var currentMargin = padding.top;
  for (final node in children) {
    final nodeMargins = node.style.margin;
    final marginLeft = collapseMargin(padding.left, nodeMargins.left);
    final marginRight = collapseMargin(padding.right, nodeMargins.right);
    final nodeAvailableWidth = blockWidth - marginLeft - marginRight;
    final nodeElement = node.format(nodeAvailableWidth);
    out.add(nodeElement);

    verticalOffset += collapseMargin(currentMargin, nodeMargins.top);
    nodeElement.translate(marginLeft, verticalOffset);
    verticalOffset += nodeElement.height;
    currentMargin = nodeMargins.bottom;
  }
  // Do not collapse padding if there are no children.
  final blockHeight = children.isEmpty
      ? padding.vertical
      : verticalOffset + collapseMargin(currentMargin, padding.bottom);
  final background =
      makeBackground(style.background, blockWidth, blockHeight);
  if (background != null) {
    out.insert(0, background);
  }
  return GroupElement(
    width: blockWidth,
    height: blockHeight,
    children: out,
  );
}