From b983b9d9f4371ac00f60abf850af58969f764059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:07:16 +0200 Subject: [PATCH] [RTL] Add cell option to control if cell is shrinked to its contents width. --- .../gdextension_special_compat_hashes.cpp | 2 +- doc/classes/RichTextLabel.xml | 1 + .../4.3-stable.expected | 7 +++++++ scene/gui/rich_text_label.compat.inc | 15 +++++++++++++ scene/gui/rich_text_label.cpp | 21 +++++++++++-------- scene/gui/rich_text_label.h | 6 +++++- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/core/extension/gdextension_special_compat_hashes.cpp b/core/extension/gdextension_special_compat_hashes.cpp index b7f8e4f2e63..154fdc654e0 100644 --- a/core/extension/gdextension_special_compat_hashes.cpp +++ b/core/extension/gdextension_special_compat_hashes.cpp @@ -776,7 +776,7 @@ void GDExtensionSpecialCompatHashes::initialize() { { "push_paragraph", 3218895358, 3089306873 }, { "push_list", 4036303897, 3017143144 }, { "push_table", 1125058220, 2623499273 }, - { "set_table_column_expand", 4132157579, 2185176273 }, + { "set_table_column_expand", 4258957458, 2185176273 }, #ifdef REAL_T_IS_DOUBLE { "add_image", 3346058748, 1507062345 }, { "push_dropcap", 981432822, 763534173 }, diff --git a/doc/classes/RichTextLabel.xml b/doc/classes/RichTextLabel.xml index 544f76d1c7e..2662cb072b6 100644 --- a/doc/classes/RichTextLabel.xml +++ b/doc/classes/RichTextLabel.xml @@ -597,6 +597,7 @@ + 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. For example, 2 columns with ratios 3 and 4 plus 70 pixels in available width would expand 30 and 40 pixels, respectively. diff --git a/misc/extension_api_validation/4.3-stable.expected b/misc/extension_api_validation/4.3-stable.expected index 91db0dd9b7a..d210417fe9f 100644 --- a/misc/extension_api_validation/4.3-stable.expected +++ b/misc/extension_api_validation/4.3-stable.expected @@ -278,3 +278,10 @@ Validate extension JSON: JSON file: Field was added in a way that breaks compati Validate extension JSON: JSON file: Field was added in a way that breaks compatibility 'classes/GPUParticles3D/methods/restart': arguments Added an optional keep_seed parameter to restart particles, to avoid modifying the seed to do particle seeking. + + +GH-101482 +--------- +Validate extension JSON: Error: Field 'classes/RichTextLabel/methods/set_table_column_expand/arguments': size changed value in new API, from 3 to 4. + +Added optional "shrink" argument. Compatibility method registered. diff --git a/scene/gui/rich_text_label.compat.inc b/scene/gui/rich_text_label.compat.inc index 7812ab05bc0..c3a6e114f29 100644 --- a/scene/gui/rich_text_label.compat.inc +++ b/scene/gui/rich_text_label.compat.inc @@ -30,6 +30,18 @@ #ifndef DISABLE_DEPRECATED +void RichTextLabel::_push_font_bind_compat_79053(const Ref &p_font, int p_size) { + push_font(p_font, p_size); +} + +void RichTextLabel::_set_table_column_expand_bind_compat_79053(int p_column, bool p_expand, int p_ratio) { + set_table_column_expand(p_column, p_expand, p_ratio, true); +} + +void RichTextLabel::_set_table_column_expand_bind_compat_101482(int p_column, bool p_expand, int p_ratio) { + set_table_column_expand(p_column, p_expand, p_ratio, true); +} + void RichTextLabel::_push_meta_bind_compat_99481(const Variant &p_meta, MetaUnderline p_underline_mode) { push_meta(p_meta, p_underline_mode, String()); } @@ -47,6 +59,9 @@ bool RichTextLabel::_remove_paragraph_bind_compat_91098(int p_paragraph) { } void RichTextLabel::_bind_compatibility_methods() { + ClassDB::bind_compatibility_method(D_METHOD("push_font", "font", "font_size"), &RichTextLabel::_push_font_bind_compat_79053); + ClassDB::bind_compatibility_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::_set_table_column_expand_bind_compat_79053); + ClassDB::bind_compatibility_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::_set_table_column_expand_bind_compat_101482, DEFVAL(1)); ClassDB::bind_compatibility_method(D_METHOD("push_meta", "data", "underline_mode"), &RichTextLabel::_push_meta_bind_compat_99481, DEFVAL(META_UNDERLINE_ALWAYS)); ClassDB::bind_compatibility_method(D_METHOD("push_meta", "data"), &RichTextLabel::_push_meta_bind_compat_89024); 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())); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 46aeba7ceaf..12954c62d24 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -693,7 +693,7 @@ void RichTextLabel::_set_table_size(ItemTable *p_table, int p_available_width) { table_need_fit = false; // Fit slim. for (int i = 0; i < col_count; i++) { - if (!p_table->columns[i].expand) { + if (!p_table->columns[i].expand || !p_table->columns[i].shrink) { continue; } 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 item->align_to_row = p_align_to_row; for (int i = 0; i < (int)item->columns.size(); i++) { item->columns[i].expand = false; + item->columns[i].shrink = true; item->columns[i].expand_ratio = 1; } _add_item(item, true, false); @@ -4038,7 +4039,7 @@ void RichTextLabel::push_context() { _add_item(item, true); } -void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio) { +void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio, bool p_shrink) { _stop_thread(); MutexLock data_lock(data_mutex); @@ -4047,6 +4048,7 @@ void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_r ItemTable *table = static_cast(current); ERR_FAIL_INDEX(p_column, (int)table->columns.size()); table->columns[p_column].expand = p_expand; + table->columns[p_column].shrink = p_shrink; table->columns[p_column].expand_ratio = p_ratio; } @@ -4582,13 +4584,19 @@ void RichTextLabel::append_text(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("cell"); } else if (tag.begins_with("cell ")) { + bool shrink = true; + OptionMap::Iterator shrink_option = bbcode_options.find("shrink"); + if (shrink_option) { + shrink = (shrink_option->value == "true"); + } + OptionMap::Iterator expand_option = bbcode_options.find("expand"); if (expand_option) { int ratio = expand_option->value.to_int(); if (ratio < 1) { ratio = 1; } - set_table_column_expand(get_current_table_column(), true, ratio); + set_table_column_expand(get_current_table_column(), true, ratio, shrink); } push_cell(); @@ -6429,7 +6437,7 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("push_strikethrough"), &RichTextLabel::push_strikethrough); ClassDB::bind_method(D_METHOD("push_table", "columns", "inline_align", "align_to_row"), &RichTextLabel::push_table, DEFVAL(INLINE_ALIGNMENT_TOP), DEFVAL(-1)); 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))); - ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand, DEFVAL(1)); + ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio", "shrink"), &RichTextLabel::set_table_column_expand, DEFVAL(1), DEFVAL(true)); ClassDB::bind_method(D_METHOD("set_cell_row_background_color", "odd_row_bg", "even_row_bg"), &RichTextLabel::set_cell_row_background_color); ClassDB::bind_method(D_METHOD("set_cell_border_color", "color"), &RichTextLabel::set_cell_border_color); 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() { ClassDB::bind_method(D_METHOD("is_menu_visible"), &RichTextLabel::is_menu_visible); ClassDB::bind_method(D_METHOD("menu_option", "option"), &RichTextLabel::menu_option); -#ifndef DISABLE_DEPRECATED - ClassDB::bind_compatibility_method(D_METHOD("push_font", "font", "font_size"), &RichTextLabel::push_font); - ClassDB::bind_compatibility_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand); -#endif // DISABLE_DEPRECATED - // Note: set "bbcode_enabled" first, to avoid unnecessary "text" resets. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text"); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 94b117821ac..6b46526049e 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -132,10 +132,13 @@ protected: static void _bind_methods(); #ifndef DISABLE_DEPRECATED + void _push_font_bind_compat_79053(const Ref &p_font, int p_size); + void _set_table_column_expand_bind_compat_79053(int p_column, bool p_expand, int p_ratio); void _push_meta_bind_compat_99481(const Variant &p_meta, MetaUnderline p_underline_mode); void _push_meta_bind_compat_89024(const Variant &p_meta); void _add_image_bind_compat_80410(const Ref &p_image, const int p_width, const int p_height, const Color &p_color, InlineAlignment p_alignment, const Rect2 &p_region); bool _remove_paragraph_bind_compat_91098(int p_paragraph); + void _set_table_column_expand_bind_compat_101482(int p_column, bool p_expand, int p_ratio); static void _bind_compatibility_methods(); #endif @@ -339,6 +342,7 @@ private: struct ItemTable : public Item { struct Column { bool expand = false; + bool shrink = true; int expand_ratio = 0; int min_width = 0; int max_width = 0; @@ -724,7 +728,7 @@ public: void push_fgcolor(const Color &p_color); void push_customfx(Ref p_custom_effect, Dictionary p_environment); void push_context(); - void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1); + void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1, bool p_shrink = true); void set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg); void set_cell_border_color(const Color &p_color); void set_cell_size_override(const Size2 &p_min_size, const Size2 &p_max_size);