scrollText method

Future<void> scrollText(
  1. String text, {
  2. int linesPerFrame = 5,
  3. double delay = 0.12,
  4. PaletteColors? textColor,
})

Scrolls text on the display.

Args: text (String): The text to scroll. linesPerFrame (int): The number of lines to scroll per frame. Defaults to 5. delay (double): The delay between frames in seconds. Defaults to 0.12. textColor (PaletteColors?): The color of the text.

Implementation

Future<void> scrollText(String text,
    {int linesPerFrame = 5,
    double delay = 0.12,
    PaletteColors? textColor}) async {
  if (!frame.useLibrary) {
    throw Exception("Cannot call scrollText without library helpers");
  }
  text = wrapText(text, 640);
  final totalHeight = getTextHeight(text);
  if (totalHeight < 400) {
    await writeText(text, x: 1, y:1, color: textColor);
    return;
  }
  String textColorName = textColor?.name ?? PaletteColors.white.name;
  await frame.runLua(
    'scrollText("${frame.escapeLuaString(text)}",$lineHeight,$totalHeight,$linesPerFrame,$delay,"$textColorName",$charSpacing)',
    checked: true,
    timeout: Duration(
      seconds: (totalHeight / linesPerFrame * (delay + 0.1) + 5).toInt(),
    ),
  );
}