Tree: Calling update in _gui_input less frequently

(cherry picked from commit d443a13244)
This commit is contained in:
Giuliano Barberi 2020-06-06 17:02:22 -04:00 committed by Rémi Verschelde
parent b2c7f94ae2
commit 221051d523
1 changed files with 13 additions and 8 deletions

View File

@ -2475,7 +2475,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
cache.hover_type = Cache::CLICK_TITLE; cache.hover_type = Cache::CLICK_TITLE;
cache.hover_index = i; cache.hover_index = i;
update();
break; break;
} }
} }
@ -2494,6 +2493,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
if (v_scroll->is_visible_in_tree()) if (v_scroll->is_visible_in_tree())
mpos.y += v_scroll->get_value(); mpos.y += v_scroll->get_value();
TreeItem *old_it = cache.hover_item;
int old_col = cache.hover_cell;
int col, h, section; int col, h, section;
TreeItem *it = _find_item_at_pos(root, mpos, col, h, section); TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
@ -2508,18 +2510,21 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} }
} }
if (it != cache.hover_item) {
cache.hover_item = it; cache.hover_item = it;
update();
}
if (it && col != cache.hover_cell) {
cache.hover_cell = col; cache.hover_cell = col;
if (it != old_it || col != old_col) {
// Only need to update if mouse enters/exits a button
bool was_over_button = old_it && old_it->cells[old_col].custom_button;
bool is_over_button = it && it->cells[col].custom_button;
if (was_over_button || is_over_button) {
update(); update();
} }
} }
} }
}
// Update if mouse enters/exits columns
if (cache.hover_type != old_hover || cache.hover_index != old_index) { if (cache.hover_type != old_hover || cache.hover_index != old_index) {
update(); update();
} }