Skip to content

Commit

Permalink
Add color in built-in documentation for overridden properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickeon committed Feb 11, 2024
1 parent 4e990cd commit fbc584d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
42 changes: 32 additions & 10 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void EditorHelp::_update_theme_item_cache() {
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.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_bold_font = get_theme_font(SNAME("doc_bold"), EditorStringName(EditorFonts));
Expand Down Expand Up @@ -995,11 +996,30 @@ void EditorHelp::_update_doc() {
class_desc->push_table(4);
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++) {
// Ignore undocumented private.
if (cd.properties[i].name.begins_with("_") && cd.properties[i].description.strip_edges().is_empty()) {
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 type.
Expand Down Expand Up @@ -1054,25 +1074,27 @@ void EditorHelp::_update_doc() {
_push_code_font();

if (!cd.properties[i].default_value.is_empty()) {
class_desc->push_color(theme_cache.symbol_color);
if (cd.properties[i].overridden) {
class_desc->push_color(theme_cache.override_color);
class_desc->add_text(" [");
class_desc->push_meta("@member " + cd.properties[i].overrides + "." + cd.properties[i].name);
_add_text(vformat(TTR("overrides %s:"), cd.properties[i].overrides));
class_desc->pop();
class_desc->add_text(" ");
class_desc->add_text(" " + _fix_constant(cd.properties[i].default_value) + "]");
overridden_property_exists = true;
} else {
class_desc->push_color(theme_cache.symbol_color);
class_desc->add_text(" [" + TTR("default:") + " ");
}
class_desc->pop();

class_desc->push_color(theme_cache.value_color);
class_desc->add_text(_fix_constant(cd.properties[i].default_value));
class_desc->pop();
class_desc->push_color(theme_cache.value_color);
class_desc->add_text(_fix_constant(cd.properties[i].default_value));
class_desc->pop();

class_desc->push_color(theme_cache.symbol_color);
class_desc->add_text("]");
class_desc->pop();
class_desc->push_color(theme_cache.symbol_color);
class_desc->add_text("]");
class_desc->pop();
}
class_desc->pop(); // color
}

if (cd.properties[i].is_deprecated) {
Expand Down
11 changes: 11 additions & 0 deletions editor/editor_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class EditorHelp : public VBoxContainer {
Color value_color;
Color qualifier_color;
Color type_color;
Color override_color;

Ref<Font> doc_font;
Ref<Font> doc_bold_font;
Expand Down Expand Up @@ -198,6 +199,16 @@ class EditorHelp : public VBoxContainer {
static void _gen_extensions_docs();
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:
virtual void _update_theme_item_cache() override;

Expand Down
1 change: 1 addition & 0 deletions editor/themes/editor_theme_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("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("override_color", "EditorHelp", p_config.warning_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("code_color", "EditorHelp", p_config.accent_color.lerp(p_config.mono_color, 0.6));
Expand Down

0 comments on commit fbc584d

Please sign in to comment.