Skip to content

Commit 1e2fc9b

Browse files
committed
[RTL] Add paragraph separation theme property.
1 parent fc523ec commit 1e2fc9b

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

doc/classes/RichTextLabel.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,9 @@
882882
The size of the text outline.
883883
[b]Note:[/b] If using a font with [member FontFile.multichannel_signed_distance_field] enabled, its [member FontFile.msdf_pixel_range] must be set to at least [i]twice[/i] the value of [theme_item outline_size] for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.
884884
</theme_item>
885+
<theme_item name="paragraph_separation" data_type="constant" type="int" default="0">
886+
Additional vertical spacing between paragraphs (in pixels). Spacing is added after the last line. This value can be negative.
887+
</theme_item>
885888
<theme_item name="shadow_offset_x" data_type="constant" type="int" default="1">
886889
The horizontal offset of the font's shadow.
887890
</theme_item>

scene/gui/rich_text_label.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void RichTextLabel::_set_table_size(ItemTable *p_table, int p_available_width) {
762762

763763
float h = frame->lines[i].text_buf->get_size().y + (frame->lines[i].text_buf->get_line_count() - 1) * theme_cache.line_separation;
764764
if (i > 0) {
765-
h += theme_cache.line_separation;
765+
h += theme_cache.paragraph_separation;
766766
}
767767
if (frame->min_size_over.y > 0) {
768768
h = MAX(h, frame->min_size_over.y);
@@ -771,7 +771,7 @@ void RichTextLabel::_set_table_size(ItemTable *p_table, int p_available_width) {
771771
h = MIN(h, frame->max_size_over.y);
772772
}
773773
yofs += h;
774-
prev_h = frame->lines[i].offset.y + frame->lines[i].text_buf->get_size().y + frame->lines[i].text_buf->get_line_count() * theme_cache.line_separation;
774+
prev_h = frame->lines[i].offset.y + frame->lines[i].text_buf->get_size().y + (frame->lines[i].text_buf->get_line_count() - 1) * theme_cache.line_separation + theme_cache.paragraph_separation;
775775

776776
frame->lines[i].offset += offset;
777777
row_baseline = MAX(row_baseline, frame->lines[i].text_buf->get_line_ascent(frame->lines[i].text_buf->get_line_count() - 1));
@@ -1513,7 +1513,7 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
15131513
// Do not apply to the last line to avoid cutting text.
15141514
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation;
15151515
} else {
1516-
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + main->lines[to_line - 1].text_buf->get_line_count() * theme_cache.line_separation;
1516+
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation + theme_cache.paragraph_separation;
15171517
}
15181518
}
15191519
float vbegin = 0, vsep = 0;
@@ -1545,7 +1545,7 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
15451545
while (ofs.y < size.height && from_line < to_line) {
15461546
MutexLock lock(main->lines[from_line].text_buf->get_mutex());
15471547
_find_click_in_line(p_frame, from_line, ofs, text_rect.size.x, vsep, p_click, r_click_frame, r_click_line, r_click_item, r_click_char, false, p_meta);
1548-
ofs.y += main->lines[from_line].text_buf->get_size().y + main->lines[from_line].text_buf->get_line_count() * (theme_cache.line_separation + vsep);
1548+
ofs.y += main->lines[from_line].text_buf->get_size().y + (main->lines[from_line].text_buf->get_line_count() - 1) * (theme_cache.line_separation + vsep) + (theme_cache.paragraph_separation + vsep);
15491549
if (((r_click_item != nullptr) && ((*r_click_item) != nullptr)) || ((r_click_frame != nullptr) && ((*r_click_frame) != nullptr))) {
15501550
if (r_outside != nullptr) {
15511551
*r_outside = false;
@@ -1762,7 +1762,11 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
17621762
return table_offy;
17631763
}
17641764

1765-
off.y += TS->shaped_text_get_descent(rid) + theme_cache.line_separation + p_vsep;
1765+
if (line == l.text_buf->get_line_count() - 1) {
1766+
off.y += TS->shaped_text_get_descent(rid) + theme_cache.paragraph_separation + p_vsep;
1767+
} else {
1768+
off.y += TS->shaped_text_get_descent(rid) + theme_cache.line_separation + p_vsep;
1769+
}
17661770
}
17671771

17681772
// Text line hit.
@@ -1891,7 +1895,7 @@ int RichTextLabel::_find_first_line(int p_from, int p_to, int p_vofs) const {
18911895
}
18921896

18931897
_FORCE_INLINE_ float RichTextLabel::_calculate_line_vertical_offset(const RichTextLabel::Line &line) const {
1894-
return line.get_height(theme_cache.line_separation);
1898+
return line.get_height(theme_cache.line_separation, theme_cache.paragraph_separation);
18951899
}
18961900

18971901
void RichTextLabel::_update_theme_item_cache() {
@@ -2287,7 +2291,7 @@ void RichTextLabel::_notification(int p_what) {
22872291
// Do not apply to the last line to avoid cutting text.
22882292
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation;
22892293
} else {
2290-
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + main->lines[to_line - 1].text_buf->get_line_count() * theme_cache.line_separation;
2294+
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation + theme_cache.paragraph_separation;
22912295
}
22922296
}
22932297
float vbegin = 0, vsep = 0;
@@ -2450,7 +2454,7 @@ void RichTextLabel::_notification(int p_what) {
24502454
// Do not apply to the last line to avoid cutting text.
24512455
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation;
24522456
} else {
2453-
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + main->lines[to_line - 1].text_buf->get_line_count() * theme_cache.line_separation;
2457+
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation + theme_cache.paragraph_separation;
24542458
}
24552459
}
24562460
float vbegin = 0, vsep = 0;
@@ -2494,7 +2498,7 @@ void RichTextLabel::_notification(int p_what) {
24942498
if (drawn_lines > 0) {
24952499
visible_paragraph_count++;
24962500
}
2497-
ofs.y += main->lines[from_line].text_buf->get_size().y + main->lines[from_line].text_buf->get_line_count() * (theme_cache.line_separation + vsep);
2501+
ofs.y += main->lines[from_line].text_buf->get_size().y + (main->lines[from_line].text_buf->get_line_count() - 1) * (theme_cache.line_separation + vsep) + (theme_cache.paragraph_separation + vsep);
24982502
from_line++;
24992503
}
25002504
if (has_focus() && get_tree()->is_accessibility_enabled()) {
@@ -7129,7 +7133,7 @@ int RichTextLabel::get_content_height() const {
71297133
// Do not apply to the last line to avoid cutting text.
71307134
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation;
71317135
} else {
7132-
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + main->lines[to_line - 1].text_buf->get_line_count() * theme_cache.line_separation;
7136+
total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + (main->lines[to_line - 1].text_buf->get_line_count() - 1) * theme_cache.line_separation + theme_cache.paragraph_separation;
71337137
}
71347138
}
71357139
return total_height;
@@ -7448,6 +7452,7 @@ void RichTextLabel::_bind_methods() {
74487452
BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, RichTextLabel, progress_fg_style, "fill", "ProgressBar");
74497453

