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