summaryrefslogtreecommitdiffstats
path: root/scene/gui/tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r--scene/gui/tree.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 46fcdcf7f6..7097fe0215 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -773,17 +773,21 @@ TreeItem *TreeItem::create_child(int p_index) {
TreeItem *item_prev = nullptr;
TreeItem *item_next = first_child;
- int idx = 0;
- while (item_next) {
- if (idx == p_index) {
- item_next->prev = ti;
- ti->next = item_next;
- break;
- }
+ if (p_index < 0 && last_child) {
+ item_prev = last_child;
+ } else {
+ int idx = 0;
+ while (item_next) {
+ if (idx == p_index) {
+ item_next->prev = ti;
+ ti->next = item_next;
+ break;
+ }
- item_prev = item_next;
- item_next = item_next->next;
- idx++;
+ item_prev = item_next;
+ item_next = item_next->next;
+ idx++;
+ }
}
if (item_prev) {
@@ -804,6 +808,10 @@ TreeItem *TreeItem::create_child(int p_index) {
}
}
+ if (item_prev == last_child) {
+ last_child = ti;
+ }
+
ti->parent = this;
ti->parent_visible_in_tree = is_visible_in_tree();
@@ -820,17 +828,13 @@ void TreeItem::add_child(TreeItem *p_item) {
p_item->parent_visible_in_tree = is_visible_in_tree();
p_item->_handle_visibility_changed(p_item->parent_visible_in_tree);
- TreeItem *item_prev = first_child;
- while (item_prev && item_prev->next) {
- item_prev = item_prev->next;
- }
-
- if (item_prev) {
- item_prev->next = p_item;
- p_item->prev = item_prev;
+ if (last_child) {
+ last_child->next = p_item;
+ p_item->prev = last_child;
} else {
first_child = p_item;
}
+ last_child = p_item;
if (!children_cache.is_empty()) {
children_cache.append(p_item);
@@ -910,13 +914,8 @@ TreeItem *TreeItem::_get_prev_in_tree(bool p_wrap, bool p_include_invisible) {
}
} else {
current = prev_item;
- while ((!current->collapsed || p_include_invisible) && current->first_child) {
- //go to the very end
-
- current = current->first_child;
- while (current->next) {
- current = current->next;
- }
+ while ((!current->collapsed || p_include_invisible) && current->last_child) {
+ current = current->last_child;
}
}
@@ -1037,6 +1036,8 @@ void TreeItem::clear_children() {
}
first_child = nullptr;
+ last_child = nullptr;
+ children_cache.clear();
};
int TreeItem::get_index() {
@@ -1141,6 +1142,7 @@ void TreeItem::move_after(TreeItem *p_item) {
if (next) {
parent->children_cache.clear();
} else {
+ parent->last_child = this;
// If the cache is empty, it has not been built but there
// are items in the tree (note p_item != nullptr,) so we cannot update it.
if (!parent->children_cache.is_empty()) {
@@ -3272,12 +3274,10 @@ void Tree::value_editor_changed(double p_value) {
return;
}
- TreeItem::Cell &c = popup_edited_item->cells.write[popup_edited_item_col];
- c.val = p_value;
+ const TreeItem::Cell &c = popup_edited_item->cells[popup_edited_item_col];
- line_editor->set_text(String::num(c.val, Math::range_step_decimals(c.step)));
+ line_editor->set_text(String::num(p_value, Math::range_step_decimals(c.step)));
- item_edited(popup_edited_item_col, popup_edited_item);
queue_redraw();
}
@@ -4468,15 +4468,8 @@ TreeItem *Tree::get_root() const {
TreeItem *Tree::get_last_item() const {
TreeItem *last = root;
-
- while (last) {
- if (last->next) {
- last = last->next;
- } else if (last->first_child && !last->collapsed) {
- last = last->first_child;
- } else {
- break;
- }
+ while (last && last->last_child && !last->collapsed) {
+ last = last->last_child;
}
return last;
@@ -4495,9 +4488,16 @@ void Tree::item_edited(int p_column, TreeItem *p_item, MouseButton p_custom_mous
}
void Tree::item_changed(int p_column, TreeItem *p_item) {
- if (p_item != nullptr && p_column >= 0 && p_column < p_item->cells.size()) {
- p_item->cells.write[p_column].dirty = true;
- columns.write[p_column].cached_minimum_width_dirty = true;
+ if (p_item != nullptr) {
+ if (p_column >= 0 && p_column < p_item->cells.size()) {
+ p_item->cells.write[p_column].dirty = true;
+ columns.write[p_column].cached_minimum_width_dirty = true;
+ } else if (p_column == -1) {
+ for (int i = 0; i < p_item->cells.size(); i++) {
+ p_item->cells.write[i].dirty = true;
+ columns.write[i].cached_minimum_width_dirty = true;
+ }
+ }
}
queue_redraw();
}