summaryrefslogtreecommitdiffstats
path: root/scene/gui/tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r--scene/gui/tree.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 2d3166270b..8a243fd68f 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -70,19 +70,27 @@ void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Si
}
void TreeItem::_changed_notify(int p_cell) {
- tree->item_changed(p_cell, this);
+ if (tree) {
+ tree->item_changed(p_cell, this);
+ }
}
void TreeItem::_changed_notify() {
- tree->item_changed(-1, this);
+ if (tree) {
+ tree->item_changed(-1, this);
+ }
}
void TreeItem::_cell_selected(int p_cell) {
- tree->item_selected(p_cell, this);
+ if (tree) {
+ tree->item_selected(p_cell, this);
+ }
}
void TreeItem::_cell_deselected(int p_cell) {
- tree->item_deselected(p_cell, this);
+ if (tree) {
+ tree->item_deselected(p_cell, this);
+ }
}
void TreeItem::_change_tree(Tree *p_tree) {
@@ -2050,7 +2058,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int text_width = item_width - theme_cache.inner_item_margin_left - theme_cache.inner_item_margin_right;
if (p_item->cells[i].icon.is_valid()) {
- text_width -= p_item->cells[i].get_icon_size().x + theme_cache.h_separation;
+ text_width -= _get_cell_icon_size(p_item->cells[i]).x + theme_cache.h_separation;
}
p_item->cells.write[i].text_buf->set_width(text_width);
@@ -4544,6 +4552,8 @@ TreeItem *Tree::get_selected() const {
void Tree::set_selected(TreeItem *p_item, int p_column) {
ERR_FAIL_INDEX(p_column, columns.size());
ERR_FAIL_NULL(p_item);
+ ERR_FAIL_COND_MSG(p_item->get_tree() != this, "The provided TreeItem does not belong to this Tree. Ensure that the TreeItem is a part of the Tree before setting it as selected.");
+
select_single_item(p_item, get_root(), p_column);
}