label.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /**************************************************************************/
  2. /* label.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef LABEL_H
  31. #define LABEL_H
  32. #include "scene/gui/control.h"
  33. class Label : public Control {
  34. GDCLASS(Label, Control);
  35. public:
  36. enum Align {
  37. ALIGN_LEFT,
  38. ALIGN_CENTER,
  39. ALIGN_RIGHT,
  40. ALIGN_FILL
  41. };
  42. enum VAlign {
  43. VALIGN_TOP,
  44. VALIGN_CENTER,
  45. VALIGN_BOTTOM,
  46. VALIGN_FILL
  47. };
  48. private:
  49. Align align;
  50. VAlign valign;
  51. String text;
  52. String xl_text;
  53. bool autowrap;
  54. bool clip;
  55. Size2 minsize;
  56. int line_count;
  57. bool uppercase;
  58. int get_longest_line_width() const;
  59. struct WordCache {
  60. enum {
  61. CHAR_NEWLINE = -1,
  62. CHAR_WRAPLINE = -2
  63. };
  64. int char_pos; // if -1, then newline
  65. int word_len;
  66. int pixel_width;
  67. int space_count;
  68. WordCache *next;
  69. WordCache() {
  70. char_pos = 0;
  71. word_len = 0;
  72. pixel_width = 0;
  73. next = nullptr;
  74. space_count = 0;
  75. }
  76. };
  77. bool word_cache_dirty;
  78. void regenerate_word_cache();
  79. float percent_visible;
  80. WordCache *word_cache;
  81. int total_char_cache;
  82. int visible_chars;
  83. int lines_skipped;
  84. int max_lines_visible;
  85. protected:
  86. void _notification(int p_what);
  87. static void _bind_methods();
  88. // bind helpers
  89. public:
  90. virtual Size2 get_minimum_size() const;
  91. void set_align(Align p_align);
  92. Align get_align() const;
  93. void set_valign(VAlign p_align);
  94. VAlign get_valign() const;
  95. void set_text(const String &p_string);
  96. String get_text() const;
  97. void set_autowrap(bool p_autowrap);
  98. bool has_autowrap() const;
  99. void set_uppercase(bool p_uppercase);
  100. bool is_uppercase() const;
  101. void set_visible_characters(int p_amount);
  102. int get_visible_characters() const;
  103. int get_total_character_count() const;
  104. void set_clip_text(bool p_clip);
  105. bool is_clipping_text() const;
  106. void set_percent_visible(float p_percent);
  107. float get_percent_visible() const;
  108. void set_lines_skipped(int p_lines);
  109. int get_lines_skipped() const;
  110. void set_max_lines_visible(int p_lines);
  111. int get_max_lines_visible() const;
  112. int get_line_height() const;
  113. int get_line_count() const;
  114. int get_visible_line_count() const;
  115. Label(const String &p_text = String());
  116. ~Label();
  117. };
  118. VARIANT_ENUM_CAST(Label::Align);
  119. VARIANT_ENUM_CAST(Label::VAlign);
  120. #endif // LABEL_H