label.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*************************************************************************/
  2. /* label.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. enum AutowrapMode {
  49. AUTOWRAP_OFF,
  50. AUTOWRAP_ARBITRARY,
  51. AUTOWRAP_WORD,
  52. AUTOWRAP_WORD_SMART
  53. };
  54. enum OverrunBehavior {
  55. OVERRUN_NO_TRIMMING,
  56. OVERRUN_TRIM_CHAR,
  57. OVERRUN_TRIM_WORD,
  58. OVERRUN_TRIM_ELLIPSIS,
  59. OVERRUN_TRIM_WORD_ELLIPSIS,
  60. };
  61. private:
  62. Align align = ALIGN_LEFT;
  63. VAlign valign = VALIGN_TOP;
  64. String text;
  65. String xl_text;
  66. AutowrapMode autowrap_mode = AUTOWRAP_OFF;
  67. bool clip = false;
  68. OverrunBehavior overrun_behavior = OVERRUN_NO_TRIMMING;
  69. Size2 minsize;
  70. bool uppercase = false;
  71. bool lines_dirty = true;
  72. bool dirty = true;
  73. RID text_rid;
  74. Vector<RID> lines_rid;
  75. Dictionary opentype_features;
  76. String language;
  77. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  78. Control::StructuredTextParser st_parser = STRUCTURED_TEXT_DEFAULT;
  79. Array st_args;
  80. float percent_visible = 1.0;
  81. int visible_chars = -1;
  82. int lines_skipped = 0;
  83. int max_lines_visible = -1;
  84. void _update_visible();
  85. void _shape();
  86. protected:
  87. void _notification(int p_what);
  88. static void _bind_methods();
  89. bool _set(const StringName &p_name, const Variant &p_value);
  90. bool _get(const StringName &p_name, Variant &r_ret) const;
  91. void _get_property_list(List<PropertyInfo> *p_list) const;
  92. public:
  93. virtual Size2 get_minimum_size() const override;
  94. void set_align(Align p_align);
  95. Align get_align() const;
  96. void set_valign(VAlign p_align);
  97. VAlign get_valign() const;
  98. void set_text(const String &p_string);
  99. String get_text() const;
  100. void set_text_direction(TextDirection p_text_direction);
  101. TextDirection get_text_direction() const;
  102. void set_opentype_feature(const String &p_name, int p_value);
  103. int get_opentype_feature(const String &p_name) const;
  104. void clear_opentype_features();
  105. void set_language(const String &p_language);
  106. String get_language() const;
  107. void set_structured_text_bidi_override(Control::StructuredTextParser p_parser);
  108. Control::StructuredTextParser get_structured_text_bidi_override() const;
  109. void set_structured_text_bidi_override_options(Array p_args);
  110. Array get_structured_text_bidi_override_options() const;
  111. void set_autowrap_mode(AutowrapMode p_mode);
  112. AutowrapMode get_autowrap_mode() const;
  113. void set_uppercase(bool p_uppercase);
  114. bool is_uppercase() const;
  115. void set_visible_characters(int p_amount);
  116. int get_visible_characters() const;
  117. int get_total_character_count() const;
  118. void set_clip_text(bool p_clip);
  119. bool is_clipping_text() const;
  120. void set_text_overrun_behavior(OverrunBehavior p_behavior);
  121. OverrunBehavior get_text_overrun_behavior() const;
  122. void set_percent_visible(float p_percent);
  123. float get_percent_visible() const;
  124. void set_lines_skipped(int p_lines);
  125. int get_lines_skipped() const;
  126. void set_max_lines_visible(int p_lines);
  127. int get_max_lines_visible() const;
  128. int get_line_height(int p_line = -1) const;
  129. int get_line_count() const;
  130. int get_visible_line_count() const;
  131. Label(const String &p_text = String());
  132. ~Label();
  133. };
  134. VARIANT_ENUM_CAST(Label::Align);
  135. VARIANT_ENUM_CAST(Label::VAlign);
  136. VARIANT_ENUM_CAST(Label::AutowrapMode);
  137. VARIANT_ENUM_CAST(Label::OverrunBehavior);
  138. #endif