@@ -2019,54 +2019,59 @@ void Tree::draw_item_rect(TreeItem::Cell &p_cell, const Rect2i &p_rect, const Co
20192019 Size2 ts = p_cell.text_buf ->get_size ();
20202020 bool rtl = is_layout_rtl ();
20212021
2022- int w = 0 ;
2023- Size2i bmsize;
2022+ Size2i icon_size;
20242023 if (p_cell.icon .is_valid ()) {
2025- bmsize = _get_cell_icon_size (p_cell);
2026- w += bmsize.width + theme_cache.h_separation ;
2027- if (rect.size .width > 0 && (w + ts.width ) > rect.size .width ) {
2028- ts.width = rect.size .width - w;
2029- }
2024+ icon_size = _get_cell_icon_size (p_cell);
20302025 }
2031- w += ts.width ;
2026+
2027+ int displayed_width = 0 ;
2028+ if (p_cell.icon .is_valid ()) {
2029+ displayed_width += icon_size.width + theme_cache.h_separation ;
2030+ }
2031+ if (displayed_width + ts.width > rect.size .width ) {
2032+ ts.width = rect.size .width - displayed_width;
2033+ }
2034+ displayed_width += ts.width ;
2035+
2036+ int empty_width = rect.size .width - displayed_width;
20322037
20332038 switch (p_cell.text_alignment ) {
20342039 case HORIZONTAL_ALIGNMENT_FILL:
20352040 case HORIZONTAL_ALIGNMENT_LEFT: {
20362041 if (rtl) {
2037- rect.position .x += MAX ( 0 , (rect. size . width - w)) ;
2042+ rect.position .x += empty_width ;
20382043 }
20392044 } break ;
20402045 case HORIZONTAL_ALIGNMENT_CENTER:
2041- rect.position .x += MAX ( 0 , (rect. size . width - w) / 2 ) ;
2046+ rect.position .x += empty_width / 2 ;
20422047 break ;
20432048 case HORIZONTAL_ALIGNMENT_RIGHT:
20442049 if (!rtl) {
2045- rect.position .x += MAX ( 0 , (rect. size . width - w)) ;
2050+ rect.position .x += empty_width ;
20462051 }
20472052 break ;
20482053 }
20492054
20502055 RID ci = get_canvas_item ();
20512056
2052- if (rtl && rect.size .width > 0 ) {
2053- Point2 draw_pos = rect.position ;
2054- draw_pos.y += Math::floor ((rect.size .y - p_cell.text_buf ->get_size ().y ) * 0.5 );
2055- if (p_ol_size > 0 && p_ol_color.a > 0 ) {
2056- p_cell.text_buf ->draw_outline (ci, draw_pos, p_ol_size, p_ol_color);
2057+ if (rtl) {
2058+ if (ts.width > 0 ) {
2059+ Point2 draw_pos = rect.position ;
2060+ draw_pos.y += Math::floor ((rect.size .y - p_cell.text_buf ->get_size ().y ) * 0.5 );
2061+ if (p_ol_size > 0 && p_ol_color.a > 0 ) {
2062+ p_cell.text_buf ->draw_outline (ci, draw_pos, p_ol_size, p_ol_color);
2063+ }
2064+ p_cell.text_buf ->draw (ci, draw_pos, p_color);
20572065 }
2058- p_cell.text_buf ->draw (ci, draw_pos, p_color);
20592066 rect.position .x += ts.width + theme_cache.h_separation ;
2060- rect.size .x -= ts.width + theme_cache.h_separation ;
20612067 }
20622068
20632069 if (p_cell.icon .is_valid ()) {
2064- p_cell.draw_icon (ci, rect.position + Size2i (0 , Math::floor ((real_t )(rect.size .y - bmsize.y ) / 2 )), bmsize, p_icon_color);
2065- rect.position .x += bmsize.x + theme_cache.h_separation ;
2066- rect.size .x -= bmsize.x + theme_cache.h_separation ;
2070+ p_cell.draw_icon (ci, rect.position + Size2i (0 , Math::floor ((real_t )(rect.size .y - icon_size.y ) / 2 )), icon_size, p_icon_color);
2071+ rect.position .x += icon_size.x + theme_cache.h_separation ;
20672072 }
20682073
2069- if (!rtl && rect. size .width > 0 ) {
2074+ if (!rtl && ts .width > 0 ) {
20702075 Point2 draw_pos = rect.position ;
20712076 draw_pos.y += Math::floor ((rect.size .y - p_cell.text_buf ->get_size ().y ) * 0.5 );
20722077 if (p_ol_size > 0 && p_ol_color.a > 0 ) {
0 commit comments