mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-03 09:29:38 +01:00
Add uri
property for LinkButton
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com> (cherry picked from commit d73a9b56b08864b5e5ccf0df910190b064ff7463)
This commit is contained in:
parent
3b7b860b18
commit
b5c01b8703
@ -18,7 +18,16 @@
|
|||||||
The button's text that will be displayed inside the button's area.
|
The button's text that will be displayed inside the button's area.
|
||||||
</member>
|
</member>
|
||||||
<member name="underline" type="int" setter="set_underline_mode" getter="get_underline_mode" enum="LinkButton.UnderlineMode" default="0">
|
<member name="underline" type="int" setter="set_underline_mode" getter="get_underline_mode" enum="LinkButton.UnderlineMode" default="0">
|
||||||
Determines when to show the underline. See [enum UnderlineMode] for options.
|
The underline mode to use for the text. See [enum LinkButton.UnderlineMode] for the available modes.
|
||||||
|
</member>
|
||||||
|
<member name="uri" type="String" setter="set_uri" getter="get_uri" default="""">
|
||||||
|
The [url=https://en.wikipedia.org/wiki/Uniform_Resource_Identifier]URI[/url] for this [LinkButton]. If set to a valid URI, pressing the button opens the URI using the operating system's default program for the protocol (via [method OS.shell_open]). HTTP and HTTPS URLs open the default web browser.
|
||||||
|
[b]Examples:[/b]
|
||||||
|
[codeblock]
|
||||||
|
uri = "https://godotengine.org" # Opens the URL in the default web browser.
|
||||||
|
uri = "C:\SomeFolder" # Opens the file explorer at the given path.
|
||||||
|
uri = "C:\SomeImage.png" # Opens the given image in the default viewing app.
|
||||||
|
[/codeblock]
|
||||||
</member>
|
</member>
|
||||||
</members>
|
</members>
|
||||||
<constants>
|
<constants>
|
||||||
|
@ -136,6 +136,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
|
|||||||
capitalize_string_remaps["rcedit"] = "rcedit";
|
capitalize_string_remaps["rcedit"] = "rcedit";
|
||||||
capitalize_string_remaps["rcodesign"] = "rcodesign";
|
capitalize_string_remaps["rcodesign"] = "rcodesign";
|
||||||
capitalize_string_remaps["signtool"] = "signtool";
|
capitalize_string_remaps["signtool"] = "signtool";
|
||||||
|
capitalize_string_remaps["uri"] = "URI";
|
||||||
capitalize_string_remaps["wine"] = "wine";
|
capitalize_string_remaps["wine"] = "wine";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "link_button.h"
|
#include "link_button.h"
|
||||||
|
|
||||||
#include "core/string/translation.h"
|
#include "core/string/translation.h"
|
||||||
|
#include "core/os/os.h"
|
||||||
#include "core/input/shortcut.h"
|
#include "core/input/shortcut.h"
|
||||||
|
|
||||||
void LinkButton::set_text(const String &p_text) {
|
void LinkButton::set_text(const String &p_text) {
|
||||||
@ -48,6 +49,14 @@ String LinkButton::get_text() const {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinkButton::set_uri(const String &p_uri) {
|
||||||
|
uri = p_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
String LinkButton::get_uri() const {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
void LinkButton::set_underline_mode(UnderlineMode p_underline_mode) {
|
void LinkButton::set_underline_mode(UnderlineMode p_underline_mode) {
|
||||||
underline_mode = p_underline_mode;
|
underline_mode = p_underline_mode;
|
||||||
update();
|
update();
|
||||||
@ -57,6 +66,14 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
|
|||||||
return underline_mode;
|
return underline_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinkButton::pressed() {
|
||||||
|
if (uri.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OS::get_singleton()->shell_open(uri);
|
||||||
|
}
|
||||||
|
|
||||||
Size2 LinkButton::get_minimum_size() const {
|
Size2 LinkButton::get_minimum_size() const {
|
||||||
return get_theme_font("font")->get_string_size(xl_text);
|
return get_theme_font("font")->get_string_size(xl_text);
|
||||||
}
|
}
|
||||||
@ -130,7 +147,8 @@ void LinkButton::_notification(int p_what) {
|
|||||||
void LinkButton::_bind_methods() {
|
void LinkButton::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_text", "text"), &LinkButton::set_text);
|
ClassDB::bind_method(D_METHOD("set_text", "text"), &LinkButton::set_text);
|
||||||
ClassDB::bind_method(D_METHOD("get_text"), &LinkButton::get_text);
|
ClassDB::bind_method(D_METHOD("get_text"), &LinkButton::get_text);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_uri", "uri"), &LinkButton::set_uri);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_uri"), &LinkButton::get_uri);
|
||||||
ClassDB::bind_method(D_METHOD("set_underline_mode", "underline_mode"), &LinkButton::set_underline_mode);
|
ClassDB::bind_method(D_METHOD("set_underline_mode", "underline_mode"), &LinkButton::set_underline_mode);
|
||||||
ClassDB::bind_method(D_METHOD("get_underline_mode"), &LinkButton::get_underline_mode);
|
ClassDB::bind_method(D_METHOD("get_underline_mode"), &LinkButton::get_underline_mode);
|
||||||
|
|
||||||
@ -140,6 +158,7 @@ void LinkButton::_bind_methods() {
|
|||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text");
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "underline", PROPERTY_HINT_ENUM, "Always,On Hover,Never"), "set_underline_mode", "get_underline_mode");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "underline", PROPERTY_HINT_ENUM, "Always,On Hover,Never"), "set_underline_mode", "get_underline_mode");
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "uri"), "set_uri", "get_uri");
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkButton::LinkButton() {
|
LinkButton::LinkButton() {
|
||||||
|
@ -46,8 +46,10 @@ private:
|
|||||||
String text;
|
String text;
|
||||||
String xl_text;
|
String xl_text;
|
||||||
UnderlineMode underline_mode;
|
UnderlineMode underline_mode;
|
||||||
|
String uri;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void pressed();
|
||||||
virtual Size2 get_minimum_size() const;
|
virtual Size2 get_minimum_size() const;
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
@ -55,6 +57,8 @@ protected:
|
|||||||
public:
|
public:
|
||||||
void set_text(const String &p_text);
|
void set_text(const String &p_text);
|
||||||
String get_text() const;
|
String get_text() const;
|
||||||
|
void set_uri(const String &p_uri);
|
||||||
|
String get_uri() const;
|
||||||
|
|
||||||
void set_underline_mode(UnderlineMode p_underline_mode);
|
void set_underline_mode(UnderlineMode p_underline_mode);
|
||||||
UnderlineMode get_underline_mode() const;
|
UnderlineMode get_underline_mode() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user