74507454
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, RichTextLabel, line_separation);
7455+
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, RichTextLabel, paragraph_separation);
74517456

74527457
BIND_THEME_ITEM(Theme::DATA_TYPE_FONT, RichTextLabel, normal_font);
74537458
BIND_THEME_ITEM(Theme::DATA_TYPE_FONT_SIZE, RichTextLabel, normal_font_size);

scene/gui/rich_text_label.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ class RichTextLabel : public Control {
181181
}
182182
}
183183

184-
_FORCE_INLINE_ float get_height(float line_separation) const {
185-
return offset.y + text_buf->get_size().y + text_buf->get_line_count() * line_separation;
184+
_FORCE_INLINE_ float get_height(float p_line_separation, float p_paragraph_separation) const {
185+
return offset.y + text_buf->get_size().y + (text_buf->get_line_count() - 1) * p_line_separation + p_paragraph_separation;
186186
}
187187
};
188188

@@ -717,6 +717,7 @@ class RichTextLabel : public Control {
717717
Ref<StyleBox> progress_fg_style;
718718

719719
int line_separation;
720+
int paragraph_separation;
720721

721722
Ref<Font> normal_font;
722723
int normal_font_size;

scene/scene_string_names.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class SceneStringNames {
6969
const StringName updated = "updated";
7070

7171
const StringName line_separation = "line_separation";
72+
const StringName paragraph_separation = "paragraph_separation";
7273
const StringName font = "font";
7374
const StringName font_size = "font_size";
7475
const StringName font_color = "font_color";

scene/theme/default_theme.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
11781178
theme->set_constant("shadow_outline_size", "RichTextLabel", Math::round(1 * scale));
11791179

11801180
theme->set_constant(SceneStringName(line_separation), "RichTextLabel", 0);
1181+
theme->set_constant(SceneStringName(paragraph_separation), "RichTextLabel", 0);
11811182
theme->set_constant("table_h_separation", "RichTextLabel", Math::round(3 * scale));
11821183
theme->set_constant("table_v_separation", "RichTextLabel", Math::round(3 * scale));
11831184

0 commit comments

Comments
 (0)