Add color in built-in documentation for overridden properties

This commit is contained in:
Micky 2024-01-16 16:54:45 +01:00
parent 4e990cd7e5
commit fbc584d4f2
3 changed files with 45 additions and 11 deletions

View File

@ -146,6 +146,7 @@ void EditorHelp::_update_theme_item_cache() {
theme_cache.value_color = get_theme_color(SNAME("value_color"), SNAME("EditorHelp")); theme_cache.value_color = get_theme_color(SNAME("value_color"), SNAME("EditorHelp"));
theme_cache.qualifier_color = get_theme_color(SNAME("qualifier_color"), SNAME("EditorHelp")); theme_cache.qualifier_color = get_theme_color(SNAME("qualifier_color"), SNAME("EditorHelp"));
theme_cache.type_color = get_theme_color(SNAME("type_color"), SNAME("EditorHelp")); theme_cache.type_color = get_theme_color(SNAME("type_color"), SNAME("EditorHelp"));
theme_cache.override_color = get_theme_color(SNAME("override_color"), SNAME("EditorHelp"));
theme_cache.doc_font = get_theme_font(SNAME("doc"), EditorStringName(EditorFonts)); theme_cache.doc_font = get_theme_font(SNAME("doc"), EditorStringName(EditorFonts));
theme_cache.doc_bold_font = get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts)); theme_cache.doc_bold_font = get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));
@ -995,11 +996,30 @@ void EditorHelp::_update_doc() {
class_desc->push_table(4); class_desc->push_table(4);
class_desc->set_table_column_expand(1, true); class_desc->set_table_column_expand(1, true);
cd.properties.sort_custom<PropertyCompare>();
bool is_generating_overridden_properties = true; // Set to false as soon as we encounter a non-overridden property.
bool overridden_property_exists = false;
for (int i = 0; i < cd.properties.size(); i++) { for (int i = 0; i < cd.properties.size(); i++) {
// Ignore undocumented private. // Ignore undocumented private.
if (cd.properties[i].name.begins_with("_") && cd.properties[i].description.strip_edges().is_empty()) { if (cd.properties[i].name.begins_with("_") && cd.properties[i].description.strip_edges().is_empty()) {
continue; continue;
} }
if (is_generating_overridden_properties && !cd.properties[i].overridden) {
is_generating_overridden_properties = false;
// No need for the extra spacing when there's no overridden property.
if (overridden_property_exists) {
class_desc->push_cell();
class_desc->pop();
class_desc->push_cell();
class_desc->pop();
class_desc->push_cell();
class_desc->pop();
class_desc->push_cell();
class_desc->pop();
}
}
property_line[cd.properties[i].name] = class_desc->get_paragraph_count() - 2; //gets overridden if description property_line[cd.properties[i].name] = class_desc->get_paragraph_count() - 2; //gets overridden if description
// Property type. // Property type.
@ -1054,17 +1074,17 @@ void EditorHelp::_update_doc() {
_push_code_font(); _push_code_font();
if (!cd.properties[i].default_value.is_empty()) { if (!cd.properties[i].default_value.is_empty()) {
class_desc->push_color(theme_cache.symbol_color);
if (cd.properties[i].overridden) { if (cd.properties[i].overridden) {
class_desc->push_color(theme_cache.override_color);
class_desc->add_text(" ["); class_desc->add_text(" [");
class_desc->push_meta("@member " + cd.properties[i].overrides + "." + cd.properties[i].name); class_desc->push_meta("@member " + cd.properties[i].overrides + "." + cd.properties[i].name);
_add_text(vformat(TTR("overrides %s:"), cd.properties[i].overrides)); _add_text(vformat(TTR("overrides %s:"), cd.properties[i].overrides));
class_desc->pop(); class_desc->pop();
class_desc->add_text(" "); class_desc->add_text(" " + _fix_constant(cd.properties[i].default_value) + "]");
overridden_property_exists = true;
} else { } else {
class_desc->push_color(theme_cache.symbol_color);
class_desc->add_text(" [" + TTR("default:") + " "); class_desc->add_text(" [" + TTR("default:") + " ");
}
class_desc->pop();
class_desc->push_color(theme_cache.value_color); class_desc->push_color(theme_cache.value_color);
class_desc->add_text(_fix_constant(cd.properties[i].default_value)); class_desc->add_text(_fix_constant(cd.properties[i].default_value));
@ -1074,6 +1094,8 @@ void EditorHelp::_update_doc() {
class_desc->add_text("]"); class_desc->add_text("]");
class_desc->pop(); class_desc->pop();
} }
class_desc->pop(); // color
}
if (cd.properties[i].is_deprecated) { if (cd.properties[i].is_deprecated) {
DEPRECATED_DOC_TAG; DEPRECATED_DOC_TAG;

View File

@ -134,6 +134,7 @@ class EditorHelp : public VBoxContainer {
Color value_color; Color value_color;
Color qualifier_color; Color qualifier_color;
Color type_color; Color type_color;
Color override_color;
Ref<Font> doc_font; Ref<Font> doc_font;
Ref<Font> doc_bold_font; Ref<Font> doc_bold_font;
@ -198,6 +199,16 @@ class EditorHelp : public VBoxContainer {
static void _gen_extensions_docs(); static void _gen_extensions_docs();
static void _compute_doc_version_hash(); static void _compute_doc_version_hash();
struct PropertyCompare {
_FORCE_INLINE_ bool operator()(const DocData::PropertyDoc &p_l, const DocData::PropertyDoc &p_r) const {
// Sort overridden properties above all else.
if (p_l.overridden == p_r.overridden) {
return p_l.name.naturalcasecmp_to(p_r.name) < 0;
}
return p_l.overridden;
}
};
protected: protected:
virtual void _update_theme_item_cache() override; virtual void _update_theme_item_cache() override;

View File

@ -2006,6 +2006,7 @@ void EditorThemeManager::_populate_editor_styles(const Ref<EditorTheme> &p_theme
p_theme->set_color("value_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6)); p_theme->set_color("value_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.6));
p_theme->set_color("qualifier_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.8)); p_theme->set_color("qualifier_color", "EditorHelp", p_config.font_color * Color(1, 1, 1, 0.8));
p_theme->set_color("type_color", "EditorHelp", p_config.accent_color.lerp(p_config.font_color, 0.5)); p_theme->set_color("type_color", "EditorHelp", p_config.accent_color.lerp(p_config.font_color, 0.5));
p_theme->set_color("override_color", "EditorHelp", p_config.warning_color);
p_theme->set_color("selection_color", "EditorHelp", p_config.selection_color); p_theme->set_color("selection_color", "EditorHelp", p_config.selection_color);
p_theme->set_color("link_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.8)); p_theme->set_color("link_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.8));
p_theme->set_color("code_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.6)); p_theme->set_color("code_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.6));