Skip to content

Commit b983b9d

Browse files
committed
[RTL] Add cell option to control if cell is shrinked to its contents width.
1 parent d19147e commit b983b9d

File tree

6 files changed

+41
-11
lines changed

6 files changed

+41
-11
lines changed

core/extension/gdextension_special_compat_hashes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ void GDExtensionSpecialCompatHashes::initialize() {
776776
{ "push_paragraph", 3218895358, 3089306873 },
777777
{ "push_list", 4036303897, 3017143144 },
778778
{ "push_table", 1125058220, 2623499273 },
779-
{ "set_table_column_expand", 4132157579, 2185176273 },
779+
{ "set_table_column_expand", 4258957458, 2185176273 },
780780
#ifdef REAL_T_IS_DOUBLE
781781
{ "add_image", 3346058748, 1507062345 },
782782
{ "push_dropcap", 981432822, 763534173 },

doc/classes/RichTextLabel.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@
597597
<param index="0" name="column" type="int" />
598598
<param index="1" name="expand" type="bool" />
599599
<param index="2" name="ratio" type="int" default="1" />
600+
<param index="3" name="shrink" type="bool" default="true" />
600601
<description>
601602
Edits the selected column's expansion options. If [param expand] is [code]true[/code], the column expands in proportion to its expansion ratio versus the other columns' ratios.
602603
For example, 2 columns with ratios 3 and 4 plus 70 pixels in available width would expand 30 and 40 pixels, respectively.

misc/extension_api_validation/4.3-stable.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,10 @@ Validate extension JSON: JSON file: Field was added in a way that breaks compati
278278
Validate extension JSON: JSON file: Field was added in a way that breaks compatibility 'classes/GPUParticles3D/methods/restart': arguments
279279

280280
Added an optional keep_seed parameter to restart particles, to avoid modifying the seed to do particle seeking.
281+
282+
283+
GH-101482
284+
---------
285+
Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/set_table_column_expand/arguments': size changed value in new API, from 3 to 4.
286+
287+
Added optional "shrink" argument. Compatibility method registered.

scene/gui/rich_text_label.compat.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@
3030

3131
#ifndef DISABLE_DEPRECATED
3232

33+
void RichTextLabel::_push_font_bind_compat_79053(const Ref<Font> &p_font, int p_size) {
34+
push_font(p_font, p_size);
35+
}
36+
37+
void RichTextLabel::_set_table_column_expand_bind_compat_79053(int p_column, bool p_expand, int p_ratio) {
38+
set_table_column_expand(p_column, p_expand, p_ratio, true);
39+
}
40+
41+
void RichTextLabel::_set_table_column_expand_bind_compat_101482(int p_column, bool p_expand, int p_ratio) {
42+
set_table_column_expand(p_column, p_expand, p_ratio, true);
43+
}
44+
3345
void RichTextLabel::_push_meta_bind_compat_99481(const Variant &p_meta, MetaUnderline p_underline_mode) {
3446
push_meta(p_meta, p_underline_mode, String());
3547
}
@@ -47,6 +59,9 @@ bool RichTextLabel::_remove_paragraph_bind_compat_91098(int p_paragraph) {
4759
}
4860

4961
void RichTextLabel::_bind_compatibility_methods() {
62+
ClassDB::bind_compatibility_method(D_METHOD("push_font", "font", "font_size"), &RichTextLabel::_push_font_bind_compat_79053);
63+
ClassDB::bind_compatibility_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::_set_table_column_expand_bind_compat_79053);
64+
ClassDB::bind_compatibility_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::_set_table_column_expand_bind_compat_101482, DEFVAL(1));
5065
ClassDB::bind_compatibility_method(D_METHOD("push_meta", "data", "underline_mode"), &RichTextLabel::_push_meta_bind_compat_99481, DEFVAL(META_UNDERLINE_ALWAYS));
5166
ClassDB::bind_compatibility_method(D_METHOD("push_meta", "data"), &RichTextLabel::_push_meta_bind_compat_89024);
5267
ClassDB::bind_compatibility_method(D_METHOD("add_image", "image", "width", "height", "color", "inline_align", "region"), &RichTextLabel::_add_image_bind_compat_80410, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(Rect2()));

