Skip to content

Commit

Permalink
Fix incorrect offset of PopupMenu separator icons
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSizov committed Oct 17, 2023
1 parent 30f2a6d commit ccb9895
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions scene/gui/popup_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,9 @@ void PopupMenu::_draw_items() {
// Separator
item_ofs.x += items[i].indent * theme_cache.indent;
if (items[i].separator) {
if (!text.is_empty() || !items[i].icon.is_null()) {
if (!text.is_empty() || items[i].icon.is_valid()) {
int content_size = items[i].text_buf->get_size().width + theme_cache.h_separation * 2;
if (!items[i].icon.is_null()) {
if (items[i].icon.is_valid()) {
content_size += icon_size.width + theme_cache.h_separation;
}

Expand Down Expand Up @@ -742,7 +742,9 @@ void PopupMenu::_draw_items() {
icon_color *= items[i].icon_modulate;

// For non-separator items, add some padding for the content.
item_ofs.x += theme_cache.item_start_padding;
if (!items[i].separator) {
item_ofs.x += theme_cache.item_start_padding;
}

// Checkboxes
if (items[i].checkable_type && !items[i].separator) {
Expand All @@ -758,7 +760,7 @@ void PopupMenu::_draw_items() {
int separator_ofs = (display_width - items[i].text_buf->get_size().width) / 2;

// Icon
if (!items[i].icon.is_null()) {
if (items[i].icon.is_valid()) {
const Point2 icon_offset = Point2(0, Math::floor((h - icon_size.height) / 2.0));
Point2 icon_pos;

Expand All @@ -769,6 +771,7 @@ void PopupMenu::_draw_items() {
icon_pos = Size2(control->get_size().width - item_ofs.x - separator_ofs - icon_size.width, item_ofs.y);
} else {
icon_pos = item_ofs + Size2(separator_ofs, 0);
separator_ofs += icon_size.width + theme_cache.h_separation;
}
} else {
if (rtl) {
Expand All @@ -794,9 +797,6 @@ void PopupMenu::_draw_items() {
if (items[i].separator) {
if (!text.is_empty()) {
Vector2 text_pos = Point2(separator_ofs, item_ofs.y + Math::floor((h - items[i].text_buf->get_size().y) / 2.0));
if (!rtl && !items[i].icon.is_null()) {
text_pos.x += icon_size.width + theme_cache.h_separation;
}

if (theme_cache.font_separator_outline_size > 0 && theme_cache.font_separator_outline_color.a > 0) {
items[i].text_buf->draw_outline(ci, text_pos, theme_cache.font_separator_outline_size, theme_cache.font_separator_outline_color);
Expand Down

0 comments on commit ccb9895

Please sign in to comment.