TxTextSpriteBlock constructor

TxTextSpriteBlock({
  1. required int msgCode,
  2. required int width,
  3. required int fontSize,
  4. required int maxDisplayRows,
  5. String? fontFamily,
  6. TextAlign textAlign = ui.TextAlign.left,
  7. TextDirection textDirection = ui.TextDirection.ltr,
  8. required String text,
})

Represents an (optionally) multi-line block of text of a specified width and number of visible rows at a specified lineHeight If the supplied text string is longer, only the last displayRows will be shown rendered and sent to Frame. If the supplied text string has fewer than or equal to displayRows, only the number of actual rows will be rendered and sent to Frame If any given line of text is shorter than width, the text Sprite will be set to the actual width required. When sending TxTextSpriteBlock to Frame, the sendMessage() will send the header with block dimensions and line-by-line offsets and the user then sends each line[] as a TxSprite message with the same msgCode as the Block, and the frame app will use the offsets to place each line. By sending each line separately we can display them as they arrive, as well as reducing overall memory requirement (each concat() call is smaller). After calling the constructor, check isNotEmpty before calling rasterize() and sending the header or the sprites. Sending a TextSpriteBlock with no lines is not intended usage. text is trimmed (leading and trailing whitespace) before laying out the paragraph, but any blank lines within the range of displayed rows will be sent as an empty (1px) TxSprite

Implementation

TxTextSpriteBlock(
    {required super.msgCode,
    required int width,
    required int fontSize,
    required int maxDisplayRows,
    String? fontFamily,
    ui.TextAlign textAlign = ui.TextAlign.left,
    ui.TextDirection textDirection = ui.TextDirection.ltr,
    required String text})
    : _msgCode = msgCode,
      _width = width,
      _fontSize = fontSize,
      _maxDisplayRows = maxDisplayRows {
  final paragraphBuilder = ui.ParagraphBuilder(ui.ParagraphStyle(
    textAlign: textAlign,
    textDirection: textDirection,
    fontFamily: fontFamily, // gets platform default if null
    fontSize: _fontSize.toDouble(), // Adjust font size as needed
  ));

  paragraphBuilder.addText(text);
  _paragraph = paragraphBuilder.build();

  _paragraph.layout(ui.ParagraphConstraints(width: width.toDouble()));

  // work out height using metrics after paragraph.layout() call
  _lineMetrics = _paragraph.computeLineMetrics();
}