Fix Treeitem icon overflows column boundary

This commit is contained in:
BrotherShort
2025-11-15 17:22:37 +08:00
parent 788beb36dc
commit 2f0ff3aeb7
2 changed files with 13 additions and 7 deletions

View File

@@ -59,23 +59,23 @@ Size2 TreeItem::Cell::get_icon_size() const {
}
}
void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size, const Color &p_color) const {
void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size, const Rect2i &p_region, const Color &p_color) const {
if (icon.is_null()) {
return;
}
Size2i dsize = (p_size == Size2()) ? icon->get_size() : p_size;
if (icon_region == Rect2i()) {
if (p_region == Rect2i()) {
icon->draw_rect_region(p_where, Rect2(p_pos, dsize), Rect2(Point2(), icon->get_size()), p_color);
if (icon_overlay.is_valid()) {
Vector2 offset = icon->get_size() - icon_overlay->get_size();
icon_overlay->draw_rect_region(p_where, Rect2(p_pos + offset, dsize), Rect2(Point2(), icon_overlay->get_size()), p_color);
}
} else {
icon->draw_rect_region(p_where, Rect2(p_pos, dsize), icon_region, p_color);
icon->draw_rect_region(p_where, Rect2(p_pos, dsize), p_region, p_color);
if (icon_overlay.is_valid()) {
icon_overlay->draw_rect_region(p_where, Rect2(p_pos, dsize), icon_region, p_color);
icon_overlay->draw_rect_region(p_where, Rect2(p_pos, dsize), p_region, p_color);
}
}
}
@@ -2088,7 +2088,7 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
int displayed_width = 0;
if (p_cell.icon.is_valid()) {
displayed_width += icon_size.width + theme_cache.icon_h_separation;
displayed_width = MIN(displayed_width + icon_size.width + theme_cache.icon_h_separation, rect.size.width);
}
if (displayed_width + ts.width > rect.size.width) {
ts.width = rect.size.width - displayed_width;
@@ -2129,7 +2129,13 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co
}
if (p_cell.icon.is_valid()) {
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);
Point2 icon_pos = rect.position + Size2i(0, Math::floor((real_t)(rect.size.y - icon_size.y) / 2));
Rect2i icon_region = (p_cell.icon_region == Rect2i()) ? Rect2i(Point2(), p_cell.icon->get_size()) : p_cell.icon_region;
if (icon_size.width > rect.size.width) {
icon_region.size.width = icon_region.size.width * rect.size.width / icon_size.width;
icon_size.width = rect.size.width;
}
p_cell.draw_icon(ci, icon_pos, icon_size, icon_region, p_icon_color);
rect.position.x += icon_size.x + theme_cache.icon_h_separation;
}

View File

@@ -132,7 +132,7 @@ private:
}
Size2 get_icon_size() const;
void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2(), const Color &p_color = Color()) const;
void draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size = Size2(), const Rect2i &p_region = Rect2i(), const Color &p_color = Color()) const;
};
mutable RID accessibility_row_element;