Skip to content

Commit 56d5a26

Browse files
committed
Allow image dimensions in RichTextLabel to be relative to font size
Use base font size Added docs and compatibility methods Fix compatibility methods maybe for real this time???? Please? Make width/height use floats instead of ints, and then make 1em be the height of surrounding text Fix documentation for floats instead of ints Update compatibility # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected Add compatibility breakages file # Conflicts: # misc/extension_api_validation/4.5-stable_4.6-stable/GH-112617.txt # Conflicts: # scene/gui/rich_text_label.cpp
1 parent 923c751 commit 56d5a26

File tree

6 files changed

+135
-54
lines changed

6 files changed

+135
-54
lines changed

doc/classes/RichTextLabel.xml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,24 @@
3434
<method name="add_image">
3535
<return type="void" />
3636
<param index="0" name="image" type="Texture2D" />
37-
<param index="1" name="width" type="int" default="0" />
38-
<param index="2" name="height" type="int" default="0" />
37+
<param index="1" name="width" type="float" default="0" />
38+
<param index="2" name="height" type="float" default="0" />
3939
<param index="3" name="color" type="Color" default="Color(1, 1, 1, 1)" />
4040
<param index="4" name="inline_align" type="int" enum="InlineAlignment" default="5" />
4141
<param index="5" name="region" type="Rect2" default="Rect2(0, 0, 0, 0)" />
4242
<param index="6" name="key" type="Variant" default="null" />
4343
<param index="7" name="pad" type="bool" default="false" />
4444
<param index="8" name="tooltip" type="String" default="&quot;&quot;" />
45-
<param index="9" name="width_in_percent" type="bool" default="false" />
46-
<param index="10" name="height_in_percent" type="bool" default="false" />
45+
<param index="9" name="width_unit" type="int" enum="RichTextLabel.ImageUnit" default="0" />
46+
<param index="10" name="height_unit" type="int" enum="RichTextLabel.ImageUnit" default="0" />
4747
<param index="11" name="alt_text" type="String" default="&quot;&quot;" />
4848
<description>
4949
Adds an image's opening and closing tags to the tag stack, optionally providing a [param width] and [param height] to resize the image, a [param color] to tint the image and a [param region] to only use parts of the image.
5050
If [param width] or [param height] is set to 0, the image size will be adjusted in order to keep the original aspect ratio.
5151
If [param width] and [param height] are not set, but [param region] is, the region's rect will be used.
5252
[param key] is an optional identifier, that can be used to modify the image via [method update_image].
5353
If [param pad] is set, and the image is smaller than the size specified by [param width] and [param height], the image padding is added to match the size instead of upscaling.
54-
If [param width_in_percent] is set, [param width] values are percentages of the control width instead of pixels.
55-
If [param height_in_percent] is set, [param height] values are percentages of the control width instead of pixels.
54+
Parameters [param width_unit] and [param height_unit] determine the units used to calculate the image width and height, respectively.
5655
[param alt_text] is used as the image description for assistive apps.
5756
</description>
5857
</method>
@@ -698,15 +697,15 @@
698697
<param index="0" name="key" type="Variant" />
699698
<param index="1" name="mask" type="int" enum="RichTextLabel.ImageUpdateMask" is_bitfield="true" />
700699
<param index="2" name="image" type="Texture2D" />
701-
<param index="3" name="width" type="int" default="0" />
702-
<param index="4" name="height" type="int" default="0" />
700+
<param index="3" name="width" type="float" default="0" />
701+
<param index="4" name="height" type="float" default="0" />
703702
<param index="5" name="color" type="Color" default="Color(1, 1, 1, 1)" />
704703
<param index="6" name="inline_align" type="int" enum="InlineAlignment" default="5" />
705704
<param index="7" name="region" type="Rect2" default="Rect2(0, 0, 0, 0)" />
706705
<param index="8" name="pad" type="bool" default="false" />
707706
<param index="9" name="tooltip" type="String" default="&quot;&quot;" />
708-
<param index="10" name="width_in_percent" type="bool" default="false" />
709-
<param index="11" name="height_in_percent" type="bool" default="false" />
707+
<param index="10" name="width_unit" type="int" enum="RichTextLabel.ImageUnit" default="0" />
708+
<param index="11" name="height_unit" type="int" enum="RichTextLabel.ImageUnit" default="0" />
710709
<description>
711710
Updates the existing images with the key [param key]. Only properties specified by [param mask] bits are updated. See [method add_image].
712711
</description>
@@ -901,8 +900,17 @@
901900
<constant name="UPDATE_TOOLTIP" value="64" enum="ImageUpdateMask" is_bitfield="true">
902901
If this bit is set, [method update_image] changes image tooltip.
903902
</constant>
904-
<constant name="UPDATE_WIDTH_IN_PERCENT" value="128" enum="ImageUpdateMask" is_bitfield="true">
905-
If this bit is set, [method update_image] changes image width from/to percents.
903+
<constant name="UPDATE_WIDTH_UNIT" value="128" enum="ImageUpdateMask" is_bitfield="true">
904+
If this bit is set, [method update_image] changes the units used to calculate image size.
905+
</constant>
906+
<constant name="IMAGE_UNIT_PIXEL" value="0" enum="ImageUnit">
907+
Images drawn with this unit will be in pixels.
908+
</constant>
909+
<constant name="IMAGE_UNIT_PERCENT" value="1" enum="ImageUnit">
910+
Images drawn with this unit will be in percentages of the control width.
911+
</constant>
912+
<constant name="IMAGE_UNIT_EM" value="2" enum="ImageUnit">
913+
Images drawn with this unit will be in percentages of the surrounding font size.
906914
</constant>
907915
</constants>
908916
<theme_items>

