Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Make Theme report property list changes less often, and other backports #53397

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/classes/Control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@
See [method get_color] for details.
</description>
</method>
<method name="get_theme_default_font" qualifiers="const">
<return type="Font" />
<description>
Returns the default font from the first matching [Theme] in the tree if that [Theme] has a valid [member Theme.default_font] value.
See [method get_color] for details.
</description>
</method>
<method name="get_tooltip" qualifiers="const">
<return type="String" />
<argument index="0" name="at_position" type="Vector2" default="Vector2( 0, 0 )" />
Expand Down
9 changes: 8 additions & 1 deletion doc/classes/Theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@
Returns [code]false[/code] if the theme does not have [code]node_type[/code].
</description>
</method>
<method name="has_default_font" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if this theme has a valid [member default_font] value.
</description>
</method>
<method name="has_font" qualifiers="const">
<return type="bool" />
<argument index="0" name="name" type="String" />
Expand Down Expand Up @@ -403,7 +409,8 @@
</methods>
<members>
<member name="default_font" type="Font" setter="set_default_font" getter="get_default_font">
The theme's default font.
The default font of this [Theme] resource. Used as a fallback value for font items defined in this theme, but having invalid values. If this value is also invalid, the global default value is used.
Use [method has_default_font] to check if this value is valid.
</member>
</members>
<constants>
Expand Down
34 changes: 34 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,37 @@ bool Control::has_constant(const StringName &p_name, const StringName &p_theme_t
return Theme::get_default()->has_constant(p_name, type);
}

Ref<Font> Control::get_theme_default_font() const {
// First, look through each control or window node in the branch, until no valid parent can be found.
// Only nodes with a theme resource attached are considered.
// For each theme resource see if their assigned theme has the default value defined and valid.
Control *theme_owner = data.theme_owner;

while (theme_owner) {
if (theme_owner && theme_owner->data.theme->has_default_theme_font()) {
return theme_owner->data.theme->get_default_theme_font();
}

Node *parent = theme_owner->get_parent();
Control *parent_c = Object::cast_to<Control>(parent);
if (parent_c) {
theme_owner = parent_c->data.theme_owner;
} else {
theme_owner = nullptr;
}
}

// Secondly, check the project-defined Theme resource.
if (Theme::get_project_default().is_valid()) {
if (Theme::get_project_default()->has_default_theme_font()) {
return Theme::get_project_default()->get_default_theme_font();
}
}

// Lastly, fall back on the default Theme.
return Theme::get_default()->get_default_theme_font();
}

Rect2 Control::get_parent_anchorable_rect() const {
if (!is_inside_tree()) {
return Rect2();
Expand Down Expand Up @@ -2793,6 +2824,8 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_color", "name", "theme_type"), &Control::has_color, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_constant", "name", "theme_type"), &Control::has_constant, DEFVAL(""));

ClassDB::bind_method(D_METHOD("get_theme_default_font"), &Control::get_theme_default_font);

ClassDB::bind_method(D_METHOD("get_parent_control"), &Control::get_parent_control);

ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction);
Expand Down Expand Up @@ -2991,6 +3024,7 @@ void Control::_bind_methods() {

BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point")));
}

Control::Control() {
data.parent = nullptr;

Expand Down
2 changes: 2 additions & 0 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ class Control : public CanvasItem {
bool has_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
bool has_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const;

Ref<Font> get_theme_default_font() const;

/* TOOLTIP */

void set_tooltip(const String &p_tooltip);
Expand Down
Loading