Skip to content

Commit

Permalink
Fix Label3D, TextMesh & Font not following project default theme in e…
Browse files Browse the repository at this point in the history
…ditor
  • Loading branch information
Mickeon committed Mar 9, 2024
1 parent f289648 commit ba86704
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
11 changes: 9 additions & 2 deletions scene/3d/label_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@ Ref<Font> Label3D::get_font() const {
}

Ref<Font> Label3D::_get_font_or_default() const {
// Similar code taken from `FontVariation::_get_base_font_or_default`.

if (theme_font.is_valid()) {
theme_font->disconnect_changed(callable_mp(const_cast<Label3D *>(this), &Label3D::_font_changed));
theme_font.unref();
Expand All @@ -791,12 +793,17 @@ Ref<Font> Label3D::_get_font_or_default() const {
return font_override;
}

StringName theme_name = "font";
const StringName theme_name = "font";
List<StringName> theme_types;
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);

ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
for (const Ref<Theme> &theme : global_context->get_themes()) {
List<Ref<Theme>> themes = global_context->get_themes();
if (Engine::get_singleton()->is_editor_hint()) {
themes.push_front(ThemeDB::get_singleton()->get_project_theme());
}

for (const Ref<Theme> &theme : themes) {
if (theme.is_null()) {
continue;
}
Expand Down
9 changes: 8 additions & 1 deletion scene/resources/3d/primitive_meshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,8 @@ Ref<Font> TextMesh::get_font() const {
}

Ref<Font> TextMesh::_get_font_or_default() const {
// Similar code taken from `FontVariation::_get_base_font_or_default`.

if (font_override.is_valid()) {
return font_override;
}
Expand All @@ -3472,7 +3474,12 @@ Ref<Font> TextMesh::_get_font_or_default() const {
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);

ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
for (const Ref<Theme> &theme : global_context->get_themes()) {
List<Ref<Theme>> themes = global_context->get_themes();
if (Engine::get_singleton()->is_editor_hint()) {
themes.push_front(ThemeDB::get_singleton()->get_project_theme());
}

for (const Ref<Theme> &theme : themes) {
if (theme.is_null()) {
continue;
}
Expand Down
7 changes: 6 additions & 1 deletion scene/resources/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2861,7 +2861,12 @@ Ref<Font> FontVariation::_get_base_font_or_default() const {
ThemeDB::get_singleton()->get_native_type_dependencies(get_class_name(), &theme_types);

ThemeContext *global_context = ThemeDB::get_singleton()->get_default_theme_context();
for (const Ref<Theme> &theme : global_context->get_themes()) {
List<Ref<Theme>> themes = global_context->get_themes();
if (Engine::get_singleton()->is_editor_hint()) {
themes.push_front(ThemeDB::get_singleton()->get_project_theme());
}

for (const Ref<Theme> &theme : themes) {
if (theme.is_null()) {
continue;
}
Expand Down

0 comments on commit ba86704

Please sign in to comment.