Skip to content

Commit 1a367f3

Browse files
committed
Merge pull request #104685 from bruvzg/rtl_vpad
[RTL] Improve vertical padding.
2 parents be57309 + a2919f8 commit 1a367f3

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

scene/gui/rich_text_label.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,20 +728,24 @@ void RichTextLabel::_set_table_size(ItemTable *p_table, int p_available_width) {
728728
int idx = 0;
729729
p_table->total_height = 0;
730730
p_table->rows.clear();
731+
p_table->rows_no_padding.clear();
731732
p_table->rows_baseline.clear();
732733

733734
Vector2 offset = Vector2(theme_cache.table_h_separation * 0.5, theme_cache.table_v_separation * 0.5).floor();
734735
float row_height = 0.0;
736+
float row_top_padding = 0.0;
737+
float row_bottom_padding = 0.0;
738+
const List<Item *>::Element *prev = p_table->subitems.front();
735739

736-
for (const List<Item *>::Element *E = p_table->subitems.front(); E; E = E->next()) {
740+
for (const List<Item *>::Element *E = prev; E; E = E->next()) {
737741
ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
738742
ItemFrame *frame = static_cast<ItemFrame *>(E->get());
739743

740744
int column = idx % col_count;
741745

742746
offset.x += frame->padding.position.x;
743-
float yofs = frame->padding.position.y;
744-
float prev_h = 0;
747+
float yofs = 0.0;
748+
float prev_h = 0.0;
745749
float row_baseline = 0.0;
746750
for (int i = 0; i < (int)frame->lines.size(); i++) {
747751
MutexLock sub_lock(frame->lines[i].text_buf->get_mutex());
@@ -768,19 +772,35 @@ void RichTextLabel::_set_table_size(ItemTable *p_table, int p_available_width) {
768772
frame->lines[i].offset += offset;
769773
row_baseline = MAX(row_baseline, frame->lines[i].text_buf->get_line_ascent(frame->lines[i].text_buf->get_line_count() - 1));
770774
}
771-
yofs += frame->padding.size.y;
775+
row_top_padding = MAX(row_top_padding, frame->padding.position.y);
776+
row_bottom_padding = MAX(row_bottom_padding, frame->padding.size.y);
772777
offset.x += p_table->columns[column].width + theme_cache.table_h_separation + frame->padding.size.x;
773778

774779
row_height = MAX(yofs, row_height);
775780
// Add row height after last column of the row or last cell of the table.
776781
if (column == col_count - 1 || E->next() == nullptr) {
777782
offset.x = Math::floor(theme_cache.table_h_separation * 0.5);
783+
float row_contents_height = row_height;
784+
row_height += row_top_padding + row_bottom_padding;
778785
row_height += theme_cache.table_v_separation;
779786
p_table->total_height += row_height;
780787
offset.y += row_height;
781788
p_table->rows.push_back(row_height);
789+
p_table->rows_no_padding.push_back(row_contents_height);
782790
p_table->rows_baseline.push_back(p_table->total_height - row_height + row_baseline + Math::floor(theme_cache.table_v_separation * 0.5));
783-
row_height = 0;
791+
for (const List<Item *>::Element *F = prev; F; F = F->next()) {
792+
ItemFrame *in_frame = static_cast<ItemFrame *>(F->get());
793+
for (int i = 0; i < (int)in_frame->lines.size(); i++) {
794+
in_frame->lines[i].offset.y += row_top_padding;
795+
}
796+
if (in_frame == frame) {
797+
break;
798+
}
799+
}
800+
row_height = 0.0;
801+
row_top_padding = 0.0;
802+
row_bottom_padding = 0.0;
803+
prev = E->next();
784804
}
785805
idx++;
786806
}
@@ -993,17 +1013,17 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
9931013
if (row % 2 == 0) {
9941014
Color c = frame->odd_row_bg != Color(0, 0, 0, 0) ? frame->odd_row_bg : odd_row_bg;
9951015
if (c.a > 0.0) {
996-
draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position - Vector2(h_separation * 0.5, v_separation * 0.5).floor(), Size2(table->columns[col].width + h_separation + frame->padding.position.x + frame->padding.size.x, table->rows[row])), c, true);
1016+
draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position - Vector2(h_separation * 0.5, v_separation * 0.5).floor(), Size2(table->columns[col].width + h_separation + frame->padding.position.x + frame->padding.size.x, table->rows_no_padding[row] + frame->padding.position.y + frame->padding.size.y)), c, true);
9971017
}
9981018
} else {
9991019
Color c = frame->even_row_bg != Color(0, 0, 0, 0) ? frame->even_row_bg : even_row_bg;
10001020
if (c.a > 0.0) {
1001-
draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position - Vector2(h_separation * 0.5, v_separation * 0.5).floor(), Size2(table->columns[col].width + h_separation + frame->padding.position.x + frame->padding.size.x, table->rows[row])), c, true);
1021+
draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position - Vector2(h_separation * 0.5, v_separation * 0.5).floor(), Size2(table->columns[col].width + h_separation + frame->padding.position.x + frame->padding.size.x, table->rows_no_padding[row] + frame->padding.position.y + frame->padding.size.y)), c, true);
10021022
}
10031023
}
10041024
Color bc = frame->border != Color(0, 0, 0, 0) ? frame->border : border;
10051025
if (bc.a > 0.0) {
1006-
draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position - Vector2(h_separation * 0.5, v_separation * 0.5).floor(), Size2(table->columns[col].width + h_separation + frame->padding.position.x + frame->padding.size.x, table->rows[row])), bc, false);
1026+
draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position - Vector2(h_separation * 0.5, v_separation * 0.5).floor(), Size2(table->columns[col].width + h_separation + frame->padding.position.x + frame->padding.size.x, table->rows_no_padding[row] + frame->padding.position.y + frame->padding.size.y)), bc, false);
10071027
}
10081028
}
10091029

scene/gui/rich_text_label.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ class RichTextLabel : public Control {
352352

353353
LocalVector<Column> columns;
354354
LocalVector<float> rows;
355+
LocalVector<float> rows_no_padding;
355356
LocalVector<float> rows_baseline;
356357

357358
int align_to_row = -1;

0 commit comments

Comments
 (0)