فهرست منبع

Merge pull request #60891 from YeldhamDev/pm_sep_font

Rémi Verschelde 3 سال پیش
والد
کامیت
20c72e8275
3فایلهای تغییر یافته به همراه22 افزوده شده و 11 حذف شده
  1. 3 0
      doc/classes/PopupMenu.xml
  2. 18 11
      scene/gui/popup_menu.cpp
  3. 1 0
      scene/resources/default_theme/default_theme.cpp

+ 3 - 0
doc/classes/PopupMenu.xml

@@ -527,6 +527,9 @@
 		<theme_item name="font" data_type="font" type="Font">
 			[Font] used for the menu items.
 		</theme_item>
+		<theme_item name="font_separator" data_type="font" type="Font">
+			[Font] used for the labeled separator.
+		</theme_item>
 		<theme_item name="checked" data_type="icon" type="Texture">
 			[Texture] icon for the checked checkbox items.
 		</theme_item>

+ 18 - 11
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> font = get_font("font");
+	Ref<Font> 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> font = get_font("font");
+	Ref<Font> 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<StyleBox> style = get_stylebox("panel");
 			Ref<StyleBox> hover = get_stylebox("hover");
 			Ref<Font> font = get_font("font");
+			Ref<Font> font_separator = get_font("font_separator");
 			// In Item::checkable_type enum order (less the non-checkable member)
 			Ref<Texture> check[] = { get_icon("checked"), get_icon("radio_checked") };
 			Ref<Texture> 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));
 				}
 

+ 1 - 0
scene/resources/default_theme/default_theme.cpp

@@ -596,6 +596,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &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));