TextNode.fromTopLeftWorld constructor

TextNode.fromTopLeftWorld({
  1. required NodeId id,
  2. required String text,
  3. required Size size,
  4. required Offset topLeftWorld,
  5. double fontSize = 24,
  6. required Color color,
  7. TextAlign align = TextAlign.left,
  8. bool isBold = false,
  9. bool isItalic = false,
  10. bool isUnderline = false,
  11. String? fontFamily,
  12. double? maxWidth,
  13. double? lineHeight,
  14. double hitPadding = 0,
  15. double opacity = 1,
  16. bool isVisible = true,
  17. bool isSelectable = true,
  18. bool isLocked = false,
  19. bool isDeletable = true,
  20. bool isTransformable = true,
})

Creates a text node positioned by its axis-aligned world top-left corner.

This helper is AABB-based: rotation/shear affects boundsWorld, so topLeftWorld is intended for UI-like positioning (selection box).

Implementation

factory TextNode.fromTopLeftWorld({
  required NodeId id,
  required String text,
  required Size size,
  required Offset topLeftWorld,
  double fontSize = 24,
  required Color color,
  TextAlign align = TextAlign.left,
  bool isBold = false,
  bool isItalic = false,
  bool isUnderline = false,
  String? fontFamily,
  double? maxWidth,
  double? lineHeight,
  double hitPadding = 0,
  double opacity = 1,
  bool isVisible = true,
  bool isSelectable = true,
  bool isLocked = false,
  bool isDeletable = true,
  bool isTransformable = true,
}) {
  final centerWorld = topLeftWorld + Offset(size.width / 2, size.height / 2);
  return TextNode(
    id: id,
    text: text,
    size: size,
    fontSize: fontSize,
    color: color,
    align: align,
    isBold: isBold,
    isItalic: isItalic,
    isUnderline: isUnderline,
    fontFamily: fontFamily,
    maxWidth: maxWidth,
    lineHeight: lineHeight,
    hitPadding: hitPadding,
    transform: Transform2D.translation(centerWorld),
    opacity: opacity,
    isVisible: isVisible,
    isSelectable: isSelectable,
    isLocked: isLocked,
    isDeletable: isDeletable,
    isTransformable: isTransformable,
  );
}