editor/doc/editor_help.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2889,7 +2889,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt, const C
28892889
}
28902890

28912891
String image_path = bbcode.substr(brk_end + 1, end - brk_end - 1);
2892-
p_rt->add_image(ResourceLoader::load(image_path, "Texture2D"), width, height, Color(1, 1, 1), INLINE_ALIGNMENT_CENTER, Rect2(), Variant(), false, String(), size_in_percent);
2892+
p_rt->add_image(ResourceLoader::load(image_path, "Texture2D"), width, height, Color(1, 1, 1), INLINE_ALIGNMENT_CENTER, Rect2(), Variant(), false, String(), size_in_percent ? RichTextLabel::IMAGE_UNIT_PERCENT : RichTextLabel::IMAGE_UNIT_PIXEL);
28932893

28942894
pos = end;
28952895
tag_stack.push_front("img");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
GH-112617
2+
---------
3+
Validate extension JSON: API was removed: classes/RichTextLabel/enums/ImageUpdateMask/values/UPDATE_WIDTH_IN_PERCENT
4+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/10': default_value changed value in new API, from "false" to "0".
5+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/10': type changed value in new API, from "bool" to "enum::RichTextLabel.ImageUnit".
6+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/9': default_value changed value in new API, from "false" to "0".
7+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/9': type changed value in new API, from "bool" to "enum::RichTextLabel.ImageUnit".
8+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/10': default_value changed value in new API, from "false" to "0".
9+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/10': type changed value in new API, from "bool" to "enum::RichTextLabel.ImageUnit".
10+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/11': default_value changed value in new API, from "false" to "0".
11+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/11': type changed value in new API, from "bool" to "enum::RichTextLabel.ImageUnit".
12+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/1': meta changed value in new API, from "int32" to "float".
13+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/1': type changed value in new API, from "int" to "float".
14+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/2': meta changed value in new API, from "int32" to "float".
15+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/add_image/arguments/2': type changed value in new API, from "int" to "float".
16+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/3': meta changed value in new API, from "int32" to "float".
17+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/3': type changed value in new API, from "int" to "float".
18+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/4': meta changed value in new API, from "int32" to "float".
19+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/update_image/arguments/4': type changed value in new API, from "int" to "float".
20+
21+
Arguments changed from bools to enums for a few methods. Compatibility methods registered.

scene/gui/rich_text_label.compat.inc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ void RichTextLabel::_push_meta_bind_compat_89024(const Variant &p_meta) {
5151
}
5252

5353
void RichTextLabel::_add_image_bind_compat_80410(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color, InlineAlignment p_alignment, const Rect2 &p_region) {
54-
add_image(p_image, p_width, p_height, p_color, p_alignment, p_region, Variant(), false, String(), false, false, String());
54+
add_image(p_image, p_width, p_height, p_color, p_alignment, p_region, Variant(), false, String(), IMAGE_UNIT_PIXEL, IMAGE_UNIT_PIXEL, String());
5555
}
5656

5757
void RichTextLabel::_add_image_bind_compat_76829(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color, InlineAlignment p_alignment, const Rect2 &p_region, const Variant &p_key, bool p_pad, const String &p_tooltip, bool p_size_in_percent) {
58-
add_image(p_image, p_width, p_height, p_color, p_alignment, p_region, p_key, p_pad, p_tooltip, p_size_in_percent, p_size_in_percent, String());
58+
add_image(p_image, p_width, p_height, p_color, p_alignment, p_region, p_key, p_pad, p_tooltip, p_size_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, p_size_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, String());
5959
}
6060

