From 6c675d4e3f9c112626312f187f818e814f79ccd5 Mon Sep 17 00:00:00 2001 From: Micky Date: Wed, 20 Nov 2024 20:08:07 +0100 Subject: [PATCH] Improve appearance of external links in built-in docs --- editor/editor_help.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index f0c54b9edd04..0a791dd4a73f 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -2407,6 +2407,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C const Ref doc_code_font = p_owner_node->get_theme_font(SNAME("doc_source"), EditorStringName(EditorFonts)); const Ref doc_kbd_font = p_owner_node->get_theme_font(SNAME("doc_keyboard"), EditorStringName(EditorFonts)); + const int doc_font_size = p_owner_node->get_theme_font_size(SNAME("doc_size"), EditorStringName(EditorFonts)); const int doc_code_font_size = p_owner_node->get_theme_font_size(SNAME("doc_source_size"), EditorStringName(EditorFonts)); const int doc_kbd_font_size = p_owner_node->get_theme_font_size(SNAME("doc_keyboard_size"), EditorStringName(EditorFonts)); @@ -2519,7 +2520,15 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C tag_stack.pop_front(); pos = brk_end + 1; - if (tag != "/img") { + if (tag == "/img") { + // Nothing to do. + } else if (tag == "/url") { + p_rt->pop(); // meta + p_rt->pop(); // hint + p_rt->pop(); // color + p_rt->add_text(" "); + p_rt->add_image(p_owner_node->get_editor_theme_icon(SNAME("ExternalLink")), 0, doc_font_size, link_color); + } else { p_rt->pop(); } } else if (tag.begins_with("method ") || tag.begins_with("constructor ") || tag.begins_with("operator ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ") || tag.begins_with("constant ") || tag.begins_with("annotation ") || tag.begins_with("theme_item ")) { @@ -2787,19 +2796,21 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C } else if (tag == "rb") { p_rt->add_text("]"); pos = brk_end + 1; - } else if (tag == "url") { - int end = bbcode.find_char('[', brk_end); - if (end == -1) { - end = bbcode.length(); + } else if (tag == "url" || tag.begins_with("url=")) { + String url; + if (tag.begins_with("url=")) { + url = tag.substr(4); + } else { + int end = bbcode.find_char('[', brk_end); + if (end == -1) { + end = bbcode.length(); + } + url = bbcode.substr(brk_end + 1, end - brk_end - 1); } - String url = bbcode.substr(brk_end + 1, end - brk_end - 1); - p_rt->push_meta(url); - pos = brk_end + 1; - tag_stack.push_front(tag); - } else if (tag.begins_with("url=")) { - String url = tag.substr(4); - p_rt->push_meta(url); + p_rt->push_color(link_color); + p_rt->push_hint(url + "\n\n" + TTR("Click to open in browser.")); + p_rt->push_meta(url, RichTextLabel::META_UNDERLINE_ON_HOVER); pos = brk_end + 1; tag_stack.push_front("url");