Skip to content

Commit b1938c4

Browse files
committed
Fix SceneTree Item text display bug
1 parent b5bdb88 commit b1938c4

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

scene/gui/tree.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,54 +1945,59 @@ void Tree::draw_item_rect(TreeItem::Cell &p_cell, const Rect2i &p_rect, const Co
19451945
Size2 ts = p_cell.text_buf->get_size();
19461946
bool rtl = is_layout_rtl();
19471947

1948-
int w = 0;
1949-
Size2i bmsize;
1948+
Size2i icon_size;
19501949
if (p_cell.icon.is_valid()) {
1951-
bmsize = _get_cell_icon_size(p_cell);
1952-
w += bmsize.width + theme_cache.h_separation;
1953-
if (rect.size.width > 0 && (w + ts.width) > rect.size.width) {
1954-
ts.width = rect.size.width - w;
1955-
}
1950+
icon_size = _get_cell_icon_size(p_cell);
19561951
}
1957-
w += ts.width;
1952+
1953+
int displayed_width = 0;
1954+
if (p_cell.icon.is_valid()) {
1955+
displayed_width += icon_size.width + theme_cache.h_separation;
1956+
}
1957+
if (displayed_width + ts.width > rect.size.width) {
1958+
ts.width = rect.size.width - displayed_width;
1959+
}
1960+
displayed_width += ts.width;
1961+
1962+
int empty_width = rect.size.width - displayed_width;
19581963

19591964
switch (p_cell.text_alignment) {
19601965
case HORIZONTAL_ALIGNMENT_FILL:
19611966
case HORIZONTAL_ALIGNMENT_LEFT: {
19621967
if (rtl) {
1963-
rect.position.x += MAX(0, (rect.size.width - w));
1968+
rect.position.x += empty_width;
19641969
}
19651970
} break;
19661971
case HORIZONTAL_ALIGNMENT_CENTER:
1967-
rect.position.x += MAX(0, (rect.size.width - w) / 2);
1972+
rect.position.x += empty_width / 2;
19681973
break;
19691974
case HORIZONTAL_ALIGNMENT_RIGHT:
19701975
if (!rtl) {
1971-
rect.position.x += MAX(0, (rect.size.width - w));
1976+
rect.position.x += empty_width;
19721977
}
19731978
break;
19741979
}
19751980

19761981
RID ci = get_canvas_item();
19771982

1978-
if (rtl && rect.size.width > 0) {
1979-
Point2 draw_pos = rect.position;
1980-
draw_pos.y += Math::floor((rect.size.y - p_cell.text_buf->get_size().y) * 0.5);
1981-
if (p_ol_size > 0 && p_ol_color.a > 0) {
1982-
p_cell.text_buf->draw_outline(ci, draw_pos, p_ol_size, p_ol_color);
1983+
if (rtl) {
1984+
if (ts.width > 0) {
1985+
Point2 draw_pos = rect.position;
1986+
draw_pos.y += Math::floor((rect.size.y - p_cell.text_buf->get_size().y) * 0.5);
1987+
if (p_ol_size > 0 && p_ol_color.a > 0) {
1988+
p_cell.text_buf->draw_outline(ci, draw_pos, p_ol_size, p_ol_color);
1989+
}
1990+
p_cell.text_buf->draw(ci, draw_pos, p_color);
19831991
}
1984-
p_cell.text_buf->draw(ci, draw_pos, p_color);
19851992
rect.position.x += ts.width + theme_cache.h_separation;
1986-
rect.size.x -= ts.width + theme_cache.h_separation;
19871993
}
19881994

19891995
if (p_cell.icon.is_valid()) {
1990-
p_cell.draw_icon(ci, rect.position + Size2i(0, Math::floor((real_t)(rect.size.y - bmsize.y) / 2)), bmsize, p_icon_color);
1991-
rect.position.x += bmsize.x + theme_cache.h_separation;
1992-
rect.size.x -= bmsize.x + theme_cache.h_separation;
1996+
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);
1997+
rect.position.x += icon_size.x + theme_cache.h_separation;
19931998
}
19941999

1995-
if (!rtl && rect.size.width > 0) {
2000+
if (!rtl && ts.width > 0) {
19962001
Point2 draw_pos = rect.position;
19972002
draw_pos.y += Math::floor((rect.size.y - p_cell.text_buf->get_size().y) * 0.5);
19982003
if (p_ol_size > 0 && p_ol_color.a > 0) {

0 commit comments

Comments
 (0)