align method

  1. @override
double align({
  1. required ParentLayout parent,
  2. required LayoutAxis axis,
  3. required double viewportSize,
  4. required double contentSize,
  5. required double maxBaseline,
  6. required double childBaseline,
})
override

Calculates the alignment position based on the value and text direction.

For LTR text direction: center + center * value For RTL text direction: center - center * value

This ensures that "start" always aligns to the reading direction start, and "end" always aligns to the reading direction end.

Implementation

@override
double align({
  required ParentLayout parent,
  required LayoutAxis axis,
  required double viewportSize,
  required double contentSize,
  required double maxBaseline,
  required double childBaseline,
}) {
  double center = (viewportSize - contentSize) / 2.0;
  double value = switch ((axis, parent.textDirection)) {
    // LayoutTextDirection.ltr => this.value,
    // LayoutTextDirection.rtl => -this.value,
    (LayoutAxis.horizontal, LayoutTextDirection.ltr) => this.value,
    (LayoutAxis.horizontal, LayoutTextDirection.rtl) => -this.value,
    (LayoutAxis.vertical, _) => this.value,
  };
  return center + center * value;
}