link_button.h 4.1 KB

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