Make EditorHelp respect font size settings

This commit is contained in:
Yuri Sizov 2023-02-11 17:33:38 +01:00
parent bbbcd77217
commit 0eb3b49c39
2 changed files with 200 additions and 158 deletions

View file

@ -59,6 +59,7 @@ void EditorHelp::_update_theme_item_cache() {
theme_cache.doc_font = get_theme_font(SNAME("doc"), SNAME("EditorFonts"));
theme_cache.doc_bold_font = get_theme_font(SNAME("doc_bold"), SNAME("EditorFonts"));
theme_cache.doc_italic_font = get_theme_font(SNAME("doc_italic"), SNAME("EditorFonts"));
theme_cache.doc_title_font = get_theme_font(SNAME("doc_title"), SNAME("EditorFonts"));
theme_cache.doc_code_font = get_theme_font(SNAME("doc_source"), SNAME("EditorFonts"));
theme_cache.doc_kbd_font = get_theme_font(SNAME("doc_keyboard"), SNAME("EditorFonts"));
@ -70,6 +71,9 @@ void EditorHelp::_update_theme_item_cache() {
theme_cache.background_style = get_theme_stylebox(SNAME("background"), SNAME("EditorHelp"));
class_desc->add_theme_font_override("normal_font", theme_cache.doc_font);
class_desc->add_theme_font_size_override("normal_font_size", theme_cache.doc_font_size);
class_desc->add_theme_color_override("selection_color", get_theme_color(SNAME("selection_color"), SNAME("EditorHelp")));
class_desc->add_theme_constant_override("line_separation", get_theme_constant(SNAME("line_separation"), SNAME("EditorHelp")));
class_desc->add_theme_constant_override("table_h_separation", get_theme_constant(SNAME("table_h_separation"), SNAME("EditorHelp")));
@ -432,6 +436,38 @@ void EditorHelp::_add_bulletpoint() {
class_desc->add_text(String(prefix));
}
void EditorHelp::_push_normal_font() {
class_desc->push_font(theme_cache.doc_font);
class_desc->push_font_size(theme_cache.doc_font_size);
}
void EditorHelp::_pop_normal_font() {
class_desc->pop();
class_desc->pop();
}
void EditorHelp::_push_title_font() {
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
}
void EditorHelp::_pop_title_font() {
class_desc->pop();
class_desc->pop();
class_desc->pop();
}
void EditorHelp::_push_code_font() {
class_desc->push_font(theme_cache.doc_code_font);
class_desc->push_font_size(theme_cache.doc_code_font_size);
}
void EditorHelp::_pop_code_font() {
class_desc->pop();
class_desc->pop();
}
Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
if (!doc->class_list.has(p_class)) {
return ERR_DOES_NOT_EXIST;
@ -453,12 +489,9 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
}
void EditorHelp::_update_method_list(const Vector<DocData::MethodDoc> p_methods) {
class_desc->pop(); // title font size
class_desc->pop(); // title font
class_desc->pop(); // title color
class_desc->add_newline();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
class_desc->push_indent(1);
class_desc->push_table(2);
class_desc->set_table_column_expand(1, true);
@ -509,16 +542,14 @@ void EditorHelp::_update_method_list(const Vector<DocData::MethodDoc> p_methods)
class_desc->pop(); //table
class_desc->pop();
class_desc->pop(); // font
_pop_code_font();
class_desc->add_newline();
class_desc->add_newline();
}
void EditorHelp::_update_method_descriptions(const DocData::ClassDoc p_classdoc, const Vector<DocData::MethodDoc> p_methods, const String &p_method_type) {
String link_color_text = theme_cache.title_color.to_html(false);
class_desc->pop(); // title font size
class_desc->pop(); // title font
class_desc->pop(); // title color
class_desc->add_newline();
class_desc->add_newline();
@ -534,15 +565,15 @@ void EditorHelp::_update_method_descriptions(const DocData::ClassDoc p_classdoc,
}
for (int i = 0; i < methods_filtered.size(); i++) {
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
_add_method(methods_filtered[i], false);
class_desc->pop();
_pop_code_font();
class_desc->add_newline();
class_desc->add_newline();
class_desc->push_color(theme_cache.text_color);
class_desc->push_font(theme_cache.doc_font);
_push_normal_font();
class_desc->push_indent(1);
if (methods_filtered[i].errors_returned.size()) {
class_desc->append_text(TTR("Error codes returned:"));
@ -584,8 +615,9 @@ void EditorHelp::_update_method_descriptions(const DocData::ClassDoc p_classdoc,
}
class_desc->pop();
_pop_normal_font();
class_desc->pop();
class_desc->pop();
class_desc->add_newline();
class_desc->add_newline();
class_desc->add_newline();
@ -610,18 +642,14 @@ void EditorHelp::_update_doc() {
// Class name
section_line.push_back(Pair<String, int>(TTR("Top"), 0));
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
class_desc->push_color(theme_cache.title_color);
_push_title_font();
class_desc->add_text(TTR("Class:") + " ");
_add_type_icon(edited_class, theme_cache.doc_title_font_size);
class_desc->add_text(" ");
class_desc->push_color(theme_cache.headline_color);
_add_text(edited_class);
class_desc->pop(); // color
class_desc->pop(); // color
class_desc->pop(); // font size
class_desc->pop(); // font
_pop_title_font();
if (cd.is_deprecated) {
class_desc->add_text(" ");
@ -642,7 +670,7 @@ void EditorHelp::_update_doc() {
// Ascendents
if (!cd.inherits.is_empty()) {
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_font);
_push_normal_font();
class_desc->add_text(TTR("Inherits:") + " ");
String inherits = cd.inherits;
@ -659,7 +687,7 @@ void EditorHelp::_update_doc() {
}
}
class_desc->pop();
_pop_normal_font();
class_desc->pop();
class_desc->add_newline();
}
@ -669,7 +697,7 @@ void EditorHelp::_update_doc() {
bool found = false;
bool prev = false;
class_desc->push_font(theme_cache.doc_font);
_push_normal_font();
for (const KeyValue<String, DocData::ClassDoc> &E : doc->class_list) {
if (E.value.inherits == cd.name) {
if (!found) {
@ -687,7 +715,7 @@ void EditorHelp::_update_doc() {
prev = true;
}
}
class_desc->pop();
_pop_normal_font();
if (found) {
class_desc->pop();
@ -731,6 +759,7 @@ void EditorHelp::_update_doc() {
class_desc->pop();
class_desc->pop();
class_desc->pop();
class_desc->add_newline();
class_desc->add_newline();
class_desc->add_newline();
@ -742,23 +771,20 @@ void EditorHelp::_update_doc() {
section_line.push_back(Pair<String, int>(TTR("Description"), class_desc->get_paragraph_count() - 2));
description_line = class_desc->get_paragraph_count() - 2;
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Description"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->add_newline();
class_desc->push_color(theme_cache.text_color);
class_desc->push_font(theme_cache.doc_font);
_push_normal_font();
class_desc->push_indent(1);
_add_text(DTR(cd.description));
class_desc->pop();
_pop_normal_font();
class_desc->pop();
class_desc->pop();
class_desc->add_newline();
class_desc->add_newline();
class_desc->add_newline();
@ -782,17 +808,14 @@ void EditorHelp::_update_doc() {
// Online tutorials
if (cd.tutorials.size()) {
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Online Tutorials"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->push_indent(1);
class_desc->push_font(theme_cache.doc_code_font);
class_desc->add_newline();
_push_code_font();
for (int i = 0; i < cd.tutorials.size(); i++) {
const String link = DTR(cd.tutorials[i].link);
@ -808,8 +831,9 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
}
_pop_code_font();
class_desc->pop();
class_desc->pop();
class_desc->add_newline();
class_desc->add_newline();
}
@ -831,16 +855,13 @@ void EditorHelp::_update_doc() {
if (has_properties) {
section_line.push_back(Pair<String, int>(TTR("Properties"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Properties"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
class_desc->push_indent(1);
class_desc->push_table(4);
class_desc->set_table_column_expand(1, true);
@ -855,9 +876,9 @@ void EditorHelp::_update_doc() {
// Property type.
class_desc->push_cell();
class_desc->push_paragraph(HORIZONTAL_ALIGNMENT_RIGHT, Control::TEXT_DIRECTION_AUTO, "");
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
_add_type(cd.properties[i].type, cd.properties[i].enumeration);
class_desc->pop();
_pop_code_font();
class_desc->pop();
class_desc->pop(); // cell
@ -882,7 +903,7 @@ void EditorHelp::_update_doc() {
// Property name.
class_desc->push_cell();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
class_desc->push_color(theme_cache.headline_color);
if (describe) {
@ -896,12 +917,12 @@ void EditorHelp::_update_doc() {
}
class_desc->pop();
class_desc->pop();
_pop_code_font();
class_desc->pop(); // cell
// Property value.
class_desc->push_cell();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
if (!cd.properties[i].default_value.is_empty()) {
class_desc->push_color(theme_cache.symbol_color);
@ -932,12 +953,12 @@ void EditorHelp::_update_doc() {
EXPERIMENTAL_DOC_TAG;
}
class_desc->pop();
_pop_code_font();
class_desc->pop(); // cell
// Property setters and getters.
class_desc->push_cell();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
if (cd.is_script_doc && (!cd.properties[i].setter.is_empty() || !cd.properties[i].getter.is_empty())) {
class_desc->push_color(theme_cache.symbol_color);
@ -965,13 +986,14 @@ void EditorHelp::_update_doc() {
class_desc->pop(); // color
}
class_desc->pop();
_pop_code_font();
class_desc->pop(); // cell
}
class_desc->pop(); // table
class_desc->pop();
class_desc->pop(); // font
_pop_code_font();
class_desc->add_newline();
class_desc->add_newline();
}
@ -1000,10 +1022,10 @@ void EditorHelp::_update_doc() {
}
section_line.push_back(Pair<String, int>(TTR("Constructors"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Constructors"));
_pop_title_font();
_update_method_list(cd.constructors);
}
@ -1013,10 +1035,10 @@ void EditorHelp::_update_doc() {
}
section_line.push_back(Pair<String, int>(TTR("Methods"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Methods"));
_pop_title_font();
_update_method_list(methods);
}
@ -1026,23 +1048,19 @@ void EditorHelp::_update_doc() {
}
section_line.push_back(Pair<String, int>(TTR("Operators"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Operators"));
_pop_title_font();
_update_method_list(cd.operators);
}
// Theme properties
if (!cd.theme_properties.is_empty()) {
section_line.push_back(Pair<String, int>(TTR("Theme Properties"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Theme Properties"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->add_newline();
@ -1064,24 +1082,20 @@ void EditorHelp::_update_doc() {
if (theme_data_type != cd.theme_properties[i].data_type) {
theme_data_type = cd.theme_properties[i].data_type;
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
if (data_type_names.has(theme_data_type)) {
class_desc->add_text(data_type_names[theme_data_type]);
} else {
class_desc->add_text("");
}
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->add_newline();
}
// Theme item header.
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
_add_bulletpoint();
// Theme item object type.
@ -1106,17 +1120,17 @@ void EditorHelp::_update_doc() {
class_desc->pop();
}
class_desc->pop(); // monofont
_pop_code_font();
// Theme item description.
if (!cd.theme_properties[i].description.strip_edges().is_empty()) {
class_desc->push_font(theme_cache.doc_font);
class_desc->push_color(theme_cache.comment_color);
_push_normal_font();
class_desc->push_indent(1);
_add_text(DTR(cd.theme_properties[i].description));
class_desc->pop(); // indent
_pop_normal_font();
class_desc->pop(); // color
class_desc->pop(); // font
}
class_desc->add_newline();
@ -1134,13 +1148,9 @@ void EditorHelp::_update_doc() {
}
section_line.push_back(Pair<String, int>(TTR("Signals"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Signals"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->add_newline();
@ -1150,7 +1160,7 @@ void EditorHelp::_update_doc() {
for (int i = 0; i < cd.signals.size(); i++) {
signal_line[cd.signals[i].name] = class_desc->get_paragraph_count() - 2; // Gets overridden if description.
class_desc->push_font(theme_cache.doc_code_font); // monofont
_push_code_font();
_add_bulletpoint();
class_desc->push_color(theme_cache.headline_color);
_add_text(cd.signals[i].name);
@ -1188,16 +1198,18 @@ void EditorHelp::_update_doc() {
}
class_desc->pop();
class_desc->pop(); // end monofont
_pop_code_font();
if (!cd.signals[i].description.strip_edges().is_empty()) {
class_desc->push_font(theme_cache.doc_font);
class_desc->push_color(theme_cache.comment_color);
_push_normal_font();
class_desc->push_indent(1);
_add_text(DTR(cd.signals[i].description));
class_desc->pop(); // indent
class_desc->pop();
class_desc->pop(); // font
_pop_normal_font();
class_desc->pop(); // color
}
class_desc->add_newline();
class_desc->add_newline();
}
@ -1230,13 +1242,9 @@ void EditorHelp::_update_doc() {
// Enums
if (enums.size()) {
section_line.push_back(Pair<String, int>(TTR("Enumerations"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Enumerations"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->push_indent(1);
class_desc->add_newline();
@ -1244,7 +1252,7 @@ void EditorHelp::_update_doc() {
for (KeyValue<String, Vector<DocData::ConstantDoc>> &E : enums) {
enum_line[E.key] = class_desc->get_paragraph_count() - 2;
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
class_desc->push_color(theme_cache.title_color);
if (E.value.size() && E.value[0].is_bitfield) {
class_desc->add_text("flags ");
@ -1252,6 +1260,7 @@ void EditorHelp::_update_doc() {
class_desc->add_text("enum ");
}
class_desc->pop();
String e = E.key;
if ((e.get_slice_count(".") > 1) && (e.get_slice(".", 0) == edited_class)) {
e = e.get_slice(".", 1);
@ -1260,7 +1269,8 @@ void EditorHelp::_update_doc() {
class_desc->push_color(theme_cache.headline_color);
class_desc->add_text(e);
class_desc->pop();
class_desc->pop();
_pop_code_font();
class_desc->push_color(theme_cache.symbol_color);
class_desc->add_text(":");
class_desc->pop();
@ -1271,12 +1281,13 @@ void EditorHelp::_update_doc() {
// Enum description.
if (e != "@unnamed_enums" && cd.enums.has(e)) {
class_desc->push_color(theme_cache.text_color);
class_desc->push_font(theme_cache.doc_font);
_push_normal_font();
class_desc->push_indent(1);
_add_text(cd.enums[e]);
class_desc->pop();
_pop_normal_font();
class_desc->pop();
class_desc->pop();
class_desc->add_newline();
class_desc->add_newline();
}
@ -1295,7 +1306,7 @@ void EditorHelp::_update_doc() {
// Add the enum constant line to the constant_line map so we can locate it as a constant.
constant_line[enum_list[i].name] = class_desc->get_paragraph_count() - 2;
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
_add_bulletpoint();
class_desc->push_color(theme_cache.headline_color);
_add_text(enum_list[i].name);
@ -1306,7 +1317,7 @@ void EditorHelp::_update_doc() {
class_desc->push_color(theme_cache.value_color);
_add_text(_fix_constant(enum_list[i].value));
class_desc->pop();
class_desc->pop();
_pop_code_font();
if (enum_list[i].is_deprecated) {
DEPRECATED_DOC_TAG;
@ -1319,10 +1330,10 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
if (!enum_list[i].description.strip_edges().is_empty()) {
class_desc->push_font(theme_cache.doc_font);
class_desc->push_color(theme_cache.comment_color);
_push_normal_font();
_add_text(DTR(enum_list[i].description));
class_desc->pop();
_pop_normal_font();
class_desc->pop();
if (DTR(enum_list[i].description).find("\n") > 0) {
class_desc->add_newline();
@ -1348,20 +1359,17 @@ void EditorHelp::_update_doc() {
// Constants
if (constants.size()) {
section_line.push_back(Pair<String, int>(TTR("Constants"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Constants"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->push_indent(1);
class_desc->add_newline();
for (int i = 0; i < constants.size(); i++) {
constant_line[constants[i].name] = class_desc->get_paragraph_count() - 2;
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
if (constants[i].value.begins_with("Color(") && constants[i].value.ends_with(")")) {
String stripped = constants[i].value.replace(" ", "").replace("Color(", "").replace(")", "");
@ -1385,7 +1393,7 @@ void EditorHelp::_update_doc() {
_add_text(_fix_constant(constants[i].value));
class_desc->pop();
class_desc->pop();
_pop_code_font();
if (constants[i].is_deprecated) {
DEPRECATED_DOC_TAG;
@ -1398,10 +1406,10 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
if (!constants[i].description.strip_edges().is_empty()) {
class_desc->push_font(theme_cache.doc_font);
class_desc->push_color(theme_cache.comment_color);
_push_normal_font();
_add_text(DTR(constants[i].description));
class_desc->pop();
_pop_normal_font();
class_desc->pop();
if (DTR(constants[i].description).find("\n") > 0) {
class_desc->add_newline();
@ -1423,13 +1431,9 @@ void EditorHelp::_update_doc() {
}
section_line.push_back(Pair<String, int>(TTR("Annotations"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Annotations"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->add_newline();
@ -1439,7 +1443,7 @@ void EditorHelp::_update_doc() {
for (int i = 0; i < cd.annotations.size(); i++) {
annotation_line[cd.annotations[i].name] = class_desc->get_paragraph_count() - 2; // Gets overridden if description.
class_desc->push_font(theme_cache.doc_code_font); // monofont
_push_code_font();
_add_bulletpoint();
class_desc->push_color(theme_cache.headline_color);
_add_text(cd.annotations[i].name);
@ -1491,16 +1495,16 @@ void EditorHelp::_update_doc() {
class_desc->pop();
}
class_desc->pop(); // end monofont
_pop_code_font();
if (!cd.annotations[i].description.strip_edges().is_empty()) {
class_desc->push_font(theme_cache.doc_font);
class_desc->push_color(theme_cache.comment_color);
_push_normal_font();
class_desc->push_indent(1);
_add_text(DTR(cd.annotations[i].description));
class_desc->pop(); // indent
class_desc->pop();
class_desc->pop(); // font
_pop_normal_font();
class_desc->pop(); // color
} else {
class_desc->push_indent(1);
class_desc->add_image(get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
@ -1525,13 +1529,9 @@ void EditorHelp::_update_doc() {
// Property descriptions
if (has_properties) {
section_line.push_back(Pair<String, int>(TTR("Property Descriptions"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Property Descriptions"));
class_desc->pop(); // font size
class_desc->pop(); // font
class_desc->pop(); // color
_pop_title_font();
class_desc->add_newline();
class_desc->add_newline();
@ -1547,16 +1547,16 @@ void EditorHelp::_update_doc() {
class_desc->set_table_column_expand(1, true);
class_desc->push_cell();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
_add_bulletpoint();
_add_type(cd.properties[i].type, cd.properties[i].enumeration);
class_desc->add_text(" ");
class_desc->pop(); // font
_pop_code_font();
class_desc->pop(); // cell
class_desc->push_cell();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
class_desc->push_color(theme_cache.headline_color);
_add_text(cd.properties[i].name);
class_desc->pop(); // color
@ -1608,7 +1608,7 @@ void EditorHelp::_update_doc() {
class_desc->pop(); // color
}
class_desc->pop(); // font
_pop_code_font();
class_desc->pop(); // cell
// Script doc doesn't have setter, getter.
@ -1623,8 +1623,9 @@ void EditorHelp::_update_doc() {
class_desc->pop(); // cell
class_desc->push_cell();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
class_desc->push_color(theme_cache.text_color);
if (method_map[cd.properties[i].setter].arguments.size() > 1) {
// Setters with additional arguments are exposed in the method list, so we link them here for quick access.
class_desc->push_meta("@method " + cd.properties[i].setter);
@ -1633,12 +1634,14 @@ void EditorHelp::_update_doc() {
} else {
class_desc->add_text(cd.properties[i].setter + TTR("(value)"));
}
class_desc->pop(); // color
class_desc->push_color(theme_cache.comment_color);
class_desc->add_text(" setter");
class_desc->pop(); // color
class_desc->pop(); // font
_pop_code_font();
class_desc->pop(); // cell
method_line[cd.properties[i].setter] = property_line[cd.properties[i].name];
}
@ -1647,8 +1650,9 @@ void EditorHelp::_update_doc() {
class_desc->pop(); // cell
class_desc->push_cell();
class_desc->push_font(theme_cache.doc_code_font);
_push_code_font();
class_desc->push_color(theme_cache.text_color);
if (method_map[cd.properties[i].getter].arguments.size() > 0) {
// Getters with additional arguments are exposed in the method list, so we link them here for quick access.
class_desc->push_meta("@method " + cd.properties[i].getter);
@ -1657,12 +1661,14 @@ void EditorHelp::_update_doc() {
} else {
class_desc->add_text(cd.properties[i].getter + "()");
}
class_desc->pop(); //color
class_desc->pop(); // color
class_desc->push_color(theme_cache.comment_color);
class_desc->add_text(" getter");
class_desc->pop(); //color
class_desc->pop(); //font
class_desc->pop(); //cell
class_desc->pop(); // color
_pop_code_font();
class_desc->pop(); // cell
method_line[cd.properties[i].getter] = property_line[cd.properties[i].name];
}
}
@ -1673,7 +1679,7 @@ void EditorHelp::_update_doc() {
class_desc->add_newline();
class_desc->push_color(theme_cache.text_color);
class_desc->push_font(theme_cache.doc_font);
_push_normal_font();
class_desc->push_indent(1);
if (!cd.properties[i].description.strip_edges().is_empty()) {
_add_text(DTR(cd.properties[i].description));
@ -1689,8 +1695,9 @@ void EditorHelp::_update_doc() {
class_desc->pop();
}
class_desc->pop();
_pop_normal_font();
class_desc->pop();
class_desc->pop();
class_desc->add_newline();
class_desc->add_newline();
class_desc->add_newline();
@ -1700,30 +1707,30 @@ void EditorHelp::_update_doc() {
// Constructor descriptions
if (!cd.constructors.is_empty()) {
section_line.push_back(Pair<String, int>(TTR("Constructor Descriptions"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Constructor Descriptions"));
_pop_title_font();
_update_method_descriptions(cd, cd.constructors, "constructor");
}
// Method descriptions
if (!methods.is_empty()) {
section_line.push_back(Pair<String, int>(TTR("Method Descriptions"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Method Descriptions"));
_pop_title_font();
_update_method_descriptions(cd, methods, "method");
}
// Operator descriptions
if (!cd.operators.is_empty()) {
section_line.push_back(Pair<String, int>(TTR("Operator Descriptions"), class_desc->get_paragraph_count() - 2));
class_desc->push_color(theme_cache.title_color);
class_desc->push_font(theme_cache.doc_title_font);
class_desc->push_font_size(theme_cache.doc_title_font_size);
_push_title_font();
class_desc->add_text(TTR("Operator Descriptions"));
_pop_title_font();
_update_method_descriptions(cd, cd.operators, "operator");
}
@ -1818,6 +1825,9 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
Ref<Font> doc_code_font = p_owner_node->get_theme_font(SNAME("doc_source"), SNAME("EditorFonts"));
Ref<Font> doc_kbd_font = p_owner_node->get_theme_font(SNAME("doc_keyboard"), SNAME("EditorFonts"));
int doc_code_font_size = p_owner_node->get_theme_font_size(SNAME("doc_source_size"), SNAME("EditorFonts"));
int doc_kbd_font_size = p_owner_node->get_theme_font_size(SNAME("doc_keyboard_size"), SNAME("EditorFonts"));
const Color type_color = p_owner_node->get_theme_color(SNAME("type_color"), SNAME("EditorHelp"));
const Color code_color = p_owner_node->get_theme_color(SNAME("code_color"), SNAME("EditorHelp"));
const Color kbd_color = p_owner_node->get_theme_color(SNAME("kbd_color"), SNAME("EditorHelp"));
@ -1941,10 +1951,12 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
if (tag != "/img") {
p_rt->pop();
if (code_tag) {
p_rt->pop(); // font size
// Pop both color and background color.
p_rt->pop();
p_rt->pop();
} else if (codeblock_tag) {
p_rt->pop(); // font size
// Pop color, cell and table.
p_rt->pop();
p_rt->pop();
@ -1966,6 +1978,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
// Use monospace font to make clickable references
// easier to distinguish from inline code and other text.
p_rt->push_font(doc_code_font);
p_rt->push_font_size(doc_code_font_size);
Color target_color = link_color;
if (link_tag == "method") {
@ -1980,7 +1993,9 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
p_rt->add_text(link_target + (link_tag == "method" ? "()" : ""));
p_rt->pop();
p_rt->pop();
p_rt->pop();
p_rt->pop(); // font size
p_rt->pop(); // font
pos = brk_end + 1;
} else if (tag.begins_with("param ")) {
@ -1989,13 +2004,16 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
// Use monospace font with translucent background color to make code easier to distinguish from other text.
p_rt->push_font(doc_code_font);
p_rt->push_font_size(doc_code_font_size);
p_rt->push_bgcolor(param_bg_color);
p_rt->push_color(code_color);
p_rt->add_text(param_name);
p_rt->pop();
p_rt->pop();
p_rt->pop();
p_rt->pop(); // font size
p_rt->pop(); // font
pos = brk_end + 1;
} else if (doc->class_list.has(tag)) {
@ -2003,29 +2021,37 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
// Use monospace font to make clickable references
// easier to distinguish from inline code and other text.
p_rt->push_font(doc_code_font);
p_rt->push_font_size(doc_code_font_size);
p_rt->push_color(type_color);
p_rt->push_meta("#" + tag);
p_rt->add_text(tag);
p_rt->pop();
p_rt->pop();
p_rt->pop();
p_rt->pop(); // font size
p_rt->pop(); // font
pos = brk_end + 1;
} else if (tag == "b") {
// Use bold font.
p_rt->push_font(doc_bold_font);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "i") {
// Use italics font.
p_rt->push_font(doc_italic_font);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "code") {
// Use monospace font with darkened background color to make code easier to distinguish from other text.
p_rt->push_font(doc_code_font);
p_rt->push_font_size(doc_code_font_size);
p_rt->push_bgcolor(code_bg_color);
p_rt->push_color(code_color.lerp(p_owner_node->get_theme_color(SNAME("error_color"), SNAME("Editor")), 0.6));
code_tag = true;
pos = brk_end + 1;
tag_stack.push_front(tag);
@ -2034,22 +2060,28 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
// Use a single-column table with cell row background color instead of `[bgcolor]`.
// This makes the background color highlight cover the entire block, rather than individual lines.
p_rt->push_font(doc_code_font);
p_rt->push_font_size(doc_code_font_size);
p_rt->push_table(1);
p_rt->push_cell();
p_rt->set_cell_row_background_color(code_bg_color, Color(code_bg_color, 0.99));
p_rt->set_cell_padding(Rect2(10 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE));
p_rt->push_color(code_dark_color);
codeblock_tag = true;
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "kbd") {
// Use keyboard font with custom color and background color.
p_rt->push_font(doc_kbd_font);
p_rt->push_font_size(doc_kbd_font_size);
p_rt->push_bgcolor(kbd_bg_color);
p_rt->push_color(kbd_color);
code_tag = true; // Though not strictly a code tag, logic is similar.
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "center") {
// Align to center.
p_rt->push_paragraph(HORIZONTAL_ALIGNMENT_CENTER, Control::TEXT_DIRECTION_AUTO, "");
@ -2083,6 +2115,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
} else if (tag.begins_with("url=")) {
String url = tag.substr(4, tag.length());
p_rt->push_meta(url);
pos = brk_end + 1;
tag_stack.push_front("url");
} else if (tag == "img") {
@ -2103,6 +2136,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, Control
String col = tag.substr(6, tag.length());
Color color = Color::from_string(col, Color());
p_rt->push_color(color);
pos = brk_end + 1;
tag_stack.push_front("color");

View file

@ -139,6 +139,7 @@ class EditorHelp : public VBoxContainer {
Ref<Font> doc_font;
Ref<Font> doc_bold_font;
Ref<Font> doc_italic_font;
Ref<Font> doc_title_font;
Ref<Font> doc_code_font;
Ref<Font> doc_kbd_font;
@ -163,6 +164,13 @@ class EditorHelp : public VBoxContainer {
void _add_bulletpoint();
void _push_normal_font();
void _pop_normal_font();
void _push_title_font();
void _pop_title_font();
void _push_code_font();
void _pop_code_font();
void _class_desc_finished();
void _class_list_select(const String &p_select);
void _class_desc_select(const String &p_select);