diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-04-07 16:36:50 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-07 16:36:50 -0300 |
commit | 51f689de3cbe167e117a042f9acb19c0cf4571ae (patch) | |
tree | 008ba370980d1e3914379aec887484e555bef25a /scene/gui | |
parent | 644ada1aac6795d50dc9dc1f6a0cd3977b854359 (diff) | |
parent | ef2b7b090c5fc1b84833e5b12d9fa168dbbcf9d5 (diff) |
Merge pull request #17744 from robfram/fix-rtl-table
Fix `RichTextLabel` column size growing beyond its calculated `max_width`
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/rich_text_label.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index ae07d5e671..6bfc4d4dee 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -516,6 +516,39 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & table->total_width += table->columns[i].width + hseparation; } + //resize to max_width if needed and distribute the remaining space + bool table_need_fit = true; + while (table_need_fit) { + table_need_fit = false; + //fit slim + for (int i = 0; i < table->columns.size(); i++) { + if (!table->columns[i].expand) + continue; + int dif = table->columns[i].width - table->columns[i].max_width; + if (dif > 0) { + table_need_fit = true; + table->columns[i].width = table->columns[i].max_width; + table->total_width -= dif; + total_ratio -= table->columns[i].expand_ratio; + } + } + //grow + remaining_width = available_width - table->total_width; + if (remaining_width > 0 && total_ratio > 0) { + for (int i = 0; i < table->columns.size(); i++) { + if (table->columns[i].expand) { + int dif = table->columns[i].max_width - table->columns[i].width; + if (dif > 0) { + int slice = table->columns[i].expand_ratio * remaining_width / total_ratio; + int incr = MIN(dif, slice); + table->columns[i].width += incr; + table->total_width += incr; + } + } + } + } + } + //compute caches properly again with the right width idx = 0; for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) { |