diff options
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r-- | scene/gui/tree.cpp | 426 |
1 files changed, 279 insertions, 147 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index df4420ca8c..45fcb448f8 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -47,8 +47,9 @@ #include <limits.h> void TreeItem::move_to_top() { - if (!parent || parent->children == this) + if (!parent || parent->children == this) { return; //already on top + } TreeItem *prev = get_prev(); prev->next = next; next = parent->children; @@ -56,13 +57,15 @@ void TreeItem::move_to_top() { } void TreeItem::move_to_bottom() { - if (!parent || !next) + if (!parent || !next) { return; + } TreeItem *prev = get_prev(); TreeItem *last = next; - while (last->next) + while (last->next) { last = last->next; + } if (prev) { prev->next = next; @@ -74,17 +77,20 @@ void TreeItem::move_to_bottom() { } Size2 TreeItem::Cell::get_icon_size() const { - if (icon.is_null()) + if (icon.is_null()) { return Size2(); - if (icon_region == Rect2i()) + } + if (icon_region == Rect2i()) { return icon->get_size(); - else + } else { return icon_region.size; + } } void TreeItem::Cell::draw_icon(const RID &p_where, const Point2 &p_pos, const Size2 &p_size, const Color &p_color) const { - if (icon.is_null()) + if (icon.is_null()) { return; + } Size2i dsize = (p_size == Size2()) ? icon->get_size() : p_size; @@ -229,12 +235,15 @@ int TreeItem::get_icon_max_width(int p_column) const { /* range works for mode number or mode combo */ void TreeItem::set_range(int p_column, double p_value) { ERR_FAIL_INDEX(p_column, cells.size()); - if (cells[p_column].step > 0) + if (cells[p_column].step > 0) { p_value = Math::stepify(p_value, cells[p_column].step); - if (p_value < cells[p_column].min) + } + if (p_value < cells[p_column].min) { p_value = cells[p_column].min; - if (p_value > cells[p_column].max) + } + if (p_value > cells[p_column].max) { p_value = cells[p_column].max; + } cells.write[p_column].val = p_value; _changed_notify(p_column); @@ -286,8 +295,9 @@ void TreeItem::set_custom_draw(int p_column, Object *p_object, const StringName } void TreeItem::set_collapsed(bool p_collapsed) { - if (collapsed == p_collapsed || !tree) + if (collapsed == p_collapsed || !tree) { return; + } collapsed = p_collapsed; TreeItem *ci = tree->selected_item; if (ci) { @@ -329,12 +339,14 @@ TreeItem *TreeItem::get_next() { } TreeItem *TreeItem::get_prev() { - if (!parent || parent->children == this) + if (!parent || parent->children == this) { return nullptr; + } TreeItem *prev = parent->children; - while (prev && prev->next != this) + while (prev && prev->next != this) { prev = prev->next; + } return prev; } @@ -374,8 +386,9 @@ TreeItem *TreeItem::get_prev_visible(bool p_wrap) { //go to the very end current = current->children; - while (current->next) + while (current->next) { current = current->next; + } } } @@ -396,10 +409,11 @@ TreeItem *TreeItem::get_next_visible(bool p_wrap) { } if (!current) { - if (p_wrap) + if (p_wrap) { return tree->root; - else + } else { return nullptr; + } } else { current = current->next; } @@ -445,10 +459,12 @@ bool TreeItem::is_selected(int p_column) { void TreeItem::set_as_cursor(int p_column) { ERR_FAIL_INDEX(p_column, cells.size()); - if (!tree) + if (!tree) { return; - if (tree->select_mode != Tree::SELECT_MULTI) + } + if (tree->select_mode != Tree::SELECT_MULTI) { return; + } tree->selected_item = this; tree->selected_col = p_column; tree->update(); @@ -469,8 +485,9 @@ void TreeItem::add_button(int p_column, const Ref<Texture2D> &p_button, int p_id ERR_FAIL_COND(!p_button.is_valid()); TreeItem::Cell::Button button; button.texture = p_button; - if (p_id < 0) + if (p_id < 0) { p_id = cells[p_column].buttons.size(); + } button.id = p_id; button.disabled = p_disabled; button.tooltip = p_tooltip; @@ -511,8 +528,9 @@ void TreeItem::erase_button(int p_column, int p_idx) { int TreeItem::get_button_by_id(int p_column, int p_id) const { ERR_FAIL_INDEX_V(p_column, cells.size(), -1); for (int i = 0; i < cells[p_column].buttons.size(); i++) { - if (cells[p_column].buttons[i].id == p_id) + if (cells[p_column].buttons[i].id == p_id) { return i; + } } return -1; @@ -568,8 +586,9 @@ void TreeItem::set_custom_color(int p_column, const Color &p_color) { Color TreeItem::get_custom_color(int p_column) const { ERR_FAIL_INDEX_V(p_column, cells.size(), Color()); - if (!cells[p_column].custom_color) + if (!cells[p_column].custom_color) { return Color(); + } return cells[p_column].color; } @@ -607,8 +626,9 @@ void TreeItem::clear_custom_bg_color(int p_column) { Color TreeItem::get_custom_bg_color(int p_column) const { ERR_FAIL_INDEX_V(p_column, cells.size(), Color()); - if (!cells[p_column].custom_bg_color) + if (!cells[p_column].custom_bg_color) { return Color(); + } return cells[p_column].bg_color; } @@ -832,8 +852,9 @@ TreeItem::TreeItem(Tree *p_tree) { TreeItem::~TreeItem() { clear_children(); - if (parent) + if (parent) { parent->remove_child(this); + } if (tree && tree->root == this) { tree->root = nullptr; @@ -848,14 +869,17 @@ TreeItem::~TreeItem() { tree->cache.hover_item = nullptr; } - if (tree && tree->selected_item == this) + if (tree && tree->selected_item == this) { tree->selected_item = nullptr; + } - if (tree && tree->drop_mode_over == this) + if (tree && tree->drop_mode_over == this) { tree->drop_mode_over = nullptr; + } - if (tree && tree->single_select_defer == this) + if (tree && tree->single_select_defer == this) { tree->single_select_defer = nullptr; + } if (tree && tree->edited_item == this) { tree->edited_item = nullptr; @@ -915,8 +939,9 @@ void Tree::update_cache() { } int Tree::compute_item_height(TreeItem *p_item) const { - if (p_item == root && hide_root) + if (p_item == root && hide_root) { return 0; + } ERR_FAIL_COND_V(cache.font.is_null(), 0); int height = cache.font->get_height(); @@ -925,15 +950,17 @@ int Tree::compute_item_height(TreeItem *p_item) const { for (int j = 0; j < p_item->cells[i].buttons.size(); j++) { Size2i s; // = cache.button_pressed->get_minimum_size(); s += p_item->cells[i].buttons[j].texture->get_size(); - if (s.height > height) + if (s.height > height) { height = s.height; + } } switch (p_item->cells[i].mode) { case TreeItem::CELL_MODE_CHECK: { int check_icon_h = cache.checked->get_height(); - if (height < check_icon_h) + if (height < check_icon_h) { height = check_icon_h; + } [[fallthrough]]; } case TreeItem::CELL_MODE_STRING: @@ -945,8 +972,9 @@ int Tree::compute_item_height(TreeItem *p_item) const { if (p_item->cells[i].icon_max_w > 0 && s.width > p_item->cells[i].icon_max_w) { s.height = s.height * p_item->cells[i].icon_max_w / s.width; } - if (s.height > height) + if (s.height > height) { height = s.height; + } } if (p_item->cells[i].mode == TreeItem::CELL_MODE_CUSTOM && p_item->cells[i].custom_button) { height += cache.custom_button->get_minimum_size().height; @@ -958,8 +986,9 @@ int Tree::compute_item_height(TreeItem *p_item) const { } } int item_min_height = p_item->get_custom_minimum_height(); - if (height < item_min_height) + if (height < item_min_height) { height = item_min_height; + } height += cache.vseparation; @@ -990,8 +1019,9 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co Rect2i rect = p_rect; Ref<Font> font = cache.font; String text = p_cell.text; - if (p_cell.suffix != String()) + if (p_cell.suffix != String()) { text += " " + p_cell.suffix; + } int w = 0; if (!p_cell.icon.is_null()) { @@ -1034,8 +1064,9 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co } int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item) { - if (p_pos.y - cache.offset.y > (p_draw_size.height)) + if (p_pos.y - cache.offset.y > (p_draw_size.height)) { return -1; //draw no more! + } RID ci = get_canvas_item(); @@ -1094,8 +1125,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) { Ref<Texture2D> b = p_item->cells[i].buttons[j].texture; Size2 s = b->get_size() + cache.button_pressed->get_minimum_size(); - if (s.height < label_h) + if (s.height < label_h) { s.height = label_h; + } Point2i o = Point2i(ofs + w - s.width, p_pos.y) - cache.offset + p_draw_ofs; @@ -1128,10 +1160,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 Rect2i row_rect = Rect2i(Point2i(cache.bg->get_margin(MARGIN_LEFT), item_rect.position.y), Size2i(get_size().width - cache.bg->get_minimum_size().width, item_rect.size.y)); //Rect2 r = Rect2i(row_rect.pos,row_rect.size); //r.grow(cache.selected->get_margin(MARGIN_LEFT)); - if (has_focus()) + if (has_focus()) { cache.selected_focus->draw(ci, row_rect); - else + } else { cache.selected->draw(ci, row_rect); + } } } @@ -1224,8 +1257,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } break; case TreeItem::CELL_MODE_RANGE: { if (p_item->cells[i].text != "") { - if (!p_item->cells[i].editable) + if (!p_item->cells[i].editable) { break; + } int option = (int)p_item->cells[i].val; @@ -1242,8 +1276,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } } - if (p_item->cells[i].suffix != String()) + if (p_item->cells[i].suffix != String()) { s += " " + p_item->cells[i].suffix; + } Ref<Texture2D> downarrow = cache.select_arrow; @@ -1259,13 +1294,15 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step)); - if (p_item->cells[i].suffix != String()) + if (p_item->cells[i].suffix != String()) { valtext += " " + p_item->cells[i].suffix; + } font->draw(ci, text_pos, valtext, col, item_rect.size.x - updown->get_width()); - if (!p_item->cells[i].editable) + if (!p_item->cells[i].editable) { break; + } Point2i updown_pos = item_rect.position; updown_pos.x += item_rect.size.x - updown->get_width(); @@ -1276,8 +1313,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } break; case TreeItem::CELL_MODE_ICON: { - if (p_item->cells[i].icon.is_null()) + if (p_item->cells[i].icon.is_null()) { break; + } Size2i icon_size = p_item->cells[i].get_icon_size(); if (p_item->cells[i].icon_max_w > 0 && icon_size.width > p_item->cells[i].icon_max_w) { icon_size.height = icon_size.height * p_item->cells[i].icon_max_w / icon_size.width; @@ -1293,8 +1331,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 case TreeItem::CELL_MODE_CUSTOM: { if (p_item->cells[i].custom_draw_obj.is_valid()) { Object *cdo = ObjectDB::get_instance(p_item->cells[i].custom_draw_obj); - if (cdo) + if (cdo) { cdo->call(p_item->cells[i].custom_draw_callback, p_item, Rect2(item_rect)); + } } if (!p_item->cells[i].editable) { @@ -1340,10 +1379,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } if (select_mode == SELECT_MULTI && selected_item == p_item && selected_col == i) { - if (has_focus()) + if (has_focus()) { cache.cursor->draw(ci, cell_rect); - else + } else { cache.cursor_unfocus->draw(ci, cell_rect); + } } } @@ -1381,8 +1421,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs; - if (c->get_children() != nullptr) + if (c->get_children() != nullptr) { root_pos -= Point2i(cache.arrow->get_width(), 0); + } float line_width = 1.0; #ifdef TOOLS_ENABLED @@ -1428,8 +1469,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 int Tree::_count_selected_items(TreeItem *p_from) const { int count = 0; for (int i = 0; i < columns.size(); i++) { - if (p_from->is_selected(i)) + if (p_from->is_selected(i)) { count++; + } } if (p_from->get_children()) { @@ -1457,8 +1499,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c for (int i = 0; i < columns.size(); i++) { TreeItem::Cell &c = p_current->cells.write[i]; - if (!c.selectable) + if (!c.selectable) { continue; + } if (select_mode == SELECT_ROW) { if (p_selected == p_current && (!c.selected || allow_reselect)) { @@ -1487,10 +1530,11 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c selected_col = i; emit_signal("cell_selected"); - if (select_mode == SELECT_MULTI) + if (select_mode == SELECT_MULTI) { emit_signal("multi_selected", p_current, i, true); - else if (select_mode == SELECT_SINGLE) + } else if (select_mode == SELECT_SINGLE) { emit_signal("item_selected"); + } } else if (select_mode == SELECT_MULTI && (selected_item != p_selected || selected_col != i)) { selected_item = p_selected; @@ -1505,8 +1549,9 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c } } else if (!r_in_range || p_force_deselect) { - if (select_mode == SELECT_MULTI && c.selected) + if (select_mode == SELECT_MULTI && c.selected) { emit_signal("multi_selected", p_current, i, false); + } c.selected = false; } //p_current->deselected_signal.call(p_col); @@ -1558,8 +1603,9 @@ void Tree::_range_click_timeout() { range_click_timer->start(); } - if (!click_handled) + if (!click_handled) { range_click_timer->stop(); + } if (propagate_mouse_activated) { emit_signal("item_activated"); @@ -1584,8 +1630,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } if (!p_item->disable_folding && !hide_folding && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + cache.item_margin))) { - if (p_item->children) + if (p_item->children) { p_item->set_collapsed(!p_item->is_collapsed()); + } return -1; //handled! } @@ -1617,9 +1664,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool break; } - if (col == -1) + if (col == -1) { return -1; - else if (col == 0) { + } else if (col == 0) { int margin = x_ofs + cache.item_margin; //-cache.hseparation; //int lm = cache.bg->get_margin(MARGIN_LEFT); col_width -= margin; @@ -1726,8 +1773,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } } - if (!c.editable) + if (!c.editable) { return -1; // if cell is not editable, don't bother + } /* editing */ @@ -1813,8 +1861,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } else { editor_text = String::num(p_item->cells[col].val, Math::range_step_decimals(p_item->cells[col].step)); - if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) + if (select_mode == SELECT_MULTI && get_tree()->get_event_count() == focus_in_id) { bring_up_editor = false; + } } } click_handled = true; @@ -1842,8 +1891,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } break; }; - if (!bring_up_editor || p_button != BUTTON_LEFT) + if (!bring_up_editor || p_button != BUTTON_LEFT) { return -1; + } click_handled = true; popup_edited_item = p_item; @@ -1871,8 +1921,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool while (c) { int child_h = propagate_mouse_event(new_pos, x_ofs, y_ofs, p_doubleclick, c, p_button, p_mod); - if (child_h < 0) + if (child_h < 0) { return -1; // break, stop propagating, no need to anymore + } new_pos.y -= child_h; y_ofs += child_h; @@ -1895,8 +1946,9 @@ void Tree::_text_editor_modal_close() { return; } - if (value_editor->has_point(value_editor->get_local_mouse_position())) + if (value_editor->has_point(value_editor->get_local_mouse_position())) { return; + } _text_editor_enter(text_editor->get_text()); } @@ -1904,11 +1956,13 @@ void Tree::_text_editor_modal_close() { void Tree::_text_editor_enter(String p_text) { popup_editor->hide(); - if (!popup_edited_item) + if (!popup_edited_item) { return; + } - if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) + if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) { return; + } TreeItem::Cell &c = popup_edited_item->cells.write[popup_edited_item_col]; switch (c.mode) { @@ -1918,12 +1972,14 @@ void Tree::_text_editor_enter(String p_text) { } break; case TreeItem::CELL_MODE_RANGE: { c.val = p_text.to_double(); - if (c.step > 0) + if (c.step > 0) { c.val = Math::stepify(c.val, c.step); - if (c.val < c.min) + } + if (c.val < c.min) { c.val = c.min; - else if (c.val > c.max) + } else if (c.val > c.max) { c.val = c.max; + } //popup_edited_item->edited_signal.call( popup_edited_item_col ); } break; @@ -1951,11 +2007,13 @@ void Tree::value_editor_changed(double p_value) { } void Tree::popup_select(int p_option) { - if (!popup_edited_item) + if (!popup_edited_item) { return; + } - if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) + if (popup_edited_item_col < 0 || popup_edited_item_col > columns.size()) { return; + } popup_edited_item->cells.write[popup_edited_item_col].val = p_option; //popup_edited_item->edited_signal.call( popup_edited_item_col ); @@ -2031,17 +2089,20 @@ void Tree::_go_up() { } if (select_mode == SELECT_MULTI) { - if (!prev) + if (!prev) { return; + } selected_item = prev; emit_signal("cell_selected"); update(); } else { int col = selected_col < 0 ? 0 : selected_col; - while (prev && !prev->cells[col].selectable) + while (prev && !prev->cells[col].selectable) { prev = prev->get_prev_visible(); - if (!prev) + } + if (!prev) { return; // do nothing.. + } prev->select(col); } @@ -2080,8 +2141,9 @@ void Tree::_go_down() { } else { int col = selected_col < 0 ? 0 : selected_col; - while (next && !next->cells[col].selectable) + while (next && !next->cells[col].selectable) { next = next->get_next_visible(); + } if (!next) { return; // do nothing.. } @@ -2097,8 +2159,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { bool is_command = k.is_valid() && k->get_command(); if (p_event->is_action("ui_right") && p_event->is_pressed()) { - if (!cursor_can_exit_tree) + if (!cursor_can_exit_tree) { accept_event(); + } if (!selected_item || select_mode == SELECT_ROW || selected_col > (columns.size() - 1)) { return; @@ -2114,8 +2177,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { _go_right(); } } else if (p_event->is_action("ui_left") && p_event->is_pressed()) { - if (!cursor_can_exit_tree) + if (!cursor_can_exit_tree) { accept_event(); + } if (!selected_item || select_mode == SELECT_ROW || selected_col < 0) { return; @@ -2133,24 +2197,28 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } } else if (p_event->is_action("ui_up") && p_event->is_pressed() && !is_command) { - if (!cursor_can_exit_tree) + if (!cursor_can_exit_tree) { accept_event(); + } _go_up(); } else if (p_event->is_action("ui_down") && p_event->is_pressed() && !is_command) { - if (!cursor_can_exit_tree) + if (!cursor_can_exit_tree) { accept_event(); + } _go_down(); } else if (p_event->is_action("ui_page_down") && p_event->is_pressed()) { - if (!cursor_can_exit_tree) + if (!cursor_can_exit_tree) { accept_event(); + } TreeItem *next = nullptr; - if (!selected_item) + if (!selected_item) { return; + } next = selected_item; for (int i = 0; i < 10; i++) { @@ -2161,16 +2229,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { break; } } - if (next == selected_item) + if (next == selected_item) { return; + } if (select_mode == SELECT_MULTI) { selected_item = next; emit_signal("cell_selected"); update(); } else { - while (next && !next->cells[selected_col].selectable) + while (next && !next->cells[selected_col].selectable) { next = next->get_next_visible(); + } if (!next) { return; // do nothing.. } @@ -2179,12 +2249,14 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { ensure_cursor_is_visible(); } else if (p_event->is_action("ui_page_up") && p_event->is_pressed()) { - if (!cursor_can_exit_tree) + if (!cursor_can_exit_tree) { accept_event(); + } TreeItem *prev = nullptr; - if (!selected_item) + if (!selected_item) { return; + } prev = selected_item; for (int i = 0; i < 10; i++) { @@ -2195,16 +2267,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { break; } } - if (prev == selected_item) + if (prev == selected_item) { return; + } if (select_mode == SELECT_MULTI) { selected_item = prev; emit_signal("cell_selected"); update(); } else { - while (prev && !prev->cells[selected_col].selectable) + while (prev && !prev->cells[selected_col].selectable) { prev = prev->get_prev_visible(); + } if (!prev) { return; // do nothing.. } @@ -2222,8 +2296,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { accept_event(); } else if (p_event->is_action("ui_select") && p_event->is_pressed()) { if (select_mode == SELECT_MULTI) { - if (!selected_item) + if (!selected_item) { return; + } if (selected_item->is_selected(selected_col)) { selected_item->deselect(selected_col); emit_signal("multi_selected", selected_item, selected_col, false); @@ -2237,15 +2312,19 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (k.is_valid()) { // Incremental search - if (!k->is_pressed()) + if (!k->is_pressed()) { return; - if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey()) + } + if (k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey()) { return; - if (!root) + } + if (!root) { return; + } - if (hide_root && !root->get_next_visible()) + if (hide_root && !root->get_next_visible()) { return; + } if (k->get_unicode() > 0) { _do_incr_search(String::chr(k->get_unicode())); @@ -2253,16 +2332,18 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { return; } else { - if (k->get_keycode() != KEY_SHIFT) + if (k->get_keycode() != KEY_SHIFT) { last_keypress = 0; + } } } Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - if (cache.font.is_null()) // avoid a strange case that may corrupt stuff + if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff update_cache(); + } Ref<StyleBox> bg = cache.bg; @@ -2295,10 +2376,12 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { mpos -= cache.bg->get_offset(); mpos.y -= _get_title_button_height(); if (mpos.y >= 0) { - if (h_scroll->is_visible_in_tree()) + if (h_scroll->is_visible_in_tree()) { mpos.x += h_scroll->get_value(); - if (v_scroll->is_visible_in_tree()) + } + if (v_scroll->is_visible_in_tree()) { mpos.y += v_scroll->get_value(); + } int col, h, section; TreeItem *it = _find_item_at_pos(root, mpos, col, h, section); @@ -2362,8 +2445,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { Ref<InputEventMouseButton> b = p_event; if (b.is_valid()) { - if (cache.font.is_null()) // avoid a strange case that may corrupt stuff + if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff update_cache(); + } if (!b->is_pressed()) { if (b->get_button_index() == BUTTON_LEFT) { @@ -2434,8 +2518,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { return; } - if (range_drag_enabled) + if (range_drag_enabled) { return; + } switch (b->get_button_index()) { case BUTTON_RIGHT: @@ -2484,8 +2569,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { pressing_pos = b->get_position(); } - if (b->get_button_index() == BUTTON_RIGHT) + if (b->get_button_index() == BUTTON_RIGHT) { break; + } if (drag_touching) { set_physics_process_internal(false); @@ -2507,8 +2593,9 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } if (b->get_button_index() == BUTTON_LEFT) { - if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command()) + if (get_item_at_position(b->get_position()) == nullptr && !b->get_shift() && !b->get_control() && !b->get_command()) { emit_signal("nothing_selected"); + } } } @@ -2558,8 +2645,9 @@ bool Tree::edit_selected() { int col = get_selected_column(); ERR_FAIL_INDEX_V_MSG(col, columns.size(), false, "No item column selected."); - if (!s->cells[col].editable) + if (!s->cells[col].editable) { return false; + } Rect2 rect = s->get_meta("__focus_rect"); popup_edited_item = s; @@ -2636,8 +2724,9 @@ bool Tree::edit_selected() { Size2 Tree::get_internal_min_size() const { Size2i size = cache.bg->get_offset(); - if (root) + if (root) { size.height += get_item_height(root); + } for (int i = 0; i < columns.size(); i++) { size.width += columns[i].min_width; } @@ -2873,10 +2962,11 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { c = c->next; } - if (prev) + if (prev) { prev->next = ti; - else + } else { p_parent->children = ti; + } ti->parent = p_parent; } else { @@ -2904,12 +2994,13 @@ TreeItem *Tree::get_last_item() { TreeItem *last = root; while (last) { - if (last->next) + if (last->next) { last = last->next; - else if (last->children) + } else if (last->children) { last = last->children; - else + } else { break; + } } return last; @@ -2918,10 +3009,11 @@ TreeItem *Tree::get_last_item() { void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) { edited_item = p_item; edited_col = p_column; - if (p_lmb) + if (p_lmb) { emit_signal("item_edited"); - else + } else { emit_signal("item_rmb_edited"); + } } void Tree::item_changed(int p_column, TreeItem *p_item) { @@ -2930,8 +3022,9 @@ void Tree::item_changed(int p_column, TreeItem *p_item) { void Tree::item_selected(int p_column, TreeItem *p_item) { if (select_mode == SELECT_MULTI) { - if (!p_item->cells[p_column].selectable) + if (!p_item->cells[p_column].selectable) { return; + } p_item->cells.write[p_column].selected = true; //emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select @@ -3013,8 +3106,9 @@ bool Tree::is_root_hidden() const { void Tree::set_column_min_width(int p_column, int p_min_width) { ERR_FAIL_INDEX(p_column, columns.size()); - if (p_min_width < 1) + if (p_min_width < 1) { return; + } columns.write[p_column].min_width = p_min_width; update(); } @@ -3047,8 +3141,9 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { if (!p_item) return nullptr; */ - if (!root) + if (!root) { return nullptr; + } while (true) { if (!p_item) { @@ -3062,17 +3157,20 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { } else { while (!p_item->next) { p_item = p_item->parent; - if (p_item == nullptr) + if (p_item == nullptr) { return nullptr; + } } p_item = p_item->next; } } - for (int i = 0; i < columns.size(); i++) - if (p_item->cells[i].selected) + for (int i = 0; i < columns.size(); i++) { + if (p_item->cells[i].selected) { return p_item; + } + } } return nullptr; @@ -3081,15 +3179,17 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { int Tree::get_column_width(int p_column) const { ERR_FAIL_INDEX_V(p_column, columns.size(), -1); - if (!columns[p_column].expand) + if (!columns[p_column].expand) { return columns[p_column].min_width; + } Ref<StyleBox> bg = cache.bg; int expand_area = get_size().width - (bg->get_margin(MARGIN_LEFT) + bg->get_margin(MARGIN_RIGHT)); - if (v_scroll->is_visible_in_tree()) + if (v_scroll->is_visible_in_tree()) { expand_area -= v_scroll->get_combined_minimum_size().width; + } int expanding_columns = 0; int expanding_total = 0; @@ -3103,8 +3203,9 @@ int Tree::get_column_width(int p_column) const { } } - if (expand_area < expanding_total) + if (expand_area < expanding_total) { return columns[p_column].min_width; + } ERR_FAIL_COND_V(expanding_columns == 0, -1); // shouldn't happen @@ -3126,10 +3227,12 @@ void Tree::set_columns(int p_columns) { ERR_FAIL_COND(blocked > 0); columns.resize(p_columns); - if (root) + if (root) { propagate_set_columns(root); - if (selected_col >= p_columns) + } + if (selected_col >= p_columns) { selected_col = p_columns - 1; + } update(); } @@ -3148,12 +3251,14 @@ Rect2 Tree::get_custom_popup_rect() const { int Tree::get_item_offset(TreeItem *p_item) const { TreeItem *it = root; int ofs = _get_title_button_height(); - if (!it) + if (!it) { return 0; + } while (true) { - if (it == p_item) + if (it == p_item) { return ofs; + } ofs += compute_item_height(it); if (it != root || !hide_root) { @@ -3168,8 +3273,9 @@ int Tree::get_item_offset(TreeItem *p_item) const { } else { while (!it->next) { it = it->parent; - if (it == nullptr) + if (it == nullptr) { return 0; + } } it = it->next; @@ -3279,10 +3385,12 @@ String Tree::get_column_title(int p_column) const { Point2 Tree::get_scroll() const { Point2 ofs; - if (h_scroll->is_visible_in_tree()) + if (h_scroll->is_visible_in_tree()) { ofs.x = h_scroll->get_value(); - if (v_scroll->is_visible_in_tree()) + } + if (v_scroll->is_visible_in_tree()) { ofs.y = v_scroll->get_value(); + } return ofs; } @@ -3309,19 +3417,22 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c while (p_at) { for (int i = 0; i < columns.size(); i++) { if (p_at->get_text(i).findn(p_find) == 0 && (!p_selectable || p_at->is_selectable(i))) { - if (r_col) + if (r_col) { *r_col = i; + } return p_at; } } - if (p_backwards) + if (p_backwards) { p_at = p_at->get_prev_visible(true); - else + } else { p_at = p_at->get_next_visible(true); + } - if ((p_at) == from) + if ((p_at) == from) { break; + } } return nullptr; @@ -3330,10 +3441,12 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_selectable) { TreeItem *from = get_selected(); - if (!from) + if (!from) { from = root; - if (!from) + } + if (!from) { return nullptr; + } return _search_item_text(from->get_next_visible(true), p_find, r_col, p_selectable); } @@ -3352,16 +3465,18 @@ TreeItem *Tree::get_item_with_text(const String &p_find) const { void Tree::_do_incr_search(const String &p_add) { uint64_t time = OS::get_singleton()->get_ticks_usec() / 1000; // convert to msec uint64_t diff = time - last_keypress; - if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000))) + if (diff > uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000))) { incr_search = p_add; - else if (incr_search != p_add) + } else if (incr_search != p_add) { incr_search += p_add; + } last_keypress = time; int col; TreeItem *item = search_item_text(incr_search, &col, true); - if (!item) + if (!item) { return; + } item->select(col); ensure_cursor_is_visible(); @@ -3403,8 +3518,9 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_ h = 0; } - if (p_item->is_collapsed()) + if (p_item->is_collapsed()) { return nullptr; // do not try children, it's collapsed + } TreeItem *n = p_item->get_children(); while (n) { @@ -3412,8 +3528,9 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_ TreeItem *r = _find_item_at_pos(n, pos, r_column, ch, section); pos.y -= ch; h += ch; - if (r) + if (r) { return r; + } n = n->get_next(); } @@ -3425,13 +3542,16 @@ int Tree::get_column_at_position(const Point2 &p_pos) const { Point2 pos = p_pos; pos -= cache.bg->get_offset(); pos.y -= _get_title_button_height(); - if (pos.y < 0) + if (pos.y < 0) { return -1; + } - if (h_scroll->is_visible_in_tree()) + if (h_scroll->is_visible_in_tree()) { pos.x += h_scroll->get_value(); - if (v_scroll->is_visible_in_tree()) + } + if (v_scroll->is_visible_in_tree()) { pos.y += v_scroll->get_value(); + } int col, h, section; TreeItem *it = _find_item_at_pos(root, pos, col, h, section); @@ -3449,13 +3569,16 @@ int Tree::get_drop_section_at_position(const Point2 &p_pos) const { Point2 pos = p_pos; pos -= cache.bg->get_offset(); pos.y -= _get_title_button_height(); - if (pos.y < 0) + if (pos.y < 0) { return -100; + } - if (h_scroll->is_visible_in_tree()) + if (h_scroll->is_visible_in_tree()) { pos.x += h_scroll->get_value(); - if (v_scroll->is_visible_in_tree()) + } + if (v_scroll->is_visible_in_tree()) { pos.y += v_scroll->get_value(); + } int col, h, section; TreeItem *it = _find_item_at_pos(root, pos, col, h, section); @@ -3473,13 +3596,16 @@ TreeItem *Tree::get_item_at_position(const Point2 &p_pos) const { Point2 pos = p_pos; pos -= cache.bg->get_offset(); pos.y -= _get_title_button_height(); - if (pos.y < 0) + if (pos.y < 0) { return nullptr; + } - if (h_scroll->is_visible_in_tree()) + if (h_scroll->is_visible_in_tree()) { pos.x += h_scroll->get_value(); - if (v_scroll->is_visible_in_tree()) + } + if (v_scroll->is_visible_in_tree()) { pos.y += v_scroll->get_value(); + } int col, h, section; TreeItem *it = _find_item_at_pos(root, pos, col, h, section); @@ -3497,13 +3623,16 @@ String Tree::get_tooltip(const Point2 &p_pos) const { Point2 pos = p_pos; pos -= cache.bg->get_offset(); pos.y -= _get_title_button_height(); - if (pos.y < 0) + if (pos.y < 0) { return Control::get_tooltip(p_pos); + } - if (h_scroll->is_visible_in_tree()) + if (h_scroll->is_visible_in_tree()) { pos.x += h_scroll->get_value(); - if (v_scroll->is_visible_in_tree()) + } + if (v_scroll->is_visible_in_tree()) { pos.y += v_scroll->get_value(); + } int col, h, section; TreeItem *it = _find_item_at_pos(root, pos, col, h, section); @@ -3512,8 +3641,9 @@ String Tree::get_tooltip(const Point2 &p_pos) const { const TreeItem::Cell &c = it->cells[col]; int col_width = get_column_width(col); - for (int i = 0; i < col; i++) + for (int i = 0; i < col; i++) { pos.x -= get_column_width(i); + } for (int j = c.buttons.size() - 1; j >= 0; j--) { Ref<Texture2D> b = c.buttons[j].texture; @@ -3527,10 +3657,11 @@ String Tree::get_tooltip(const Point2 &p_pos) const { col_width -= size.width; } String ret; - if (it->get_tooltip(col) == "") + if (it->get_tooltip(col) == "") { ret = it->get_text(col); - else + } else { ret = it->get_tooltip(col); + } return ret; } } @@ -3556,8 +3687,9 @@ bool Tree::is_folding_hidden() const { } void Tree::set_drop_mode_flags(int p_flags) { - if (drop_mode_flags == p_flags) + if (drop_mode_flags == p_flags) { return; + } drop_mode_flags = p_flags; if (drop_mode_flags == 0) { drop_mode_over = nullptr; |