Skip to content

Commit 0dc6b7c

Browse files
committed
Merge pull request godotengine#101280 from Sauermann/fix-focus-rect-meta-access
Fix `__focus_rect` meta access error when resizing `Tree`
2 parents 82199a8 + 2a72f78 commit 0dc6b7c

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
@@ -3822,12 +3822,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
38223822
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
38233823
warp_mouse(range_drag_capture_pos);
38243824
} else {
3825-
Rect2 rect;
3826-
if (select_mode == SELECT_ROW) {
3827-
rect = get_selected()->get_meta("__focus_col_" + itos(selected_col));
3828-
} else {
3829-
rect = get_selected()->get_meta("__focus_rect");
3830-
}
3825+
Rect2 rect = _get_item_focus_rect(get_selected());
38313826
Point2 mpos = mb->get_position();
38323827
int icon_size_x = 0;
38333828
Ref<Texture2D> icon = get_selected()->get_icon(selected_col);
@@ -4205,12 +4200,7 @@ bool Tree::edit_selected(bool p_force_edit) {
42054200
}
42064201

42074202
float popup_scale = popup_editor->is_embedded() ? 1.0 : popup_editor->get_parent_visible_window()->get_content_scale_factor();
4208-
Rect2 rect;
4209-
if (select_mode == SELECT_ROW) {
4210-
rect = s->get_meta("__focus_col_" + itos(selected_col));
4211-
} else {
4212-
rect = s->get_meta("__focus_rect");
4213-
}
4203+
Rect2 rect = _get_item_focus_rect(s);
42144204
rect.position *= popup_scale;
42154205
popup_edited_item = s;
42164206
popup_edited_item_col = col;
@@ -4317,6 +4307,16 @@ bool Tree::edit_selected(bool p_force_edit) {
43174307
return false;
43184308
}
43194309

4310+
Rect2 Tree::_get_item_focus_rect(const TreeItem *p_item) const {
4311+
Rect2 rect;
4312+
if (select_mode == SELECT_ROW) {
4313+
rect = p_item->get_meta("__focus_col_" + itos(selected_col));
4314+
} else {
4315+
rect = p_item->get_meta("__focus_rect");
4316+
}
4317+
return rect;
4318+
}
4319+
43204320
bool Tree::is_editing() {
43214321
return popup_editor->is_visible();
43224322
}
@@ -4599,7 +4599,7 @@ void Tree::_notification(int p_what) {
45994599
case NOTIFICATION_RESIZED:
46004600
case NOTIFICATION_TRANSFORM_CHANGED: {
46014601
if (popup_edited_item != nullptr) {
4602-
Rect2 rect = popup_edited_item->get_meta("__focus_rect");
4602+
Rect2 rect = _get_item_focus_rect(popup_edited_item);
46034603

46044604
popup_editor->set_position(get_global_position() + rect.position);
46054605
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)