summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-11-05 11:51:59 +0100
committerGitHub <noreply@github.com>2017-11-05 11:51:59 +0100
commita0ac0804ca34317faea1ee6dbc66037178b0f727 (patch)
tree65f1c3304ec19f2389def1cfa5fbb16568b24103 /scene/gui
parent3149ef084b9aaae33d74cfb28592ed95726fb88d (diff)
parent8f204d78fd20d0ad1008fa1643b863c863c0a0be (diff)
Merge pull request #12640 from poke1024/createnode-ui
In Create New Node, always select and show best (shortest) match
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/tree.cpp20
-rw-r--r--scene/gui/tree.h1
2 files changed, 21 insertions, 0 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 5c6f2b0d01..f2e5919b5f 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -3332,6 +3332,26 @@ Point2 Tree::get_scroll() const {
return ofs;
}
+void Tree::scroll_to_item(TreeItem *p_item) {
+
+ if (!is_visible_in_tree()) {
+
+ // hack to work around crash in get_item_rect() if Tree is not in tree.
+ return;
+ }
+
+ // make sure the scrollbar min and max are up to date with latest changes.
+ update_scrollbars();
+
+ const Rect2 r = get_item_rect(p_item);
+
+ if (r.position.y < v_scroll->get_value()) {
+ v_scroll->set_value(r.position.y);
+ } else if (r.position.y + r.size.y + 2 * cache.vseparation > v_scroll->get_value() + get_size().y) {
+ v_scroll->set_value(r.position.y + r.size.y + 2 * cache.vseparation - get_size().y);
+ }
+}
+
TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards) {
while (p_at) {
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 2ee91a8b73..64d6016942 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -570,6 +570,7 @@ public:
TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false);
Point2 get_scroll() const;
+ void scroll_to_item(TreeItem *p_item);
void set_cursor_can_exit_tree(bool p_enable);
bool can_cursor_exit_tree() const;