Skip to content

Commit

Permalink
Merge pull request #64119 from YuriSizov/theme-init-database
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Aug 29, 2022
2 parents 0024ba8 + 6320a0f commit e60086f
Show file tree
Hide file tree
Showing 25 changed files with 589 additions and 311 deletions.
3 changes: 3 additions & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,9 @@
<member name="TextServerManager" type="TextServerManager" setter="" getter="">
The [TextServerManager] singleton.
</member>
<member name="ThemeDB" type="ThemeDB" setter="" getter="">
The [ThemeDB] singleton.
</member>
<member name="Time" type="Time" setter="" getter="">
The [Time] singleton.
</member>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<description>
Returns a [Color] from the first matching [Theme] in the tree if that [Theme] has a color item with the specified [param name] and [param theme_type]. If [param theme_type] is omitted the class name of the current control is used as the type, or [member theme_type_variation] if it is defined. If the type is a class name its parent classes are also checked, in order of inheritance. If the type is a variation its base types are checked, in order of dependency, then the control's class name and its parent classes are checked.
For the current control its local overrides are considered first (see [method add_theme_color_override]), then its assigned [member theme]. After the current control, each parent control and its assigned [member theme] are considered; controls without a [member theme] assigned are skipped. If no matching [Theme] is found in the tree, a custom project [Theme] (see [member ProjectSettings.gui/theme/custom]) and the default [Theme] are used.
For the current control its local overrides are considered first (see [method add_theme_color_override]), then its assigned [member theme]. After the current control, each parent control and its assigned [member theme] are considered; controls without a [member theme] assigned are skipped. If no matching [Theme] is found in the tree, the custom project [Theme] (see [member ProjectSettings.gui/theme/custom]) and the default [Theme] are used (see [ThemeDB]).
[codeblocks]
[gdscript]
func _ready():
Expand Down
16 changes: 8 additions & 8 deletions doc/classes/Theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
<description>
Returns the [Font] property defined by [param name] and [param theme_type], if it exists.
Returns the default theme font if the property doesn't exist and the default theme font is set up (see [member default_font]). Use [method has_font] to check for existence of the property and [method has_default_font] to check for existence of the default theme font.
Returns the engine fallback font value, if neither exist.
Returns the engine fallback font value, if neither exist (see [member ThemeDB.fallback_font]).
</description>
</method>
<method name="get_font_list" qualifiers="const">
Expand All @@ -167,7 +167,7 @@
<description>
Returns the font size property defined by [param name] and [param theme_type], if it exists.
Returns the default theme font size if the property doesn't exist and the default theme font size is set up (see [member default_font_size]). Use [method has_font_size] to check for existence of the property and [method has_default_font_size] to check for existence of the default theme font.
Returns the engine fallback font size value, if neither exist.
Returns the engine fallback font size value, if neither exist (see [member ThemeDB.fallback_font_size]).
</description>
</method>
<method name="get_font_size_list" qualifiers="const">
Expand Down Expand Up @@ -195,7 +195,7 @@
<param index="1" name="theme_type" type="StringName" />
<description>
Returns the icon property defined by [param name] and [param theme_type], if it exists.
Returns the engine fallback icon value if the property doesn't exist. Use [method has_icon] to check for existence.
Returns the engine fallback icon value if the property doesn't exist (see [member ThemeDB.fallback_icon]). Use [method has_icon] to check for existence.
</description>
</method>
<method name="get_icon_list" qualifiers="const">
Expand All @@ -217,7 +217,7 @@
<param index="1" name="theme_type" type="StringName" />
<description>
Returns the [StyleBox] property defined by [param name] and [param theme_type], if it exists.
Returns the engine fallback stylebox value if the property doesn't exist. Use [method has_stylebox] to check for existence.
Returns the engine fallback stylebox value if the property doesn't exist (see [member ThemeDB.fallback_stylebox]). Use [method has_stylebox] to check for existence.
</description>
</method>
<method name="get_stylebox_list" qualifiers="const">
Expand All @@ -240,7 +240,7 @@
<param index="2" name="theme_type" type="StringName" />
<description>
Returns the theme property of [param data_type] defined by [param name] and [param theme_type], if it exists.
Returns the engine fallback icon value if the property doesn't exist. Use [method has_theme_item] to check for existence.
Returns the engine fallback icon value if the property doesn't exist (see [ThemeDB]). Use [method has_theme_item] to check for existence.
[b]Note:[/b] This method is analogous to calling the corresponding data type specific method, but can be used for more generalized logic.
</description>
</method>
Expand Down Expand Up @@ -542,15 +542,15 @@
</methods>
<members>
<member name="default_base_scale" type="float" setter="set_default_base_scale" getter="get_default_base_scale" default="0.0">
The default base scale factor of this theme resource. Used by some controls to scale their visual properties based on the global scale factor. If this value is set to [code]0.0[/code], the global scale factor is used.
The default base scale factor of this theme resource. Used by some controls to scale their visual properties based on the global scale factor. If this value is set to [code]0.0[/code], the global scale factor is used (see [member ThemeDB.fallback_base_scale]).
Use [method has_default_base_scale] to check if this value is valid.
</member>
<member name="default_font" type="Font" setter="set_default_font" getter="get_default_font">
The default font of this theme resource. Used as the default value when trying to fetch a font resource that doesn't exist in this theme or is in invalid state. If the default font is also missing or invalid, the engine fallback value is used.
The default font of this theme resource. Used as the default value when trying to fetch a font resource that doesn't exist in this theme or is in invalid state. If the default font is also missing or invalid, the engine fallback value is used (see [member ThemeDB.fallback_font]).
Use [method has_default_font] to check if this value is valid.
</member>
<member name="default_font_size" type="int" setter="set_default_font_size" getter="get_default_font_size" default="-1">
The default font size of this theme resource. Used as the default value when trying to fetch a font size value that doesn't exist in this theme or is in invalid state. If the default font size is also missing or invalid, the engine fallback value is used.
The default font size of this theme resource. Used as the default value when trying to fetch a font size value that doesn't exist in this theme or is in invalid state. If the default font size is also missing or invalid, the engine fallback value is used (see [member ThemeDB.fallback_font_size]).
Values below [code]0[/code] are invalid and can be used to unset the property. Use [method has_default_font_size] to check if this value is valid.
</member>
</members>
Expand Down
54 changes: 54 additions & 0 deletions doc/classes/ThemeDB.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ThemeDB" inherits="Object" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
An engine singleton providing access to static [Theme] information, such as default and project theme, and fallback values.
</brief_description>
<description>
This engine singleton provides access to static information about [Theme] resources used by the engine and by your projects. You can fetch the default engine theme, as well as your project configured theme.
[ThemeDB] also contains fallback values for theme properties.
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_default_theme">
<return type="Theme" />
<description>
Returns a reference to the default engine [Theme]. This theme resource is responsible for the out-of-the-box look of [Control] nodes and cannot be overridden.
</description>
</method>
<method name="get_project_theme">
<return type="Theme" />
<description>
Returns a reference to the custom project [Theme]. This theme resources allows to override the default engine theme for every control node in the project.
To set the project theme, see [member ProjectSettings.gui/theme/custom].
</description>
</method>
</methods>
<members>
<member name="fallback_base_scale" type="float" setter="set_fallback_base_scale" getter="get_fallback_base_scale" default="1.0">
The fallback base scale factor of every [Control] node and [Theme] resource. Used when no other value is available to the control.
See also [member Theme.default_base_scale].
</member>
<member name="fallback_font" type="Font" setter="set_fallback_font" getter="get_fallback_font">
The fallback font of every [Control] node and [Theme] resource. Used when no other value is available to the control.
See also [member Theme.default_font].
</member>
<member name="fallback_font_size" type="int" setter="set_fallback_font_size" getter="get_fallback_font_size" default="16">
The fallback font size of every [Control] node and [Theme] resource. Used when no other value is available to the control.
See also [member Theme.default_font_size].
</member>
<member name="fallback_icon" type="Texture2D" setter="set_fallback_icon" getter="get_fallback_icon">
The fallback icon of every [Control] node and [Theme] resource. Used when no other value is available to the control.
</member>
<member name="fallback_stylebox" type="StyleBox" setter="set_fallback_stylebox" getter="get_fallback_stylebox">
The fallback stylebox of every [Control] node and [Theme] resource. Used when no other value is available to the control.
</member>
</members>
<signals>
<signal name="fallback_changed">
<description>
Emitted when one of the fallback values had been changed. Use it to refresh the look of controls that may rely on the fallback theme items.
</description>
</signal>
</signals>
</class>
17 changes: 9 additions & 8 deletions editor/doc_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "core/version.h"
#include "editor/editor_settings.h"
#include "scene/resources/theme.h"
#include "scene/theme/theme_db.h"

