Skip to content

Commit

Permalink
Fix godotengine#88892: TreeItem shows cell edit in the wrong column w…
Browse files Browse the repository at this point in the history
…hen SelectMode=Row and TreeItem has multiple columns

Editor would not be brought up when clicking on all but the last column on a TreeItem with SelectMode=Row with
multiple columns and when the editor was being brought up when clicking on the last column, it was editing the first column

Fixed draw_item, gui_input and edit_selected functions by setting set_meta parameter for each column
Fixed select_single_item function by changing selected_col depending on input
  • Loading branch information
aqfranco authored and DanielSnd committed Apr 10, 2024
1 parent c2ff298 commit 52ef983
Showing 1 changed file with 18 additions and 5 deletions.
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;
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

0 comments on commit 52ef983

Please sign in to comment.