Skip to content

Commit c83ccae

Browse files
committed
Merge pull request #108469 from bruvzg/rtl_emb_click
[RTL] Fix padding and alignment of embedded image clicks.
2 parents c2ddb04 + 17e050c commit c83ccae

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

scene/gui/rich_text_label.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,10 +1715,21 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
17151715
const Glyph *glyphs = TS->shaped_text_get_glyphs(rid);
17161716
if (glyphs[glyph_idx].flags & TextServer::GRAPHEME_IS_EMBEDDED_OBJECT) {
17171717
// Emebedded object.
1718+
Vector2 obj_off = p_ofs + off;
17181719
for (int i = 0; i < objects.size(); i++) {
17191720
if (TS->shaped_text_get_object_glyph(rid, objects[i]) == glyph_idx) {
17201721
Rect2 obj_rect = TS->shaped_text_get_object_rect(rid, objects[i]);
1721-
obj_rect.position.y += baseline_y;
1722+
obj_rect.position += obj_off;
1723+
Item *it = items.get_or_null(objects[i]);
1724+
if (it && it->type == ITEM_IMAGE) {
1725+
ItemImage *img = reinterpret_cast<ItemImage *>(it);
1726+
if (img && img->pad && img->image.is_valid()) {
1727+
Size2 pad_size = rect.size.min(img->image->get_size());
1728+
Vector2 pad_off = (rect.size - pad_size) / 2;
1729+
obj_rect.position += pad_off;
1730+
obj_rect.size = pad_size;
1731+
}
1732+
}
17221733
if (p_click.y >= obj_rect.position.y && p_click.y <= obj_rect.position.y + obj_rect.size.y) {
17231734
char_pos = glyphs[glyph_idx].start;
17241735
char_clicked = true;

0 commit comments

Comments
 (0)