diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index e4bd967e54f..088b8b997b8 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -527,6 +527,9 @@ [Font] used for the menu items. + + [Font] used for the labeled separator. + [Texture] icon for the checked checkbox items. diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 280f1537103..f6bbf5c6153 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -52,15 +52,18 @@ Size2 PopupMenu::get_minimum_size() const { Size2 minsize = get_stylebox("panel")->get_minimum_size(); Ref font = get_font("font"); + Ref font_separator = get_font("font_separator"); float max_w = 0; float icon_w = 0; - int font_h = font->get_height(); int check_w = MAX(get_icon("checked")->get_width(), get_icon("radio_checked")->get_width()) + hseparation; int accel_max_w = 0; bool has_check = false; for (int i = 0; i < items.size(); i++) { + String text = items[i].xl_text; + int font_h = items[i].separator && text != String() ? font_separator->get_height() : font->get_height(); + Size2 size; if (!items[i].icon.is_null()) { Size2 icon_size = items[i].icon->get_size(); @@ -76,8 +79,7 @@ Size2 PopupMenu::get_minimum_size() const { has_check = true; } - String text = items[i].xl_text; - size.width += font->get_string_size(text).width; + size.width += items[i].separator ? font_separator->get_string_size(text).width : font->get_string_size(text).width; size.height += vseparation; if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { @@ -117,10 +119,13 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { } Ref font = get_font("font"); + Ref font_separator = get_font("font_separator"); int vseparation = get_constant("vseparation"); - float font_h = font->get_height(); for (int i = 0; i < items.size(); i++) { + String text = items[i].xl_text; + float font_h = items[i].separator && text != String() ? font_separator->get_height() : font->get_height(); + ofs.y += vseparation; float h; @@ -485,6 +490,7 @@ void PopupMenu::_notification(int p_what) { Ref style = get_stylebox("panel"); Ref hover = get_stylebox("hover"); Ref font = get_font("font"); + Ref font_separator = get_font("font_separator"); // In Item::checkable_type enum order (less the non-checkable member) Ref check[] = { get_icon("checked"), get_icon("radio_checked") }; Ref uncheck[] = { get_icon("unchecked"), get_icon("radio_unchecked") }; @@ -502,7 +508,6 @@ void PopupMenu::_notification(int p_what) { Color font_color_accel = get_color("font_color_accel"); Color font_color_hover = get_color("font_color_hover"); Color font_color_separator = get_color("font_color_separator"); - float font_h = font->get_height(); // Add the check and the wider icon to the offset of all items. float icon_ofs = 0.0; @@ -526,6 +531,9 @@ void PopupMenu::_notification(int p_what) { } for (int i = 0; i < items.size(); i++) { + String text = items[i].xl_text; + float font_h = items[i].separator && text != String() ? font_separator->get_height() : font->get_height(); + if (i == 0) { ofs.y += vseparation / 2; } else { @@ -546,12 +554,10 @@ void PopupMenu::_notification(int p_what) { hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation))); } - String text = items[i].xl_text; - item_ofs.x += items[i].h_ofs; if (items[i].separator) { if (text != String()) { - int ss = font->get_string_size(text).width / 2; + int ss = font_separator->get_string_size(text).width / 2; int center = get_size().width / 2; int l = center - ss; int r = center + ss; @@ -584,14 +590,15 @@ void PopupMenu::_notification(int p_what) { submenu->draw(ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(), item_ofs.y + Math::floor(h - submenu->get_height()) / 2), icon_color); } - item_ofs.y += font->get_ascent(); if (items[i].separator) { if (text != String()) { - int center = (get_size().width - font->get_string_size(text).width) / 2; - font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_separator); + item_ofs.y += font_separator->get_ascent(); + int center = (get_size().width - font_separator->get_string_size(text).width) / 2; + font_separator->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_separator); } } else { item_ofs.x += icon_ofs + check_ofs; + item_ofs.y += font->get_ascent(); font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color)); } diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 01617320f6d..3a13494c0fc 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -596,6 +596,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_icon("submenu", "PopupMenu", make_icon(submenu_png)); theme->set_font("font", "PopupMenu", default_font); + theme->set_font("font_separator", "PopupMenu", default_font); theme->set_color("font_color", "PopupMenu", control_font_color); theme->set_color("font_color_accel", "PopupMenu", Color(0.7, 0.7, 0.7, 0.8));