link_button.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**************************************************************************/
  2. /* link_button.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 LINK_BUTTON_H
  31. #define LINK_BUTTON_H
  32. #include "scene/gui/base_button.h"
  33. #include "scene/resources/text_line.h"
  34. class LinkButton : public BaseButton {
  35. GDCLASS(LinkButton, BaseButton);
  36. public:
  37. enum UnderlineMode {
  38. UNDERLINE_MODE_ALWAYS,
  39. UNDERLINE_MODE_ON_HOVER,
  40. UNDERLINE_MODE_NEVER
  41. };
  42. private:
  43. String text;
  44. String xl_text;
  45. Ref<TextLine> text_buf;
  46. UnderlineMode underline_mode = UNDERLINE_MODE_ALWAYS;
  47. String uri;
  48. String language;
  49. TextDirection text_direction = TEXT_DIRECTION_AUTO;
  50. TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
  51. Array st_args;
  52. struct ThemeCache {
  53. Ref<StyleBox> focus;
  54. Color font_color;
  55. Color font_focus_color;
  56. Color font_pressed_color;
  57. Color font_hover_color;
  58. Color font_hover_pressed_color;
  59. Color font_disabled_color;
  60. Ref<Font> font;
  61. int font_size = 0;
  62. int outline_size = 0;
  63. Color font_outline_color;
  64. int underline_spacing = 0;
  65. } theme_cache;
  66. void _shape();
  67. protected:
  68. virtual void pressed() override;
  69. virtual Size2 get_minimum_size() const override;
  70. void _notification(int p_what);
  71. static void _bind_methods();
  72. public:
  73. void set_text(const String &p_text);
  74. String get_text() const;
  75. void set_uri(const String &p_uri);
  76. String get_uri() const;
  77. void set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser);
  78. TextServer::StructuredTextParser get_structured_text_bidi_override() const;
  79. void set_structured_text_bidi_override_options(Array p_args);
  80. Array get_structured_text_bidi_override_options() const;
  81. void set_text_direction(TextDirection p_text_direction);
  82. TextDirection get_text_direction() const;
  83. void set_language(const String &p_language);
  84. String get_language() const;
  85. void set_underline_mode(UnderlineMode p_underline_mode);
  86. UnderlineMode get_underline_mode() const;
  87. Ref<Font> get_button_font() const;
  88. LinkButton(const String &p_text = String());
  89. };
  90. VARIANT_ENUM_CAST(LinkButton::UnderlineMode);
  91. #endif // LINK_BUTTON_H