diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-04-14 00:15:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-14 00:15:23 +0200 |
commit | 321213d863e7825d7e5a83902d108f4d6cb0b8fb (patch) | |
tree | 2622b2d3be7d8a15569669582c4ad08b816d47d2 | |
parent | c7922af4e5607cfa7b94c661dfd5a6aff60536ac (diff) | |
parent | 59c3d4e17f4474fb19fe58a422829a4f59ccde52 (diff) |
Merge pull request #60220 from YeldhamDev/the_line_must_be_drawn_here
Fix and tweak labeled separator in `PopupMenu`
-rw-r--r-- | doc/classes/PopupMenu.xml | 2 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index 4bcfc3c726..d849e22b56 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -569,7 +569,7 @@ [Color] used for labeled separators' text. See [method add_separator]. </theme_item> <theme_item name="hseparation" data_type="constant" type="int" default="4"> - The horizontal space between the item's name and the shortcut text/submenu arrow. + The horizontal space between the item's elements. </theme_item> <theme_item name="item_end_padding" data_type="constant" type="int" default="2"> </theme_item> diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index b01f45e9ab..d89c20ceaa 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -564,10 +564,8 @@ void PopupMenu::_draw_items() { // Separator item_ofs.x += items[i].h_ofs; if (items[i].separator) { - int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; - int sep_ofs = Math::floor((h - sep_h) / 2.0); if (!text.is_empty() || !items[i].icon.is_null()) { - int content_size = items[i].text_buf->get_size().width; + int content_size = items[i].text_buf->get_size().width + hseparation * 2; if (!items[i].icon.is_null()) { content_size += icon_size.width + hseparation; } @@ -576,12 +574,18 @@ void PopupMenu::_draw_items() { int content_left = content_center - content_size / 2; int content_right = content_center + content_size / 2; if (content_left > item_ofs.x) { + int sep_h = labeled_separator_left->get_center_size().height + labeled_separator_left->get_minimum_size().height; + int sep_ofs = Math::floor((h - sep_h) / 2.0); labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(MAX(0, content_left - item_ofs.x), sep_h))); } if (content_right < display_width) { + int sep_h = labeled_separator_right->get_center_size().height + labeled_separator_right->get_minimum_size().height; + int sep_ofs = Math::floor((h - sep_h) / 2.0); labeled_separator_right->draw(ci, Rect2(Point2(content_right, item_ofs.y + sep_ofs), Size2(MAX(0, display_width - content_right), sep_h))); } } else { + int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; + int sep_ofs = Math::floor((h - sep_h) / 2.0); separator->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(display_width, sep_h))); } } |