LyricLayout.compute constructor
LyricLayout.compute(
- LyricModel model,
- LyricStyle style,
- Size viewSize
Implementation
factory LyricLayout.compute(
LyricModel model,
LyricStyle style,
Size viewSize,
) {
final maxWidth = viewSize.width;
final lineMetrics = <LineMetrics>[];
for (var line in model.lines) {
final textPainter = TextPainter(
textAlign: style.lineTextAlign,
textDirection: TextDirection.ltr,
);
final activeTextPainter = TextPainter(
textAlign: style.lineTextAlign,
textDirection: TextDirection.ltr,
);
final translationTextPainter = TextPainter(
textAlign: style.lineTextAlign,
textDirection: TextDirection.ltr,
);
textPainter.text = TextSpan(text: line.text, style: style.textStyle);
textPainter.layout(maxWidth: maxWidth);
final metrics = textPainter.computeLineMetrics();
final height = textPainter.height;
final width = textPainter.width;
activeTextPainter.text =
TextSpan(text: line.text, style: style.activeStyle);
activeTextPainter.layout(maxWidth: maxWidth);
final activceLineMetrics = activeTextPainter.computeLineMetrics();
final highlightWidth = activeTextPainter.width;
final highlightHeight = activeTextPainter.height;
double translationWidth = 0;
double translationHeight = 0;
if (line.translation != null) {
translationTextPainter.text = TextSpan(
text: line.translation,
style: style.translationStyle,
);
translationTextPainter.layout(maxWidth: maxWidth);
translationWidth = translationTextPainter.width;
translationHeight = translationTextPainter.height;
}
final words = _calcWordMetrics(
line, textPainter, activeTextPainter, translationTextPainter);
lineMetrics.add(
LineMetrics(
line: line,
height: height,
width: width,
activeWidth: highlightWidth,
activeHeight: highlightHeight,
translationWidth: translationWidth,
translationHeight: translationHeight,
activeMetrics: activceLineMetrics,
metrics: metrics,
words: words,
textPainter: textPainter,
activeTextPainter: activeTextPainter,
translationTextPainter: translationTextPainter,
),
);
}
return LyricLayout._internal(
lineMetrics,
style,
viewSize,
style.calcSelectionAnchorPosition(viewSize.height),
style.calcActiveAnchorPosition(viewSize.height),
);
}