button.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*************************************************************************/
  2. /* button.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 BUTTON_H
  31. #define BUTTON_H
  32. #include "scene/gui/base_button.h"
  33. #include "scene/resources/text_paragraph.h"
  34. class Button : public BaseButton {
  35. GDCLASS(Button, BaseButton);
  36. public:
  37. enum TextAlign {
  38. ALIGN_LEFT,
  39. ALIGN_CENTER,
  40. ALIGN_RIGHT
  41. };
  42. private:
  43. bool flat = false;
  44. String text;
  45. String xl_text;
  46. Ref<TextParagraph> text_buf;
  47. Dictionary opentype_features;
  48. String language;
  49. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  50. Ref<Texture2D> icon;
  51. bool expand_icon = false;
  52. bool clip_text = false;
  53. TextAlign align = ALIGN_CENTER;
  54. TextAlign icon_align = ALIGN_LEFT;
  55. float _internal_margin[4] = {};
  56. void _shape();
  57. protected:
  58. void _set_internal_margin(Side p_side, float p_value);
  59. void _notification(int p_what);
  60. static void _bind_methods();
  61. bool _set(const StringName &p_name, const Variant &p_value);
  62. bool _get(const StringName &p_name, Variant &r_ret) const;
  63. void _get_property_list(List<PropertyInfo> *p_list) const;
  64. public:
  65. virtual Size2 get_minimum_size() const override;
  66. void set_text(const String &p_text);
  67. String get_text() const;
  68. void set_text_direction(TextDirection p_text_direction);
  69. TextDirection get_text_direction() const;
  70. void set_opentype_feature(const String &p_name, int p_value);
  71. int get_opentype_feature(const String &p_name) const;
  72. void clear_opentype_features();
  73. void set_language(const String &p_language);
  74. String get_language() const;
  75. void set_icon(const Ref<Texture2D> &p_icon);
  76. Ref<Texture2D> get_icon() const;
  77. void set_expand_icon(bool p_enabled);
  78. bool is_expand_icon() const;
  79. void set_flat(bool p_enabled);
  80. bool is_flat() const;
  81. void set_clip_text(bool p_enabled);
  82. bool get_clip_text() const;
  83. void set_text_align(TextAlign p_align);
  84. TextAlign get_text_align() const;
  85. void set_icon_align(TextAlign p_align);
  86. TextAlign get_icon_align() const;
  87. Button(const String &p_text = String());
  88. ~Button();
  89. };
  90. VARIANT_ENUM_CAST(Button::TextAlign);
  91. #endif