Optimize theme usage in editor log

This commit is contained in:
kobewi 2022-08-11 12:48:43 +02:00
parent e9e9e92e48
commit be0de927c7
2 changed files with 21 additions and 5 deletions

View file

@ -93,6 +93,12 @@ void EditorLog::_update_theme() {
collapse_button->set_icon(get_theme_icon(SNAME("CombineLines"), SNAME("EditorIcons")));
show_search_button->set_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons")));
theme_cache.error_color = get_theme_color(SNAME("error_color"), SNAME("Editor"));
theme_cache.error_icon = get_theme_icon(SNAME("Error"), SNAME("EditorIcons"));
theme_cache.warning_color = get_theme_color(SNAME("warning_color"), SNAME("Editor"));
theme_cache.warning_icon = get_theme_icon(SNAME("Warning"), SNAME("EditorIcons"));
theme_cache.message_color = get_theme_color(SNAME("font_color"), SNAME("Editor")) * Color(1, 1, 1, 0.6);
}
void EditorLog::_notification(int p_what) {
@ -264,22 +270,22 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) {
case MSG_TYPE_STD_RICH: {
} break;
case MSG_TYPE_ERROR: {
log->push_color(get_theme_color(SNAME("error_color"), SNAME("Editor")));
Ref<Texture2D> icon = get_theme_icon(SNAME("Error"), SNAME("EditorIcons"));
log->push_color(theme_cache.error_color);
Ref<Texture2D> icon = theme_cache.error_icon;
log->add_image(icon);
log->add_text(" ");
tool_button->set_icon(icon);
} break;
case MSG_TYPE_WARNING: {
log->push_color(get_theme_color(SNAME("warning_color"), SNAME("Editor")));
Ref<Texture2D> icon = get_theme_icon(SNAME("Warning"), SNAME("EditorIcons"));
log->push_color(theme_cache.warning_color);
Ref<Texture2D> icon = theme_cache.warning_icon;
log->add_image(icon);
log->add_text(" ");
tool_button->set_icon(icon);
} break;
case MSG_TYPE_EDITOR: {
// Distinguish editor messages from messages printed by the project
log->push_color(get_theme_color(SNAME("font_color"), SNAME("Editor")) * Color(1, 1, 1, 0.6));
log->push_color(theme_cache.message_color);
} break;
}

View file

@ -67,6 +67,16 @@ private:
}
};
struct {
Color error_color;
Ref<Texture2D> error_icon;
Color warning_color;
Ref<Texture2D> warning_icon;
Color message_color;
} theme_cache;
// Encapsulates all data and functionality regarding filters.
struct LogFilter {
private: