button.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*************************************************************************/
  2. /* button.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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. private:
  37. bool flat = false;
  38. String text;
  39. String xl_text;
  40. Ref<TextParagraph> text_buf;
  41. String language;
  42. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  43. TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_NO_TRIMMING;
  44. Ref<Texture2D> icon;
  45. bool expand_icon = false;
  46. bool clip_text = false;
  47. HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_CENTER;
  48. HorizontalAlignment icon_alignment = HORIZONTAL_ALIGNMENT_LEFT;
  49. float _internal_margin[4] = {};
  50. void _shape(Ref<TextParagraph> p_paragraph = Ref<TextParagraph>(), String p_text = "");
  51. protected:
  52. void _set_internal_margin(Side p_side, float p_value);
  53. void _notification(int p_what);
  54. static void _bind_methods();
  55. public:
  56. virtual Size2 get_minimum_size() const override;
  57. Size2 get_minimum_size_for_text_and_icon(const String &p_text, Ref<Texture2D> p_icon) const;
  58. void set_text(const String &p_text);
  59. String get_text() const;
  60. void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior);
  61. TextServer::OverrunBehavior get_text_overrun_behavior() const;
  62. void set_text_direction(TextDirection p_text_direction);
  63. TextDirection get_text_direction() const;
  64. void set_language(const String &p_language);
  65. String get_language() const;
  66. void set_icon(const Ref<Texture2D> &p_icon);
  67. Ref<Texture2D> get_icon() const;
  68. void set_expand_icon(bool p_enabled);
  69. bool is_expand_icon() const;
  70. void set_flat(bool p_enabled);
  71. bool is_flat() const;
  72. void set_clip_text(bool p_enabled);
  73. bool get_clip_text() const;
  74. void set_text_alignment(HorizontalAlignment p_alignment);
  75. HorizontalAlignment get_text_alignment() const;
  76. void set_icon_alignment(HorizontalAlignment p_alignment);
  77. HorizontalAlignment get_icon_alignment() const;
  78. Button(const String &p_text = String());
  79. ~Button();
  80. };
  81. #endif // BUTTON_H