Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RTL] Fix indent in tables and tables in indent. #96735

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ float RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font
Line &l = p_frame->lines[p_line];
MutexLock lock(l.text_buf->get_mutex());

l.offset.x = _find_margin(l.from, p_base_font, p_base_font_size) + l.prefix_width;
l.indent = _find_margin(l.from, p_base_font, p_base_font_size) + l.prefix_width;
l.offset.x = l.indent;
l.text_buf->set_width(p_width - l.offset.x);

PackedFloat32Array tab_stops = _find_tab_stops(l.from);
Expand Down Expand Up @@ -501,7 +502,8 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
}

// Add indent.
l.offset.x = _find_margin(l.from, p_base_font, p_base_font_size) + l.prefix_width;
l.indent = _find_margin(l.from, p_base_font, p_base_font_size) + l.prefix_width;
l.offset.x = l.indent;
l.text_buf->set_width(p_width - l.offset.x);
l.text_buf->set_alignment(_find_alignment(l.from));
l.text_buf->set_direction(_find_direction(l.from));
Expand Down Expand Up @@ -625,8 +627,8 @@ float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
t_char_count += cell_ch;
remaining_characters -= cell_ch;

table->columns[column].min_width = MAX(table->columns[column].min_width, ceil(frame->lines[i].text_buf->get_size().x));
table->columns[column].max_width = MAX(table->columns[column].max_width, ceil(frame->lines[i].text_buf->get_non_wrapped_size().x));
table->columns[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].indent + ceil(frame->lines[i].text_buf->get_size().x));
table->columns[column].max_width = MAX(table->columns[column].max_width, frame->lines[i].indent + ceil(frame->lines[i].text_buf->get_non_wrapped_size().x));
}
idx++;
}
Expand Down Expand Up @@ -977,6 +979,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o

if (frame->lines.size() != 0 && row < row_count) {
Vector2 coff = frame->lines[0].offset;
coff.x -= frame->lines[0].indent;
if (rtl) {
coff.x = rect.size.width - table->columns[col].width - coff.x;
}
Expand Down Expand Up @@ -2548,6 +2551,10 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font, int
float margin = 0.0;

while (item) {
if (item->type == ITEM_FRAME) {
break;
}

if (item->type == ITEM_INDENT) {
Ref<Font> font = p_base_font;
int font_size = p_base_font_size;
Expand Down Expand Up @@ -4295,7 +4302,6 @@ void RichTextLabel::append_text(const String &p_bbcode) {
parsing_bbcode.store(true);

int pos = 0;
int indent_level = 0;

bool in_bold = false;
bool in_italics = false;
Expand Down Expand Up @@ -4377,7 +4383,7 @@ void RichTextLabel::append_text(const String &p_bbcode) {
in_italics = false;
}
if ((tag_stack.front()->get() == "indent") || (tag_stack.front()->get() == "ol") || (tag_stack.front()->get() == "ul")) {
indent_level--;
current_frame->indent_level--;
}

if (!tag_ok) {
Expand Down Expand Up @@ -4650,44 +4656,44 @@ void RichTextLabel::append_text(const String &p_bbcode) {
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "ul") {
indent_level++;
push_list(indent_level, LIST_DOTS, false);
current_frame->indent_level++;
push_list(current_frame->indent_level, LIST_DOTS, false);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag.begins_with("ul bullet=")) {
String bullet = _get_tag_value(tag);
indent_level++;
push_list(indent_level, LIST_DOTS, false, bullet);
current_frame->indent_level++;
push_list(current_frame->indent_level, LIST_DOTS, false, bullet);
pos = brk_end + 1;
tag_stack.push_front("ul");
} else if ((tag == "ol") || (tag == "ol type=1")) {
indent_level++;
push_list(indent_level, LIST_NUMBERS, false);
current_frame->indent_level++;
push_list(current_frame->indent_level, LIST_NUMBERS, false);
pos = brk_end + 1;
tag_stack.push_front("ol");
} else if (tag == "ol type=a") {
indent_level++;
push_list(indent_level, LIST_LETTERS, false);
current_frame->indent_level++;
push_list(current_frame->indent_level, LIST_LETTERS, false);
pos = brk_end + 1;
tag_stack.push_front("ol");
} else if (tag == "ol type=A") {
indent_level++;
push_list(indent_level, LIST_LETTERS, true);
current_frame->indent_level++;
push_list(current_frame->indent_level, LIST_LETTERS, true);
pos = brk_end + 1;
tag_stack.push_front("ol");
} else if (tag == "ol type=i") {
indent_level++;
push_list(indent_level, LIST_ROMAN, false);
current_frame->indent_level++;
push_list(current_frame->indent_level, LIST_ROMAN, false);
pos = brk_end + 1;
tag_stack.push_front("ol");
} else if (tag == "ol type=I") {
indent_level++;
push_list(indent_level, LIST_ROMAN, true);
current_frame->indent_level++;
push_list(current_frame->indent_level, LIST_ROMAN, true);
pos = brk_end + 1;
tag_stack.push_front("ol");
} else if (tag == "indent") {
indent_level++;
push_indent(indent_level);
current_frame->indent_level++;
push_indent(current_frame->indent_level);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag.begins_with("lang=")) {
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/rich_text_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class RichTextLabel : public Control {
Color dc_ol_color;

Vector2 offset;
float indent = 0.0;
int char_offset = 0;
int char_count = 0;

Expand Down Expand Up @@ -205,6 +206,7 @@ class RichTextLabel : public Control {
Size2 min_size_over = Size2(-1, -1);
Size2 max_size_over = Size2(-1, -1);
Rect2 padding;
int indent_level = 0;

ItemFrame() {
type = ITEM_FRAME;
Expand Down