TextAlignment.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * The Alignment of a TextLabel.
  3. * Specifically the label's position coordinates within the Bounding Box.
  4. * For LeftBottom, the label's position is at the left bottom corner of its Bounding Box.
  5. * (used for example with title, composer, author, etc.)
  6. * (see Show Bounding Box For -> Labels in the local demo)
  7. */
  8. export enum TextAlignmentEnum {
  9. LeftTop,
  10. LeftCenter,
  11. LeftBottom,
  12. CenterTop,
  13. CenterCenter,
  14. CenterBottom,
  15. RightTop,
  16. RightCenter,
  17. RightBottom
  18. }
  19. /*
  20. * TODO this could be split into two alignments, e.g. <Left, Top> for LeftTop.
  21. * A function like IsLeft would be easier with the split.
  22. * On the other hand, accessing these values will be more complex
  23. */
  24. export class TextAlignment {
  25. public static IsLeft(textAlignment: TextAlignmentEnum): boolean {
  26. return textAlignment === TextAlignmentEnum.LeftTop
  27. || textAlignment === TextAlignmentEnum.LeftCenter
  28. || textAlignment === TextAlignmentEnum.LeftBottom;
  29. }
  30. public static IsCenterAligned(textAlignment: TextAlignmentEnum): boolean {
  31. return textAlignment === TextAlignmentEnum.CenterTop
  32. || textAlignment === TextAlignmentEnum.CenterCenter
  33. || textAlignment === TextAlignmentEnum.CenterBottom;
  34. }
  35. public static IsRight(textAlignment: TextAlignmentEnum): boolean {
  36. return textAlignment === TextAlignmentEnum.RightTop
  37. || textAlignment === TextAlignmentEnum.RightCenter
  38. || textAlignment === TextAlignmentEnum.RightBottom;
  39. }
  40. }