From aa77c26636f5331d91003e434c8bdf98b461d0cc Mon Sep 17 00:00:00 2001 From: Jordyfel Date: Mon, 9 Jun 2025 20:24:20 +0300 Subject: [PATCH] Fix itemlist text separation --- scene/gui/item_list.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 76939bd3158..dc95c6f1d54 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1578,8 +1578,6 @@ void ItemList::_notification(int p_what) { } if (!items[i].text.is_empty()) { - Vector2 size2 = items[i].text_buf->get_size(); - Color txt_modulate; if (items[i].selected && hovered == i) { txt_modulate = theme_cache.font_hovered_selected_color; @@ -1598,19 +1596,20 @@ void ItemList::_notification(int p_what) { } if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) { - text_ofs += base_ofs; - text_ofs += items[i].rect_cache.position; - text_ofs.y += MAX(theme_cache.v_separation, 0) / 2; + text_ofs.x += MAX(theme_cache.h_separation, 0) / 2; items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_CENTER); - float text_w = items[i].rect_cache.size.width; - if (wraparound_items && items[i].rect_cache.size.width > width) { - text_w -= items[i].rect_cache.size.width - width; + float text_w = items[i].rect_cache.size.width - text_ofs.x * 2; + if (wraparound_items && text_w + text_ofs.x > width) { + text_w = width - text_ofs.x; } items.write[i].text_buf->set_width(text_w); + text_ofs += base_ofs; + text_ofs += items[i].rect_cache.position; + if (rtl) { text_ofs.x = size.width - text_ofs.x - text_w; } @@ -1621,18 +1620,8 @@ void ItemList::_notification(int p_what) { items[i].text_buf->draw(get_canvas_item(), text_ofs, txt_modulate); } else { - if (fixed_column_width > 0) { - size2.x = MIN(size2.x, fixed_column_width); - } - - if (icon_mode == ICON_MODE_TOP) { - text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2; - text_ofs.x += MAX(theme_cache.h_separation, 0) / 2; - text_ofs.y += MAX(theme_cache.v_separation, 0) / 2; - } else { - text_ofs.y += (items[i].rect_cache.size.height - size2.y) / 2; - text_ofs.x += MAX(theme_cache.h_separation, 0) / 2; - } + text_ofs.y += (items[i].rect_cache.size.height - items[i].text_buf->get_size().y) / 2; + text_ofs.x += MAX(theme_cache.h_separation, 0) / 2; real_t text_width_ofs = text_ofs.x;