From cdc0e005579b11cbf8e3db7b0f647d74134312b4 Mon Sep 17 00:00:00 2001 From: Chia-Hsiang Cheng <88014292+garychia@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:32:58 +0800 Subject: [PATCH] Draw separators before selected style boxes (cherry picked from commit 749db002276d49c472fb48fab17aac72483f15ab) --- scene/gui/item_list.cpp | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index fab30b4a3c4..0f1dfaa4e00 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1077,6 +1077,32 @@ void ItemList::_notification(int p_what) { // Define a visible frame to check against and optimize drawing. const Rect2 clip(-base_ofs, size); + // Do a binary search to find the first separator that is below clip_position.y. + int first_visible_separator = 0; + { + int lo = 0; + int hi = separators.size(); + while (lo < hi) { + const int mid = (lo + hi) / 2; + if (separators[mid] < clip.position.y) { + lo = mid + 1; + } else { + hi = mid; + } + } + first_visible_separator = lo; + } + + // Draw visible separators. + for (int i = first_visible_separator; i < separators.size(); i++) { + if (separators[i] > clip.position.y + clip.size.y) { + break; // done + } + + const int y = base_ofs.y + separators[i]; + draw_line(Vector2(theme_cache.panel_style->get_margin(SIDE_LEFT), y), Vector2(width, y), theme_cache.guide_color); + } + // Do a binary search to find the first item whose rect reaches below clip.position.y. int first_item_visible; { @@ -1298,32 +1324,6 @@ void ItemList::_notification(int p_what) { draw_style_box(cursor, r); } } - - // Do a binary search to find the first separator that is below clip_position.y. - int first_visible_separator = 0; - { - int lo = 0; - int hi = separators.size(); - while (lo < hi) { - const int mid = (lo + hi) / 2; - if (separators[mid] < clip.position.y) { - lo = mid + 1; - } else { - hi = mid; - } - } - first_visible_separator = lo; - } - - // Draw visible separators. - for (int i = first_visible_separator; i < separators.size(); i++) { - if (separators[i] > clip.position.y + clip.size.y) { - break; // done - } - - const int y = base_ofs.y + separators[i]; - draw_line(Vector2(theme_cache.panel_style->get_margin(SIDE_LEFT), y), Vector2(width, y), theme_cache.guide_color); - } } break; } }