diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-01-04 13:30:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-04 13:30:37 +0100 |
commit | 8bfd96ee3f499035773b750f31e875cd3ef3b1fb (patch) | |
tree | 9fa2e8bd61c56c5fa38cec5c5a6492a061397d54 | |
parent | c5ff2cb3d9bca0478e3abce7540e3b831fa5ef37 (diff) | |
parent | e5aaa7d8909fb0d2814e503ed9939a784bf59211 (diff) |
Merge pull request #44905 from EricEzaM/PR/popup-menu-item-highlight-fix
Fixed hover highlight style rect of items being cut off.
-rw-r--r-- | scene/gui/popup_menu.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index ecb5ac0ffc..813a386474 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -72,9 +72,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const { } size.width += items[i].text_buf->get_size().x; - if (i > 0) { - size.height += vseparation; - } + size.height += vseparation; if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { int accel_w = hseparation * 2; @@ -152,9 +150,7 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { } for (int i = 0; i < items.size(); i++) { - if (i > 0) { - ofs.y += vseparation; - } + ofs.y += i > 0 ? vseparation : (float)vseparation / 2; ofs.y += MAX(items[i].get_icon_size().height, items[i].text_buf->get_size().y); @@ -506,10 +502,8 @@ void PopupMenu::_draw_items() { // Loop through all items and draw each. for (int i = 0; i < items.size(); i++) { - // If not the first item, add the separation space between items. - if (i > 0) { - ofs.y += vseparation; - } + // For the first item only add half a separation. For all other items, add a whole separation to the offset. + ofs.y += i > 0 ? vseparation : (float)vseparation / 2; _shape_item(i); @@ -519,9 +513,9 @@ void PopupMenu::_draw_items() { if (i == mouse_over) { if (rtl) { - hover->draw(ci, Rect2(item_ofs + Point2(-hseparation + scroll_width, -vseparation / 2), Size2(display_width + hseparation * 2, h + vseparation))); + hover->draw(ci, Rect2(item_ofs + Point2(scroll_width, -vseparation / 2), Size2(display_width, h + vseparation))); } else { - hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(display_width + hseparation * 2, h + vseparation))); + hover->draw(ci, Rect2(item_ofs + Point2(0, -vseparation / 2), Size2(display_width, h + vseparation))); } } |