// Used for a hack preserving Mono properties on non-Mono builds.
#include "modules/modules_enabled.gen.h" // For mono.
Expand Down Expand Up @@ -567,29 +568,29 @@ void DocTools::generate(bool p_basic_types) {
{
List<StringName> l;

Theme::get_default()->get_color_list(cname, &l);
ThemeDB::get_singleton()->get_default_theme()->get_color_list(cname, &l);
for (const StringName &E : l) {
DocData::ThemeItemDoc tid;
tid.name = E;
tid.type = "Color";
tid.data_type = "color";
tid.default_value = Variant(Theme::get_default()->get_color(E, cname)).get_construct_string().replace("\n", " ");
tid.default_value = Variant(ThemeDB::get_singleton()->get_default_theme()->get_color(E, cname)).get_construct_string().replace("\n", " ");
c.theme_properties.push_back(tid);
}

l.clear();
Theme::get_default()->get_constant_list(cname, &l);
ThemeDB::get_singleton()->get_default_theme()->get_constant_list(cname, &l);
for (const StringName &E : l) {
DocData::ThemeItemDoc tid;
tid.name = E;
tid.type = "int";
tid.data_type = "constant";
tid.default_value = itos(Theme::get_default()->get_constant(E, cname));
tid.default_value = itos(ThemeDB::get_singleton()->get_default_theme()->get_constant(E, cname));
c.theme_properties.push_back(tid);
}

l.clear();
Theme::get_default()->get_font_list(cname, &l);
ThemeDB::get_singleton()->get_default_theme()->get_font_list(cname, &l);
for (const StringName &E : l) {
DocData::ThemeItemDoc tid;
tid.name = E;
Expand All @@ -599,7 +600,7 @@ void DocTools::generate(bool p_basic_types) {
}

l.clear();
Theme::get_default()->get_font_size_list(cname, &l);
ThemeDB::get_singleton()->get_default_theme()->get_font_size_list(cname, &l);
for (const StringName &E : l) {
DocData::ThemeItemDoc tid;
tid.name = E;
Expand All @@ -609,7 +610,7 @@ void DocTools::generate(bool p_basic_types) {
}

l.clear();
Theme::get_default()->get_icon_list(cname, &l);
ThemeDB::get_singleton()->get_default_theme()->get_icon_list(cname, &l);
for (const StringName &E : l) {
DocData::ThemeItemDoc tid;
tid.name = E;
Expand All @@ -619,7 +620,7 @@ void DocTools::generate(bool p_basic_types) {
}

l.clear();
Theme::get_default()->get_stylebox_list(cname, &l);
ThemeDB::get_singleton()->get_default_theme()->get_stylebox_list(cname, &l);
for (const StringName &E : l) {
DocData::ThemeItemDoc tid;
tid.name = E;
Expand Down
Loading

0 comments on commit e60086f

Please sign in to comment.