Merge pull request #15312 from poke1024/fix-rtl-table-wrap

Fixes word wrapping in tables in RichTextLabel
This commit is contained in:
Rémi Verschelde 2018-01-04 09:07:31 +01:00 committed by GitHub
commit 59ce175767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -451,6 +451,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
table->columns[i].width = 0; table->columns[i].width = 0;
} }
//compute minimum width for each cell //compute minimum width for each cell
const int available_width = p_width - hseparation * (table->columns.size() - 1) - wofs;
for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) { for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
ERR_CONTINUE(E->get()->type != ITEM_FRAME); //children should all be frames ERR_CONTINUE(E->get()->type != ITEM_FRAME); //children should all be frames
ItemFrame *frame = static_cast<ItemFrame *>(E->get()); ItemFrame *frame = static_cast<ItemFrame *>(E->get());
@ -461,7 +463,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
for (int i = 0; i < frame->lines.size(); i++) { for (int i = 0; i < frame->lines.size(); i++) {
_process_line(frame, Point2(), ly, p_width, i, PROCESS_CACHE, cfont, Color()); _process_line(frame, Point2(), ly, available_width, i, PROCESS_CACHE, cfont, Color());
table->columns[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].minimum_width); table->columns[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].minimum_width);
} }
idx++; idx++;
@ -470,11 +472,11 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
//compute available width and total ratio (for expanders) //compute available width and total ratio (for expanders)
int total_ratio = 0; int total_ratio = 0;
int available_width = p_width - hseparation * (table->columns.size() - 1); int remaining_width = available_width;
table->total_width = hseparation; table->total_width = hseparation;
for (int i = 0; i < table->columns.size(); i++) { for (int i = 0; i < table->columns.size(); i++) {
available_width -= table->columns[i].min_width; remaining_width -= table->columns[i].min_width;
if (table->columns[i].expand) if (table->columns[i].expand)
total_ratio += table->columns[i].expand_ratio; total_ratio += table->columns[i].expand_ratio;
} }
@ -484,7 +486,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
for (int i = 0; i < table->columns.size(); i++) { for (int i = 0; i < table->columns.size(); i++) {
table->columns[i].width = table->columns[i].min_width; table->columns[i].width = table->columns[i].min_width;
if (table->columns[i].expand) if (table->columns[i].expand)
table->columns[i].width += table->columns[i].expand_ratio * available_width / total_ratio; table->columns[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
table->total_width += table->columns[i].width + hseparation; table->total_width += table->columns[i].width + hseparation;
} }