ScrollTextBoxComponent<T extends TextRenderer> constructor

ScrollTextBoxComponent<T extends TextRenderer>({
  1. required Vector2 size,
  2. String? text,
  3. T? textRenderer,
  4. TextBoxConfig? boxConfig,
  5. Anchor align = Anchor.topLeft,
  6. double pixelRatio = 1.0,
  7. Vector2? position,
  8. Vector2? scale,
  9. double angle = 0.0,
  10. Anchor? anchor = Anchor.topLeft,
  11. int? priority,
  12. ComponentKey? key,
  13. List<Component>? children,
  14. void onComplete()?,
})

Constructor for ScrollTextBoxComponent.

  • size: Specifies the size of the text box. Must have positive dimensions.
  • text: The text content to be displayed.
  • textRenderer: Handles the rendering of the text.
  • boxConfig: Configuration for the text box appearance.
  • onComplete: Callback will be executed after all text is displayed.
  • Other parameters include alignment, pixel ratio, and positioning settings. An assertion ensures that the size has positive dimensions.

Implementation

ScrollTextBoxComponent({
  required Vector2 size,
  String? text,
  T? textRenderer,
  TextBoxConfig? boxConfig,
  Anchor align = Anchor.topLeft,
  double pixelRatio = 1.0,
  super.position,
  super.scale,
  double angle = 0.0,
  super.anchor = Anchor.topLeft,
  super.priority,
  super.key,
  List<Component>? children,
  void Function()? onComplete,
})  : assert(
        size.x > 0 && size.y > 0,
        'size must have positive dimensions: $size',
      ),
      super(size: size) {
  final marginTop = boxConfig?.margins.top ?? 0;
  final marginBottom = boxConfig?.margins.bottom ?? 0;
  final innerMargins = EdgeInsets.fromLTRB(0, marginTop, 0, marginBottom);

  boxConfig ??= const TextBoxConfig();
  boxConfig = TextBoxConfig(
    timePerChar: boxConfig.timePerChar,
    dismissDelay: boxConfig.dismissDelay,
    growingBox: boxConfig.growingBox,
    maxWidth: size.x,
    margins: EdgeInsets.fromLTRB(
      boxConfig.margins.left,
      0,
      boxConfig.margins.right,
      0,
    ),
  );
  _scrollTextBoxComponent = _ScrollTextBoxComponent<T>(
    text: text,
    textRenderer: textRenderer,
    boxConfig: boxConfig,
    align: align,
    pixelRatio: pixelRatio,
    onComplete: onComplete,
  );
  newLineNotifier = _scrollTextBoxComponent.newLineNotifier;

  _scrollTextBoxComponent.setOwnerComponent = this;
  // Integrates the [ClipComponent] for managing
  // the text box's scrollable area.
  add(
    ClipComponent.rectangle(
      size: size - Vector2(0, innerMargins.vertical),
      position: Vector2(0, innerMargins.top),
      angle: angle,
      scale: scale,
      priority: priority,
      children: children,
    )..add(_scrollTextBoxComponent),
  );
}