From 17e050c64f40238b5a67b78d70d6b50cc11c2620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Thu, 10 Jul 2025 10:57:12 +0300 Subject: [PATCH] [RTL] Fix padding and alignment of embedded image clicks. --- scene/gui/rich_text_label.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 9e5d253bb99..35759df83ab 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1704,10 +1704,21 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V const Glyph *glyphs = TS->shaped_text_get_glyphs(rid); if (glyphs[glyph_idx].flags & TextServer::GRAPHEME_IS_EMBEDDED_OBJECT) { // Emebedded object. + Vector2 obj_off = p_ofs + off; for (int i = 0; i < objects.size(); i++) { if (TS->shaped_text_get_object_glyph(rid, objects[i]) == glyph_idx) { Rect2 obj_rect = TS->shaped_text_get_object_rect(rid, objects[i]); - obj_rect.position.y += baseline_y; + obj_rect.position += obj_off; + Item *it = items.get_or_null(objects[i]); + if (it && it->type == ITEM_IMAGE) { + ItemImage *img = reinterpret_cast(it); + if (img && img->pad && img->image.is_valid()) { + Size2 pad_size = rect.size.min(img->image->get_size()); + Vector2 pad_off = (rect.size - pad_size) / 2; + obj_rect.position += pad_off; + obj_rect.size = pad_size; + } + } if (p_click.y >= obj_rect.position.y && p_click.y <= obj_rect.position.y + obj_rect.size.y) { char_pos = glyphs[glyph_idx].start; char_clicked = true;