Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TreeItem shows cell edit in the wrong column when select_mode=Row and TreeItem has multiple columns #89977

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2195,9 +2195,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if ((select_mode == SELECT_ROW && selected_item == p_item) || p_item->cells[i].selected || !p_item->has_meta("__focus_rect")) {
Rect2i r = cell_rect;

p_item->set_meta("__focus_rect", Rect2(r.position, r.size));

if (select_mode != SELECT_ROW) {
p_item->set_meta("__focus_rect", Rect2(r.position, r.size));
if (rtl) {
r.position.x = get_size().width - r.position.x - r.size.x;
}
Expand All @@ -2208,6 +2207,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
theme_cache.selected->draw(ci, r);
}
}
} else {
p_item->set_meta("__focus_col_" + itos(i), Rect2(r.position, r.size));
}
}

Expand Down Expand Up @@ -2693,7 +2694,6 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
if (p_selected == p_current && (!c.selected || allow_reselect)) {
c.selected = true;
selected_item = p_selected;
selected_col = 0;
if (!emitted_row) {
emit_signal(SNAME("item_selected"));
emitted_row = true;
Expand All @@ -2704,6 +2704,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
c.selected = false;
}
}
if (&selected_cell == &c) {
selected_col = i;
}
} else if (select_mode == SELECT_SINGLE || select_mode == SELECT_MULTI) {
if (!r_in_range && &selected_cell == &c) {
if (!selected_cell.selected || allow_reselect) {
Expand Down Expand Up @@ -3778,7 +3781,12 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
warp_mouse(range_drag_capture_pos);
} else {
Rect2 rect = get_selected()->get_meta("__focus_rect");
Rect2 rect;
if (select_mode == SELECT_ROW) {
rect = get_selected()->get_meta("__focus_col_" + itos(selected_col));
} else {
rect = get_selected()->get_meta("__focus_rect");
}
Point2 mpos = mb->get_position();
int icon_size_x = 0;
Ref<Texture2D> icon = get_selected()->get_icon(selected_col);
Expand Down Expand Up @@ -3987,7 +3995,12 @@ bool Tree::edit_selected(bool p_force_edit) {
return false;
}

Rect2 rect = s->get_meta("__focus_rect");
Rect2 rect;
AThousandShips marked this conversation as resolved.
Show resolved Hide resolved
if (select_mode == SELECT_ROW) {
rect = s->get_meta("__focus_col_" + itos(selected_col));
} else {
rect = s->get_meta("__focus_rect");
}
popup_edited_item = s;
popup_edited_item_col = col;

Expand Down
Loading