summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-09-21 18:55:12 +0200
committerRémi Verschelde <rverschelde@gmail.com>2022-09-21 18:55:12 +0200
commit9f2748f63ceb19d4a7734819557a1607d2d4c348 (patch)
tree9df9582c8ca98a90c0c400f821eb3d1a2c290bb4 /scene
parentb770fa2791f1aeb3296ca91909dd316328582078 (diff)
parent4a0e03cea56f3c4a8f413148c0261464baf8e95e (diff)
Merge pull request #66213 from KoBeWi/not_right_but_works™
Remove duplicate code in ItemList
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/item_list.cpp16
1 files changed, 2 insertions, 14 deletions
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 008109da65..357f2480bd 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -662,19 +662,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) {
pos.x = get_size().width - pos.x;
}
- int closest = -1;
-
- for (int i = 0; i < items.size(); i++) {
- Rect2 rc = items[i].rect_cache;
- if (i % current_columns == current_columns - 1) {
- rc.size.width = get_size().width; //not right but works
- }
-
- if (rc.has_point(pos)) {
- closest = i;
- break;
- }
- }
+ int closest = get_item_at_position(mb->get_position(), true);
if (closest != -1 && (mb->get_button_index() == MouseButton::LEFT || (allow_rmb_select && mb->get_button_index() == MouseButton::RIGHT))) {
int i = closest;
@@ -1467,7 +1455,7 @@ int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const {
for (int i = 0; i < items.size(); i++) {
Rect2 rc = items[i].rect_cache;
if (i % current_columns == current_columns - 1) {
- rc.size.width = get_size().width - rc.position.x; //make sure you can still select the last item when clicking past the column
+ rc.size.width = get_size().width - rc.position.x; // Make sure you can still select the last item when clicking past the column.
}
if (rc.has_point(pos)) {