From 02f767fe0d8716a6745c13fd557a2564cbfd046f Mon Sep 17 00:00:00 2001
From: Pedro J. Estébanez
Date: Mon, 9 Apr 2018 19:55:24 +0200
Subject: Add support for radio-looking items with icon
Letting users of `PopupMenu` use them. `OptionButton` was one of those interested and is updated in this commit.
Fixes #18063.
(cherry picked from commit b964a9e678a969bdc28972c55655d7f0667d68b7)
---
doc/classes/PopupMenu.xml | 15 +++++++++++++++
scene/gui/option_button.cpp | 2 +-
scene/gui/popup_menu.cpp | 7 +++++++
scene/gui/popup_menu.h | 1 +
4 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml
index 8e7b37d47..f6b1423c7 100644
--- a/doc/classes/PopupMenu.xml
+++ b/doc/classes/PopupMenu.xml
@@ -77,6 +77,21 @@
created from the index. Note that checkable items just display a checkmark, but don't have any built-in checking behavior and must be checked/unchecked manually.
+
+
+
+
+
+
+
+
+
+
+
+
+ The same as [method add_icon_check_item] but the inserted item will look as a radio button. Remember this is just cosmetic and you have to add the logic for checking/unchecking items in radio groups.
+
+
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index f3c92b926..cef8cc8c0 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -108,7 +108,7 @@ void OptionButton::pressed() {
void OptionButton::add_icon_item(const Ref &p_icon, const String &p_label, int p_ID) {
- popup->add_icon_check_item(p_icon, p_label, p_ID);
+ popup->add_icon_radio_check_item(p_icon, p_label, p_ID);
if (popup->get_item_count() == 1)
select(0);
}
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 1ff045c31..1d73719cf 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -592,6 +592,13 @@ void PopupMenu::add_radio_check_item(const String &p_label, int p_ID, uint32_t p
update();
}
+void PopupMenu::add_icon_radio_check_item(const Ref &p_icon, const String &p_label, int p_ID, uint32_t p_accel) {
+
+ add_icon_check_item(p_icon, p_label, p_ID, p_accel);
+ items[items.size() - 1].checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON;
+ update();
+}
+
void PopupMenu::add_icon_shortcut(const Ref &p_icon, const Ref &p_shortcut, int p_ID, bool p_global) {
ERR_FAIL_COND(p_shortcut.is_null());
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index e541a431a..91af9ec27 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -120,6 +120,7 @@ public:
void add_icon_check_item(const Ref &p_icon, const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
void add_check_item(const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
void add_radio_check_item(const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
+ void add_icon_radio_check_item(const Ref &p_icon, const String &p_label, int p_ID = -1, uint32_t p_accel = 0);
void add_submenu_item(const String &p_label, const String &p_submenu, int p_ID = -1);
void add_icon_shortcut(const Ref &p_icon, const Ref &p_shortcut, int p_ID = -1, bool p_global = false);
--
cgit v1.3.1