Skip to content

Commit 2a72f78

Browse files
committed
Fix __focus_rect meta access when resizing Tree
`NOTIFICATION_RESIZED` outputs errors, if `select_mode == SELECT_ROW`. This PR unifies the access to the item focus rect.
1 parent d2ada64 commit 2a72f78

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

scene/gui/tree.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,12 +3820,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
38203820
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
38213821
warp_mouse(range_drag_capture_pos);
38223822
} else {
3823-
Rect2 rect;
3824-
if (select_mode == SELECT_ROW) {
3825-
rect = get_selected()->get_meta("__focus_col_" + itos(selected_col));
3826-
} else {
3827-
rect = get_selected()->get_meta("__focus_rect");
3828-
}
3823+
Rect2 rect = _get_item_focus_rect(get_selected());
38293824
Point2 mpos = mb->get_position();
38303825
int icon_size_x = 0;
38313826
Ref<Texture2D> icon = get_selected()->get_icon(selected_col);
@@ -4203,12 +4198,7 @@ bool Tree::edit_selected(bool p_force_edit) {
42034198
}
42044199

42054200
float popup_scale = popup_editor->is_embedded() ? 1.0 : popup_editor->get_parent_visible_window()->get_content_scale_factor();
4206-
Rect2 rect;
4207-
if (select_mode == SELECT_ROW) {
4208-
rect = s->get_meta("__focus_col_" + itos(selected_col));
4209-
} else {
4210-
rect = s->get_meta("__focus_rect");
4211-
}
4201+
Rect2 rect = _get_item_focus_rect(s);
42124202
rect.position *= popup_scale;
42134203
popup_edited_item = s;
42144204
popup_edited_item_col = col;
@@ -4315,6 +4305,16 @@ bool Tree::edit_selected(bool p_force_edit) {
43154305
return false;
43164306
}
43174307

4308+
Rect2 Tree::_get_item_focus_rect(const TreeItem *p_item) const {
4309+
Rect2 rect;
4310+
if (select_mode == SELECT_ROW) {
4311+
rect = p_item->get_meta("__focus_col_" + itos(selected_col));
4312+
} else {
4313+
rect = p_item->get_meta("__focus_rect");
4314+
}
4315+
return rect;
4316+
}
4317+
43184318
bool Tree::is_editing() {
43194319
return popup_editor->is_visible();
43204320
}
@@ -4597,7 +4597,7 @@ void Tree::_notification(int p_what) {
45974597
case NOTIFICATION_RESIZED:
45984598
case NOTIFICATION_TRANSFORM_CHANGED: {
45994599
if (popup_edited_item != nullptr) {
4600-
Rect2 rect = popup_edited_item->get_meta("__focus_rect");
4600+
Rect2 rect = _get_item_focus_rect(popup_edited_item);
46014601

46024602
popup_editor->set_position(get_global_position() + rect.position);
46034603
popup_editor->set_size(rect.size);

scene/gui/tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ class Tree : public Control {
716716

717717
Rect2 _get_scrollbar_layout_rect() const;
718718
Rect2 _get_content_rect() const; // Considering the background stylebox and scrollbars.
719+
Rect2 _get_item_focus_rect(const TreeItem *p_item) const;
719720

720721
protected:
721722
virtual void _update_theme_item_cache() override;

0 commit comments

Comments
 (0)