From bab2f3c0215f2e3a437a3759c7211b0a7de6d39a Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Wed, 13 Apr 2022 23:46:35 -0300 Subject: [PATCH] Add `font_separator` and related properties to `PopupMenu` --- doc/classes/PopupMenu.xml | 12 ++++++++++++ scene/gui/popup_menu.cpp | 15 ++++++++++----- scene/resources/default_theme/default_theme.cpp | 4 ++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index d849e22b56f..f8f16acb066 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -568,6 +568,9 @@ [Color] used for labeled separators' text. See [method add_separator]. + + The tint of text outline of the labeled separator. + The horizontal space between the item's elements. @@ -578,12 +581,21 @@ The size of the item text outline. + + The size of the labeled separator text outline. + The vertical space between each menu item. [Font] used for the menu items. + + [Font] used for the labeled separator. + + + Font size of the labeled separator. + Font size of the menu items. diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index d89c20ceaa9..ab496d058ce 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -635,23 +635,28 @@ void PopupMenu::_draw_items() { } } - // Text Color font_outline_color = get_theme_color(SNAME("font_outline_color")); int outline_size = get_theme_constant(SNAME("outline_size")); + + // Text if (items[i].separator) { + Color font_separator_outline_color = get_theme_color(SNAME("font_separator_outline_color")); + int separator_outline_size = get_theme_constant(SNAME("separator_outline_size")); + 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 + hseparation; } - if (outline_size > 0 && font_outline_color.a > 0) { - items[i].text_buf->draw_outline(ci, text_pos, outline_size, font_outline_color); + if (separator_outline_size > 0 && font_separator_outline_color.a > 0) { + items[i].text_buf->draw_outline(ci, text_pos, separator_outline_size, font_separator_outline_color); } items[i].text_buf->draw(ci, text_pos, font_separator_color); } } else { item_ofs.x += icon_ofs + check_ofs; + if (rtl) { Vector2 text_pos = Size2(control->get_size().width - items[i].text_buf->get_size().width - item_ofs.x, item_ofs.y) + Point2(0, Math::floor((h - items[i].text_buf->get_size().y) / 2.0)); if (outline_size > 0 && font_outline_color.a > 0) { @@ -724,8 +729,8 @@ void PopupMenu::_shape_item(int p_item) { if (items.write[p_item].dirty) { items.write[p_item].text_buf->clear(); - Ref font = get_theme_font(SNAME("font")); - int font_size = get_theme_font_size(SNAME("font_size")); + Ref font = get_theme_font(items[p_item].separator ? SNAME("font_separator") : SNAME("font")); + int font_size = get_theme_font_size(items[p_item].separator ? SNAME("font_separator_size") : SNAME("font_size")); if (items[p_item].text_direction == Control::TEXT_DIRECTION_INHERITED) { items.write[p_item].text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index eb71401a3ad..3ba6abd5233 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -653,7 +653,9 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_icon("submenu_mirrored", "PopupMenu", icons["arrow_left"]); theme->set_font("font", "PopupMenu", Ref()); + theme->set_font("font_separator", "PopupMenu", Ref()); theme->set_font_size("font_size", "PopupMenu", -1); + theme->set_font_size("font_separator_size", "PopupMenu", -1); theme->set_color("font_color", "PopupMenu", control_font_color); theme->set_color("font_accelerator_color", "PopupMenu", Color(0.7, 0.7, 0.7, 0.8)); @@ -661,10 +663,12 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_color("font_hover_color", "PopupMenu", control_font_color); theme->set_color("font_separator_color", "PopupMenu", control_font_color); theme->set_color("font_outline_color", "PopupMenu", Color(1, 1, 1)); + theme->set_color("font_separator_outline_color", "PopupMenu", Color(1, 1, 1)); theme->set_constant("hseparation", "PopupMenu", 4 * scale); theme->set_constant("vseparation", "PopupMenu", 4 * scale); theme->set_constant("outline_size", "PopupMenu", 0); + theme->set_constant("separator_outline_size", "PopupMenu", 0); theme->set_constant("item_start_padding", "PopupMenu", 2 * scale); theme->set_constant("item_end_padding", "PopupMenu", 2 * scale);