summaryrefslogtreecommitdiff
path: root/scene/gui/tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r--scene/gui/tree.cpp77
1 files changed, 53 insertions, 24 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index d479a1636a..964f376dbd 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -2162,9 +2162,8 @@ void Tree::_go_right() {
if (selected_item->get_children() != NULL && selected_item->is_collapsed()) {
selected_item->set_collapsed(false);
} else if (selected_item->get_next_visible()) {
- selected_item->select(0);
+ selected_col = 0;
_go_down();
- return;
}
} else {
if (select_mode == SELECT_MULTI) {
@@ -2746,9 +2745,13 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventPanGesture> pan_gesture = p_event;
if (pan_gesture.is_valid()) {
- double prev_value = v_scroll->get_value();
+ double prev_v = v_scroll->get_value();
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
- if (v_scroll->get_value() != prev_value) {
+
+ double prev_h = h_scroll->get_value();
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
+
+ if (v_scroll->get_value() != prev_v || h_scroll->get_value() != prev_h) {
accept_event();
}
}
@@ -3427,7 +3430,10 @@ int Tree::get_item_offset(TreeItem *p_item) const {
if (it == p_item)
return ofs;
- ofs += compute_item_height(it) + cache.vseparation;
+ ofs += compute_item_height(it);
+ if (it != root || !hide_root) {
+ ofs += cache.vseparation;
+ }
if (it->children && !it->collapsed) {
@@ -3453,25 +3459,48 @@ int Tree::get_item_offset(TreeItem *p_item) const {
}
void Tree::ensure_cursor_is_visible() {
-
- if (!is_inside_tree())
+ if (!is_inside_tree()) {
return;
+ }
+ if (!selected_item || (selected_col == -1)) {
+ return; // Nothing under cursor.
+ }
- TreeItem *selected = get_selected();
- if (!selected)
- return;
- int ofs = get_item_offset(selected);
- if (ofs == -1)
- return;
- int h = compute_item_height(selected) + cache.vseparation;
- int screenh = get_size().height - h_scroll->get_combined_minimum_size().height;
-
- if (h > screenh) { //screen size is too small, maybe it was not resized yet.
- v_scroll->set_value(ofs);
- } else if (ofs + h > v_scroll->get_value() + screenh) {
- v_scroll->call_deferred("set_value", ofs - screenh + h);
- } else if (ofs < v_scroll->get_value()) {
- v_scroll->set_value(ofs);
+ const Size2 area_size = get_size() - cache.bg->get_minimum_size();
+
+ int y_offset = get_item_offset(selected_item);
+ if (y_offset != -1) {
+ const int tbh = _get_title_button_height();
+ y_offset -= tbh;
+
+ const int cell_h = compute_item_height(selected_item) + cache.vseparation;
+ const int screen_h = area_size.height - h_scroll->get_combined_minimum_size().height - tbh;
+
+ if (cell_h > screen_h) { // Screen size is too small, maybe it was not resized yet.
+ v_scroll->set_value(y_offset);
+ } else if (y_offset + cell_h > v_scroll->get_value() + screen_h) {
+ v_scroll->call_deferred("set_value", y_offset - screen_h + cell_h);
+ } else if (y_offset < v_scroll->get_value()) {
+ v_scroll->set_value(y_offset);
+ }
+ }
+
+ if (select_mode != SELECT_ROW) { // Cursor always at col 0 in this mode.
+ int x_offset = 0;
+ for (int i = 0; i < selected_col; i++) {
+ x_offset += get_column_width(i);
+ }
+
+ const int cell_w = get_column_width(selected_col);
+ const int screen_w = area_size.width - v_scroll->get_combined_minimum_size().width;
+
+ if (cell_w > screen_w) {
+ h_scroll->set_value(x_offset);
+ } else if (x_offset + cell_w > h_scroll->get_value() + screen_w) {
+ h_scroll->call_deferred("set_value", x_offset - screen_w + cell_w);
+ } else if (x_offset < h_scroll->get_value()) {
+ h_scroll->set_value(x_offset);
+ }
}
}