diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 167f1bc07c9..273cf9a5901 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -89,16 +89,14 @@ - Overrides the [Color] with given [code]name[/code] in the [member theme] resource the control uses. - [b]Note:[/b] Unlike other theme overrides, there is no way to undo a color override without manually assigning the previous color. + Creates a local override for a theme [Color] with the specified [code]name[/code]. Local overrides always take precedence when fetching theme items for the control. An override cannot be removed, but it can be overridden with the corresponding default value. + See also [method get_color]. [b]Example of overriding a label's color and resetting it later:[/b] [codeblock] - # Override the child node "MyLabel"'s font color to orange. + # Given the child Label node "MyLabel", override its font color with a custom value. $MyLabel.add_color_override("font_color", Color(1, 0.5, 0)) - - # Reset the color by creating a new node to get the default value: - var default_label_color = Label.new().get_color("font_color") - $MyLabel.add_color_override("font_color", default_label_color) + # Reset the font color of the child label. + $MyLabel.add_color_override("font_color", get_color("font_color", "Label")) [/codeblock] @@ -107,7 +105,8 @@ - Overrides an integer constant with given [code]name[/code] in the [member theme] resource the control uses. If the [code]constant[/code] is [code]0[/code], the override is cleared and the constant from assigned [Theme] is used. + Creates a local override for a theme constant with the specified [code]name[/code]. Local overrides always take precedence when fetching theme items for the control. An override cannot be removed, but it can be overridden with the corresponding default value. + See also [method get_constant]. @@ -115,7 +114,8 @@ - Overrides the font with given [code]name[/code] in the [member theme] resource the control uses. If [code]font[/code] is [code]null[/code] or invalid, the override is cleared and the font from assigned [Theme] is used. + Creates a local override for a theme [Font] with the specified [code]name[/code]. Local overrides always take precedence when fetching theme items for the control. An override can be removed by assigning it a [code]null[/code] value. + See also [method get_font]. @@ -123,7 +123,8 @@ - Overrides the icon with given [code]name[/code] in the [member theme] resource the control uses. If [code]icon[/code] is [code]null[/code] or invalid, the override is cleared and the icon from assigned [Theme] is used. + Creates a local override for a theme icon with the specified [code]name[/code]. Local overrides always take precedence when fetching theme items for the control. An override can be removed by assigning it a [code]null[/code] value. + See also [method get_icon]. @@ -131,7 +132,7 @@ - Overrides the [Shader] with given [code]name[/code] in the [member theme] resource the control uses. If [code]shader[/code] is [code]null[/code] or invalid, the override is cleared and the shader from assigned [Theme] is used. + Creates a local override for a theme shader with the specified [code]name[/code]. Local overrides always take precedence when fetching theme items for the control. An override can be removed by assigning it a [code]null[/code] value. @@ -139,7 +140,8 @@ - Overrides the [StyleBox] with given [code]name[/code] in the [member theme] resource the control uses. If [code]stylebox[/code] is empty or invalid, the override is cleared and the [StyleBox] from assigned [Theme] is used. + Creates a local override for a theme [StyleBox] with the specified [code]name[/code]. Local overrides always take precedence when fetching theme items for the control. An override can be removed by assigning it a [code]null[/code] value. + See also [method get_stylebox]. [b]Example of modifying a property in a StyleBox by duplicating it:[/b] [codeblock] # The snippet below assumes the child node MyButton has a StyleBoxFlat assigned. @@ -149,8 +151,7 @@ new_stylebox_normal.border_width_top = 3 new_stylebox_normal.border_color = Color(0, 1, 0.5) $MyButton.add_stylebox_override("normal", new_stylebox_normal) - - # Remove the stylebox override: + # Remove the stylebox override. $MyButton.add_stylebox_override("normal", null) [/codeblock] @@ -222,12 +223,16 @@ - + - Returns a color from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. + Returns a [Color] from the first matching [Theme] in the tree if that [Theme] has a color item with the specified [code]name[/code] and [code]theme_type[/code]. If [code]theme_type[/code] is omitted the class name of the current control is used as the type. If the type is a class name its parent classes are also checked, in order of inheritance. + For the current control its local overrides are considered first (see [method add_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. [codeblock] func _ready(): - modulate = get_color("font_color", "Button") #get the color defined for button fonts + # Get the font color defined for the current Control's class, if it exists. + modulate = get_color("font_color") + # Get the font color defined for the Button class. + modulate = get_color("font_color", "Button") [/codeblock] @@ -240,9 +245,10 @@ - + - Returns a constant from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. + Returns a constant from the first matching [Theme] in the tree if that [Theme] has a constant item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. @@ -288,9 +294,10 @@ - + - Returns a font from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. + Returns a [Font] from the first matching [Theme] in the tree if that [Theme] has a font item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. @@ -302,9 +309,10 @@ - + - Returns an icon from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. + Returns an icon from the first matching [Theme] in the tree if that [Theme] has an icon item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. @@ -347,9 +355,10 @@ - + - Returns a [StyleBox] from assigned [Theme] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code]. + Returns a [StyleBox] from the first matching [Theme] in the tree if that [Theme] has a stylebox item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. @@ -378,31 +387,35 @@ - + - Returns [code]true[/code] if [Color] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a color item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. - Returns [code]true[/code] if [Color] with given [code]name[/code] has a valid override in this [Control] node. + Returns [code]true[/code] if there is a local override for a theme [Color] with the specified [code]name[/code] in this [Control] node. + See [method add_color_override]. - + - Returns [code]true[/code] if constant with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a constant item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. - Returns [code]true[/code] if constant with given [code]name[/code] has a valid override in this [Control] node. + Returns [code]true[/code] if there is a local override for a theme constant with the specified [code]name[/code] in this [Control] node. + See [method add_constant_override]. @@ -414,31 +427,35 @@ - + - Returns [code]true[/code] if font with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a font item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. - Returns [code]true[/code] if font with given [code]name[/code] has a valid override in this [Control] node. + Returns [code]true[/code] if there is a local override for a theme [Font] with the specified [code]name[/code] in this [Control] node. + See [method add_font_override]. - + - Returns [code]true[/code] if icon with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has an icon item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. - Returns [code]true[/code] if icon with given [code]name[/code] has a valid override in this [Control] node. + Returns [code]true[/code] if there is a local override for a theme icon with the specified [code]name[/code] in this [Control] node. + See [method add_icon_override]. @@ -454,22 +471,25 @@ - Returns [code]true[/code] if [Shader] with given [code]name[/code] has a valid override in this [Control] node. + Returns [code]true[/code] if there is a local override for a theme shader with the specified [code]name[/code] in this [Control] node. + See [method add_shader_override]. - + - Returns [code]true[/code] if [StyleBox] with given [code]name[/code] and associated with [Control] of given [code]node_type[/code] exists in assigned [Theme]. + Returns [code]true[/code] if there is a matching [Theme] in the tree that has a stylebox item with the specified [code]name[/code] and [code]theme_type[/code]. + See [method get_color] for details. - Returns [code]true[/code] if [StyleBox] with given [code]name[/code] has a valid override in this [Control] node. + Returns [code]true[/code] if there is a local override for a theme [StyleBox] with the specified [code]name[/code] in this [Control] node. + See [method add_stylebox_override]. diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 6e44956246b..50bf20970be 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -785,15 +785,15 @@ Size2 Control::get_minimum_size() const { return Size2(); } -Ref Control::get_icon(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +Ref Control::get_icon(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { const Ref *tex = data.icon_override.getptr(p_name); if (tex) { return *tex; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -827,15 +827,15 @@ Ref Control::get_icon(const StringName &p_name, const StringName &p_nod return Theme::get_default()->get_icon(p_name, type); } -Ref Control::get_shader(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +Ref Control::get_shader(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { const Ref *sdr = data.shader_override.getptr(p_name); if (sdr) { return *sdr; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -869,15 +869,15 @@ Ref Control::get_shader(const StringName &p_name, const StringName &p_no return Theme::get_default()->get_shader(p_name, type); } -Ref Control::get_stylebox(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +Ref Control::get_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { const Ref *style = data.style_override.getptr(p_name); if (style) { return *style; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -917,15 +917,15 @@ Ref Control::get_stylebox(const StringName &p_name, const StringName & } return Theme::get_default()->get_stylebox(p_name, type); } -Ref Control::get_font(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +Ref Control::get_font(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { const Ref *font = data.font_override.getptr(p_name); if (font) { return *font; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -955,15 +955,15 @@ Ref Control::get_font(const StringName &p_name, const StringName &p_node_t return Theme::get_default()->get_font(p_name, type); } -Color Control::get_color(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +Color Control::get_color(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { const Color *color = data.color_override.getptr(p_name); if (color) { return *color; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -996,15 +996,15 @@ Color Control::get_color(const StringName &p_name, const StringName &p_node_type return Theme::get_default()->get_color(p_name, type); } -int Control::get_constant(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +int Control::get_constant(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { const int *constant = data.constant_override.getptr(p_name); if (constant) { return *constant; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -1067,14 +1067,14 @@ bool Control::has_constant_override(const StringName &p_name) const { return constant != nullptr; } -bool Control::has_icon(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +bool Control::has_icon(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { if (has_icon_override(p_name)) { return true; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -1106,14 +1106,14 @@ bool Control::has_icon(const StringName &p_name, const StringName &p_node_type) return Theme::get_default()->has_icon(p_name, type); } -bool Control::has_shader(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +bool Control::has_shader(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { if (has_shader_override(p_name)) { return true; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -1144,14 +1144,14 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_node_type } return Theme::get_default()->has_shader(p_name, type); } -bool Control::has_stylebox(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +bool Control::has_stylebox(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { if (has_stylebox_override(p_name)) { return true; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -1182,14 +1182,14 @@ bool Control::has_stylebox(const StringName &p_name, const StringName &p_node_ty } return Theme::get_default()->has_stylebox(p_name, type); } -bool Control::has_font(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +bool Control::has_font(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { if (has_font_override(p_name)) { return true; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -1221,14 +1221,14 @@ bool Control::has_font(const StringName &p_name, const StringName &p_node_type) return Theme::get_default()->has_font(p_name, type); } -bool Control::has_color(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +bool Control::has_color(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { if (has_color_override(p_name)) { return true; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -1260,14 +1260,14 @@ bool Control::has_color(const StringName &p_name, const StringName &p_node_type) return Theme::get_default()->has_color(p_name, type); } -bool Control::has_constant(const StringName &p_name, const StringName &p_node_type) const { - if (p_node_type == StringName() || p_node_type == get_class_name()) { +bool Control::has_constant(const StringName &p_name, const StringName &p_theme_type) const { + if (p_theme_type == StringName() || p_theme_type == get_class_name()) { if (has_constant_override(p_name)) { return true; } } - StringName type = p_node_type ? p_node_type : get_class_name(); + StringName type = p_theme_type ? p_theme_type : get_class_name(); // try with custom themes Control *theme_owner = data.theme_owner; @@ -2774,11 +2774,11 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("add_color_override", "name", "color"), &Control::add_color_override); ClassDB::bind_method(D_METHOD("add_constant_override", "name", "constant"), &Control::add_constant_override); - ClassDB::bind_method(D_METHOD("get_icon", "name", "node_type"), &Control::get_icon, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_stylebox", "name", "node_type"), &Control::get_stylebox, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_font", "name", "node_type"), &Control::get_font, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_color", "name", "node_type"), &Control::get_color, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_constant", "name", "node_type"), &Control::get_constant, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_icon", "name", "theme_type"), &Control::get_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_stylebox", "name", "theme_type"), &Control::get_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_font", "name", "theme_type"), &Control::get_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_color", "name", "theme_type"), &Control::get_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_constant", "name", "theme_type"), &Control::get_constant, DEFVAL("")); ClassDB::bind_method(D_METHOD("has_icon_override", "name"), &Control::has_icon_override); ClassDB::bind_method(D_METHOD("has_shader_override", "name"), &Control::has_shader_override); @@ -2787,11 +2787,11 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("has_color_override", "name"), &Control::has_color_override); ClassDB::bind_method(D_METHOD("has_constant_override", "name"), &Control::has_constant_override); - ClassDB::bind_method(D_METHOD("has_icon", "name", "node_type"), &Control::has_icon, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_stylebox", "name", "node_type"), &Control::has_stylebox, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_font", "name", "node_type"), &Control::has_font, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_color", "name", "node_type"), &Control::has_color, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_constant", "name", "node_type"), &Control::has_constant, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_icon", "name", "theme_type"), &Control::has_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_stylebox", "name", "theme_type"), &Control::has_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_font", "name", "theme_type"), &Control::has_font, DEFVAL("")); + 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_parent_control"), &Control::get_parent_control); diff --git a/scene/gui/control.h b/scene/gui/control.h index a60f2ee3e0e..745897e878c 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -425,12 +425,12 @@ public: void add_color_override(const StringName &p_name, const Color &p_color); void add_constant_override(const StringName &p_name, int p_constant); - Ref get_icon(const StringName &p_name, const StringName &p_node_type = StringName()) const; - Ref get_shader(const StringName &p_name, const StringName &p_node_type = StringName()) const; - Ref get_stylebox(const StringName &p_name, const StringName &p_node_type = StringName()) const; - Ref get_font(const StringName &p_name, const StringName &p_node_type = StringName()) const; - Color get_color(const StringName &p_name, const StringName &p_node_type = StringName()) const; - int get_constant(const StringName &p_name, const StringName &p_node_type = StringName()) const; + Ref get_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + Ref get_shader(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + Ref get_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + Ref get_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + Color get_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + int get_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const; bool has_icon_override(const StringName &p_name) const; bool has_shader_override(const StringName &p_name) const; @@ -439,12 +439,12 @@ public: bool has_color_override(const StringName &p_name) const; bool has_constant_override(const StringName &p_name) const; - bool has_icon(const StringName &p_name, const StringName &p_node_type = StringName()) const; - bool has_shader(const StringName &p_name, const StringName &p_node_type = StringName()) const; - bool has_stylebox(const StringName &p_name, const StringName &p_node_type = StringName()) const; - bool has_font(const StringName &p_name, const StringName &p_node_type = StringName()) const; - bool has_color(const StringName &p_name, const StringName &p_node_type = StringName()) const; - bool has_constant(const StringName &p_name, const StringName &p_node_type = StringName()) const; + bool has_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + bool has_shader(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + bool has_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + bool has_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const; + 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; /* TOOLTIP */