diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-06-10 10:49:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 10:49:54 +0200 |
commit | 8b79f2aad4c42644ba0d398b427ccbe64c5d8204 (patch) | |
tree | 49248f413ac9721e73f168cfb6ebc3e179c06181 | |
parent | f25f0c54d676b72b7bbbdff2a696c45450d1bb88 (diff) | |
parent | d443a13244093a3b094dc52b197f9abb363bdfee (diff) |
Merge pull request #39350 from giulianob/improve-tree-redraw
Tree: Calling update in _gui_input less frequently
-rw-r--r-- | scene/gui/tree.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 45fcb448f8..7b9db7c081 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2364,7 +2364,6 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (pos.x < len) { cache.hover_type = Cache::CLICK_TITLE; cache.hover_index = i; - update(); break; } } @@ -2383,6 +2382,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { mpos.y += v_scroll->get_value(); } + TreeItem *old_it = cache.hover_item; + int old_col = cache.hover_cell; + int col, h, section; TreeItem *it = _find_item_at_pos(root, mpos, col, h, section); @@ -2397,18 +2399,21 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } } - if (it != cache.hover_item) { - cache.hover_item = it; - update(); - } + cache.hover_item = it; + cache.hover_cell = col; - if (it && col != cache.hover_cell) { - cache.hover_cell = col; - update(); + 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 if mouse enters/exits columns if (cache.hover_type != old_hover || cache.hover_index != old_index) { update(); } |