6161
void RichTextLabel::_push_table_bind_compat_76829(int p_columns, InlineAlignment p_alignment, int p_align_to_row) {
@@ -75,11 +75,19 @@ void RichTextLabel::_push_strikethrough_bind_compat_106300() {
7575
}
7676

7777
void RichTextLabel::_add_image_bind_compat_107347(const Ref<Texture2D> &p_image, int p_width, int p_height, const Color &p_color, InlineAlignment p_alignment, const Rect2 &p_region, const Variant &p_key, bool p_pad, const String &p_tooltip, bool p_size_in_percent, const String &p_alt_text) {
78-
add_image(p_image, p_width, p_height, p_color, p_alignment, p_region, p_key, p_pad, p_tooltip, p_size_in_percent, p_size_in_percent, p_alt_text);
78+
add_image(p_image, p_width, p_height, p_color, p_alignment, p_region, p_key, p_pad, p_tooltip, p_size_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, p_size_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, p_alt_text);
7979
}
8080

8181
void RichTextLabel::_update_image_bind_compat_107347(const Variant &p_key, BitField<ImageUpdateMask> p_mask, const Ref<Texture2D> &p_image, int p_width, int p_height, const Color &p_color, InlineAlignment p_alignment, const Rect2 &p_region, bool p_pad, const String &p_tooltip, bool p_size_in_percent) {
82-
update_image(p_key, p_mask, p_image, p_width, p_height, p_color, p_alignment, p_region, p_pad, p_tooltip, p_size_in_percent, p_size_in_percent);
82+
update_image(p_key, p_mask, p_image, p_width, p_height, p_color, p_alignment, p_region, p_pad, p_tooltip, p_size_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, p_size_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL);
83+
}
84+
85+
void RichTextLabel::_add_image_bind_compat_112617(const Ref<Texture2D> &p_image, int p_width, int p_height, const Color &p_color, InlineAlignment p_alignment, const Rect2 &p_region, const Variant &p_key, bool p_pad, const String &p_tooltip, bool p_width_in_percent, bool p_height_in_percent, const String &p_alt_text) {
86+
add_image(p_image, p_width, p_height, p_color, p_alignment, p_region, p_key, p_pad, p_tooltip, p_width_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, p_height_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, p_alt_text);
87+
}
88+
89+
void RichTextLabel::_update_image_bind_compat_112617(const Variant &p_key, BitField<ImageUpdateMask> p_mask, const Ref<Texture2D> &p_image, int p_width, int p_height, const Color &p_color, InlineAlignment p_alignment, const Rect2 &p_region, bool p_pad, const String &p_tooltip, bool p_width_in_percent, bool p_height_in_percent) {
90+
update_image(p_key, p_mask, p_image, p_width, p_height, p_color, p_alignment, p_region, p_pad, p_tooltip, p_width_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL, p_height_in_percent ? IMAGE_UNIT_PERCENT : IMAGE_UNIT_PIXEL);
8391
}
8492

8593
void RichTextLabel::_bind_compatibility_methods() {
@@ -96,6 +104,9 @@ void RichTextLabel::_bind_compatibility_methods() {
96104
ClassDB::bind_compatibility_method(D_METHOD("push_strikethrough"), &RichTextLabel::_push_strikethrough_bind_compat_106300);
97105
ClassDB::bind_compatibility_method(D_METHOD("add_image", "image", "width", "height", "color", "inline_align", "region", "key", "pad", "tooltip", "size_in_percent", "alt_text"), &RichTextLabel::_add_image_bind_compat_107347, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(Rect2()), DEFVAL(Variant()), DEFVAL(false), DEFVAL(String()), DEFVAL(false), DEFVAL(String()));
98106
ClassDB::bind_compatibility_method(D_METHOD("update_image", "key", "mask", "image", "width", "height", "color", "inline_align", "region", "pad", "tooltip", "size_in_percent"), &RichTextLabel::_update_image_bind_compat_107347, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(Rect2()), DEFVAL(false), DEFVAL(String()), DEFVAL(false));
107+
108+
ClassDB::bind_compatibility_method(D_METHOD("add_image", "image", "width", "height", "color", "inline_align", "region", "key", "pad", "tooltip", "width_in_percent", "height_in_percent", "alt_text"), &RichTextLabel::_add_image_bind_compat_112617, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(Rect2()), DEFVAL(Variant()), DEFVAL(false), DEFVAL(String()), DEFVAL(false), DEFVAL(false), DEFVAL(String()));
109+
ClassDB::bind_compatibility_method(D_METHOD("update_image", "key", "mask", "image", "width", "height", "color", "inline_align", "region", "pad", "tooltip", "width_in_percent", "height_in_percent"), &RichTextLabel::_update_image_bind_compat_112617, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(Rect2()), DEFVAL(false), DEFVAL(String()), DEFVAL(false), DEFVAL(false));
99110
}
100111

101112
#endif // DISABLE_DEPRECATED

0 commit comments

Comments
 (0)