Merge pull request #14692 from poke1024/docsgroups

Docs methods grouping by prefix
This commit is contained in:
Rémi Verschelde 2017-12-17 14:23:49 +01:00 committed by GitHub
commit 93c9aada67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 144 additions and 127 deletions

View file

@ -522,6 +522,19 @@ EditorHelpIndex::EditorHelpIndex() {
/// /////////////////////////////////
DocData *EditorHelp::doc = NULL;
void EditorHelp::_init_colors() {
title_color = get_color("accent_color", "Editor");
text_color = get_color("default_color", "RichTextLabel");
headline_color = get_color("headline_color", "EditorHelp");
base_type_color = title_color.linear_interpolate(text_color, 0.5);
comment_color = Color(text_color.r, text_color.g, text_color.b, 0.6);
symbol_color = comment_color;
value_color = Color(text_color.r, text_color.g, text_color.b, 0.4);
qualifier_color = Color(text_color.r, text_color.g, text_color.b, 0.8);
type_color = get_color("accent_color", "Editor").linear_interpolate(text_color, 0.5);
}
void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
if (!is_visible_in_tree())
@ -654,6 +667,86 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) {
class_desc->pop();
}
void EditorHelp::_add_method(const DocData::MethodDoc &p_method, bool p_overview) {
method_line[p_method.name] = class_desc->get_line_count() - 2; //gets overridden if description
const bool is_vararg = p_method.qualifiers.find("vararg") != -1;
if (p_overview) {
class_desc->push_cell();
class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
}
_add_type(p_method.return_type, p_method.return_enum);
if (p_overview) {
class_desc->pop(); //align
class_desc->pop(); //cell
class_desc->push_cell();
} else {
class_desc->add_text(" ");
}
if (p_overview && p_method.description != "") {
class_desc->push_meta("@method" + p_method.name);
}
class_desc->push_color(headline_color);
_add_text(p_method.name);
class_desc->pop();
if (p_overview && p_method.description != "") {
class_desc->pop(); //meta
}
class_desc->push_color(symbol_color);
class_desc->add_text(p_method.arguments.size() || is_vararg ? "( " : "(");
class_desc->pop();
for (int j = 0; j < p_method.arguments.size(); j++) {
class_desc->push_color(text_color);
if (j > 0)
class_desc->add_text(", ");
_add_type(p_method.arguments[j].type, p_method.arguments[j].enumeration);
class_desc->add_text(" ");
_add_text(p_method.arguments[j].name);
if (p_method.arguments[j].default_value != "") {
class_desc->push_color(symbol_color);
class_desc->add_text("=");
class_desc->pop();
_add_text(p_method.arguments[j].default_value);
}
class_desc->pop();
}
if (is_vararg) {
class_desc->push_color(text_color);
if (p_method.arguments.size())
class_desc->add_text(", ");
class_desc->push_color(symbol_color);
class_desc->add_text("...");
class_desc->pop();
class_desc->pop();
}
class_desc->push_color(symbol_color);
class_desc->add_text(p_method.arguments.size() || is_vararg ? " )" : ")");
class_desc->pop();
if (p_method.qualifiers != "") {
class_desc->push_color(qualifier_color);
class_desc->add_text(" ");
_add_text(p_method.qualifiers);
class_desc->pop();
}
if (p_overview)
class_desc->pop(); //cell
}
Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
//ERR_FAIL_COND(!doc->class_list.has(p_class));
@ -679,15 +772,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
edited_class = p_class;
//edited_class->show();
// Colors
const Color title_color = get_color("accent_color", "Editor");
const Color text_color = get_color("default_color", "RichTextLabel");
const Color headline_color = get_color("headline_color", "EditorHelp");
const Color base_type_color = title_color.linear_interpolate(text_color, 0.5);
const Color comment_color = Color(text_color.r, text_color.g, text_color.b, 0.6);
const Color symbol_color = comment_color;
const Color value_color = Color(text_color.r, text_color.g, text_color.b, 0.4);
const Color qualifier_color = Color(text_color.r, text_color.g, text_color.b, 0.8);
_init_colors();
DocData::ClassDoc cd = doc->class_list[p_class]; //make a copy, so we can sort without worrying
@ -892,78 +977,51 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
class_desc->push_table(2);
class_desc->set_table_column_expand(1, 1);
for (int i = 0; i < methods.size(); i++) {
bool any_previous = false;
for (int pass = 0; pass < 2; pass++) {
Vector<DocData::MethodDoc> m;
bool is_vararg = methods[i].qualifiers.find("vararg") != -1;
method_line[methods[i].name] = class_desc->get_line_count() - 2; //gets overridden if description
class_desc->push_cell();
class_desc->push_align(RichTextLabel::ALIGN_RIGHT);
class_desc->push_font(doc_code_font);
_add_type(methods[i].return_type, methods[i].return_enum);
//class_desc->add_text(" ");
class_desc->pop(); //align
class_desc->pop(); //font
class_desc->pop(); //cell
class_desc->push_cell();
class_desc->push_font(doc_code_font);
if (methods[i].description != "") {
method_descr = true;
class_desc->push_meta("@method" + methods[i].name);
for (int i = 0; i < methods.size(); i++) {
const String &q = methods[i].qualifiers;
if ((pass == 0 && q.find("virtual") != -1) || (pass == 1 && q.find("virtual") == -1)) {
m.push_back(methods[i]);
}
}
class_desc->push_color(headline_color);
_add_text(methods[i].name);
class_desc->pop();
if (methods[i].description != "")
class_desc->pop(); // pop meta
class_desc->push_color(symbol_color);
class_desc->add_text(methods[i].arguments.size() || is_vararg ? "( " : "(");
class_desc->pop();
for (int j = 0; j < methods[i].arguments.size(); j++) {
class_desc->push_color(text_color);
if (j > 0)
class_desc->add_text(", ");
_add_type(methods[i].arguments[j].type, methods[i].arguments[j].enumeration);
class_desc->add_text(" ");
_add_text(methods[i].arguments[j].name);
if (methods[i].arguments[j].default_value != "") {
class_desc->push_color(symbol_color);
class_desc->add_text("=");
class_desc->pop();
_add_text(methods[i].arguments[j].default_value);
if (any_previous && !m.empty()) {
class_desc->push_cell();
class_desc->pop(); //cell
class_desc->push_cell();
class_desc->pop(); //cell
any_previous = false;
}
String group_prefix;
for (int i = 0; i < m.size(); i++) {
const String new_prefix = m[i].name.substr(0, 3);
bool is_new_group = false;
if (i < m.size() - 1 && new_prefix == m[i + 1].name.substr(0, 3) && new_prefix != group_prefix) {
is_new_group = i > 0;
group_prefix = new_prefix;
} else if (group_prefix != "" && new_prefix != group_prefix) {
is_new_group = true;
group_prefix = "";
}
class_desc->pop();
if (is_new_group && pass == 1) {
class_desc->push_cell();
class_desc->pop(); //cell
class_desc->push_cell();
class_desc->pop(); //cell
}
_add_method(m[i], true);
}
if (is_vararg) {
class_desc->push_color(text_color);
if (methods[i].arguments.size())
class_desc->add_text(", ");
class_desc->push_color(symbol_color);
class_desc->add_text("...");
class_desc->pop();
class_desc->pop();
}
class_desc->push_color(symbol_color);
class_desc->add_text(methods[i].arguments.size() || is_vararg ? " )" : ")");
class_desc->pop();
if (methods[i].qualifiers != "") {
class_desc->push_color(qualifier_color);
class_desc->add_text(" ");
_add_text(methods[i].qualifiers);
class_desc->pop();
}
class_desc->pop(); //monofont
//class_desc->add_newline();
class_desc->pop(); //cell
any_previous = !m.empty();
}
class_desc->pop(); //table
class_desc->pop();
class_desc->add_newline();
@ -1366,60 +1424,7 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
for (int i = 0; i < methods.size(); i++) {
bool is_vararg = methods[i].qualifiers.find("vararg") != -1;
method_line[methods[i].name] = class_desc->get_line_count() - 2;
class_desc->push_font(doc_code_font);
_add_type(methods[i].return_type, methods[i].return_enum);
class_desc->add_text(" ");
class_desc->push_color(headline_color);
_add_text(methods[i].name);
class_desc->pop();
class_desc->push_color(symbol_color);
class_desc->add_text(methods[i].arguments.size() || is_vararg ? "( " : "(");
class_desc->pop();
for (int j = 0; j < methods[i].arguments.size(); j++) {
class_desc->push_color(text_color);
if (j > 0)
class_desc->add_text(", ");
_add_type(methods[i].arguments[j].type, methods[i].arguments[j].enumeration);
class_desc->add_text(" ");
_add_text(methods[i].arguments[j].name);
if (methods[i].arguments[j].default_value != "") {
class_desc->push_color(symbol_color);
class_desc->add_text("=");
class_desc->pop();
_add_text(methods[i].arguments[j].default_value);
}
class_desc->pop();
}
if (is_vararg) {
class_desc->push_color(text_color);
if (methods[i].arguments.size())
class_desc->add_text(", ");
class_desc->push_color(symbol_color);
class_desc->add_text("...");
class_desc->pop();
class_desc->pop();
}
class_desc->push_color(symbol_color);
class_desc->add_text(methods[i].arguments.size() || is_vararg ? " )" : ")");
class_desc->pop();
if (methods[i].qualifiers != "") {
class_desc->push_color(qualifier_color);
class_desc->add_text(" ");
_add_text(methods[i].qualifiers);
class_desc->pop();
}
class_desc->pop();
_add_method(methods[i], false);
class_desc->add_newline();
class_desc->push_color(text_color);

View file

@ -139,6 +139,17 @@ class EditorHelp : public VBoxContainer {
String base_path;
Color title_color;
Color text_color;
Color headline_color;
Color base_type_color;
Color type_color;
Color comment_color;
Color symbol_color;
Color value_color;
Color qualifier_color;
void _init_colors();
void _help_callback(const String &p_topic);
void _add_text(const String &p_bbcode);
@ -146,6 +157,7 @@ class EditorHelp : public VBoxContainer {
//void _button_pressed(int p_idx);
void _add_type(const String &p_type, const String &p_enum = String());
void _add_method(const DocData::MethodDoc &p_method, bool p_overview = true);
void _class_list_select(const String &p_select);
void _class_desc_select(const String &p_select);