scene/gui/rich_text_label.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ void RichTextLabel::_set_table_size(ItemTable *p_table, int p_available_width) {
693693
table_need_fit = false;
694694
// Fit slim.
695695
for (int i = 0; i < col_count; i++) {
696-
if (!p_table->columns[i].expand) {
696+
if (!p_table->columns[i].expand || !p_table->columns[i].shrink) {
697697
continue;
698698
}
699699
int dif = p_table->columns[i].width - p_table->columns[i].max_width;
@@ -3900,6 +3900,7 @@ void RichTextLabel::push_table(int p_columns, InlineAlignment p_alignment, int p
39003900
item->align_to_row = p_align_to_row;
39013901
for (int i = 0; i < (int)item->columns.size(); i++) {
39023902
item->columns[i].expand = false;
3903+
item->columns[i].shrink = true;
39033904
item->columns[i].expand_ratio = 1;
39043905
}
39053906
_add_item(item, true, false);
@@ -4038,7 +4039,7 @@ void RichTextLabel::push_context() {
40384039
_add_item(item, true);
40394040
}
40404041

4041-
void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio) {
4042+
void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio, bool p_shrink) {
40424043
_stop_thread();
40434044
MutexLock data_lock(data_mutex);
40444045

@@ -4047,6 +4048,7 @@ void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_r
40474048
ItemTable *table = static_cast<ItemTable *>(current);
40484049
ERR_FAIL_INDEX(p_column, (int)table->columns.size());
40494050
table->columns[p_column].expand = p_expand;
4051+
table->columns[p_column].shrink = p_shrink;
40504052
table->columns[p_column].expand_ratio = p_ratio;
40514053
}
40524054

@@ -4582,13 +4584,19 @@ void RichTextLabel::append_text(const String &p_bbcode) {
45824584
pos = brk_end + 1;
45834585
tag_stack.push_front("cell");
45844586
} else if (tag.begins_with("cell ")) {
4587+
bool shrink = true;
4588+
OptionMap::Iterator shrink_option = bbcode_options.find("shrink");
4589+
if (shrink_option) {
4590+
shrink = (shrink_option->value == "true");
4591+
}
4592+
45854593
OptionMap::Iterator expand_option = bbcode_options.find("expand");
45864594
if (expand_option) {
45874595
int ratio = expand_option->value.to_int();
45884596
if (ratio < 1) {
45894597
ratio = 1;
45904598
}
4591-
set_table_column_expand(get_current_table_column(), true, ratio);
4599+
set_table_column_expand(get_current_table_column(), true, ratio, shrink);
45924600
}
45934601

45944602
push_cell();
@@ -6429,7 +6437,7 @@ void RichTextLabel::_bind_methods() {
64296437
ClassDB::bind_method(D_METHOD("push_strikethrough"), &RichTextLabel::push_strikethrough);
64306438
ClassDB::bind_method(D_METHOD("push_table", "columns", "inline_align", "align_to_row"), &RichTextLabel::push_table, DEFVAL(INLINE_ALIGNMENT_TOP), DEFVAL(-1));
64316439
ClassDB::bind_method(D_METHOD("push_dropcap", "string", "font", "size", "dropcap_margins", "color", "outline_size", "outline_color"), &RichTextLabel::push_dropcap, DEFVAL(Rect2()), DEFVAL(Color(1, 1, 1)), DEFVAL(0), DEFVAL(Color(0, 0, 0, 0)));
6432-
ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand, DEFVAL(1));
6440+
ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio", "shrink"), &RichTextLabel::set_table_column_expand, DEFVAL(1), DEFVAL(true));
64336441
ClassDB::bind_method(D_METHOD("set_cell_row_background_color", "odd_row_bg", "even_row_bg"), &RichTextLabel::set_cell_row_background_color);
64346442
ClassDB::bind_method(D_METHOD("set_cell_border_color", "color"), &RichTextLabel::set_cell_border_color);
64356443
ClassDB::bind_method(D_METHOD("set_cell_size_override", "min_size", "max_size"), &RichTextLabel::set_cell_size_override);
@@ -6568,11 +6576,6 @@ void RichTextLabel::_bind_methods() {
65686576
ClassDB::bind_method(D_METHOD("is_menu_visible"), &RichTextLabel::is_menu_visible);
65696577
ClassDB::bind_method(D_METHOD("menu_option", "option"), &RichTextLabel::menu_option);
65706578

6571-
#ifndef DISABLE_DEPRECATED
6572-
ClassDB::bind_compatibility_method(D_METHOD("push_font", "font", "font_size"), &RichTextLabel::push_font);
6573-
ClassDB::bind_compatibility_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand);
6574-
#endif // DISABLE_DEPRECATED
6575-
65766579
// Note: set "bbcode_enabled" first, to avoid unnecessary "text" resets.
65776580
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode");
65786581
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text");

scene/gui/rich_text_label.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,13 @@ class RichTextLabel : public Control {
132132
static void _bind_methods();
133133

134134
#ifndef DISABLE_DEPRECATED
135+
void _push_font_bind_compat_79053(const Ref<Font> &p_font, int p_size);
136+
void _set_table_column_expand_bind_compat_79053(int p_column, bool p_expand, int p_ratio);
135137
void _push_meta_bind_compat_99481(const Variant &p_meta, MetaUnderline p_underline_mode);
136138
void _push_meta_bind_compat_89024(const Variant &p_meta);
137139
void _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);
138140
bool _remove_paragraph_bind_compat_91098(int p_paragraph);
141+
void _set_table_column_expand_bind_compat_101482(int p_column, bool p_expand, int p_ratio);
139142
static void _bind_compatibility_methods();
140143
#endif
141144

@@ -339,6 +342,7 @@ class RichTextLabel : public Control {
339342
struct ItemTable : public Item {
340343
struct Column {
341344
bool expand = false;
345+
bool shrink = true;
342346
int expand_ratio = 0;
343347
int min_width = 0;
344348
int max_width = 0;
@@ -724,7 +728,7 @@ class RichTextLabel : public Control {
724728
void push_fgcolor(const Color &p_color);
725729
void push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment);
726730
void push_context();
727-
void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1);
731+
void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1, bool p_shrink = true);
728732
void set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg);
729733
void set_cell_border_color(const Color &p_color);
730734
void set_cell_size_override(const Size2 &p_min_size, const Size2 &p_max_size);

0 commit comments

Comments
 (0)