Skip to content

Commit 59c3d4e

Browse files
committed
Fix and tweak labeled separator in PopupMenu
1 parent 8fee889 commit 59c3d4e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

doc/classes/PopupMenu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@
569569
[Color] used for labeled separators' text. See [method add_separator].
570570
</theme_item>
571571
<theme_item name="hseparation" data_type="constant" type="int" default="4">
572-
The horizontal space between the item's name and the shortcut text/submenu arrow.
572+
The horizontal space between the item's elements.
573573
</theme_item>
574574
<theme_item name="item_end_padding" data_type="constant" type="int" default="2">
575575
</theme_item>

scene/gui/popup_menu.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,8 @@ void PopupMenu::_draw_items() {
564564
// Separator
565565
item_ofs.x += items[i].h_ofs;
566566
if (items[i].separator) {
567-
int sep_h = separator->get_center_size().height + separator->get_minimum_size().height;
568-
int sep_ofs = Math::floor((h - sep_h) / 2.0);
569567
if (!text.is_empty() || !items[i].icon.is_null()) {
570-
int content_size = items[i].text_buf->get_size().width;
568+
int content_size = items[i].text_buf->get_size().width + hseparation * 2;
571569
if (!items[i].icon.is_null()) {
572570
content_size += icon_size.width + hseparation;
573571
}
@@ -576,12 +574,18 @@ void PopupMenu::_draw_items() {
576574
int content_left = content_center - content_size / 2;
577575
int content_right = content_center + content_size / 2;
578576
if (content_left > item_ofs.x) {
577+
int sep_h = labeled_separator_left->get_center_size().height + labeled_separator_left->get_minimum_size().height;
578+
int sep_ofs = Math::floor((h - sep_h) / 2.0);
579579
labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(MAX(0, content_left - item_ofs.x), sep_h)));
580580
}
581581
if (content_right < display_width) {
582+
int sep_h = labeled_separator_right->get_center_size().height + labeled_separator_right->get_minimum_size().height;
583+
int sep_ofs = Math::floor((h - sep_h) / 2.0);
582584
labeled_separator_right->draw(ci, Rect2(Point2(content_right, item_ofs.y + sep_ofs), Size2(MAX(0, display_width - content_right), sep_h)));
583585
}
584586
} else {
587+
int sep_h = separator->get_center_size().height + separator->get_minimum_size().height;
588+
int sep_ofs = Math::floor((h - sep_h) / 2.0);
585589
separator->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(display_width, sep_h)));
586590
}
587591
}

0 commit comments

Comments
 (0)