summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2020-12-29 17:39:44 +0100
committerGitHub <noreply@github.com>2020-12-29 17:39:44 +0100
commit3a9777cb3f2aa879281fcc8552dfc2619d3abb9b (patch)
tree6230ff072f35746a52cdaf38c038998f5db42c01
parentf62f64193a5ba54a5e0e74547d0cb0fb54b11258 (diff)
parentca8c794d0422f2e64a0afa0dab9b31a6589c7024 (diff)
Merge pull request #44724 from Chaosus/popup_separator
Added optional id parameter to `PopupMenu::add_separator`
-rw-r--r--doc/classes/PopupMenu.xml4
-rw-r--r--scene/gui/popup_menu.cpp6
-rw-r--r--scene/gui/popup_menu.h2
3 files changed, 7 insertions, 5 deletions
diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml
index 04798c04e9..2532af9a0c 100644
--- a/doc/classes/PopupMenu.xml
+++ b/doc/classes/PopupMenu.xml
@@ -205,8 +205,10 @@
</return>
<argument index="0" name="label" type="String" default="&quot;&quot;">
</argument>
+ <argument index="1" name="id" type="int" default="-1">
+ </argument>
<description>
- Adds a separator between items. Separators also occupy an index.
+ Adds a separator between items. Separators also occupy an index, which you can set by using the [code]id[/code] parameter.
A [code]label[/code] can optionally be provided, which will appear at the center of the separator.
</description>
</method>
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index e1a324efb3..4f95074fc6 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -1349,10 +1349,10 @@ void PopupMenu::remove_item(int p_idx) {
child_controls_changed();
}
-void PopupMenu::add_separator(const String &p_text) {
+void PopupMenu::add_separator(const String &p_text, int p_id) {
Item sep;
sep.separator = true;
- sep.id = -1;
+ sep.id = p_id;
if (p_text != String()) {
sep.text = p_text;
sep.xl_text = tr(p_text);
@@ -1600,7 +1600,7 @@ void PopupMenu::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_item", "idx"), &PopupMenu::remove_item);
- ClassDB::bind_method(D_METHOD("add_separator", "label"), &PopupMenu::add_separator, DEFVAL(String()));
+ ClassDB::bind_method(D_METHOD("add_separator", "label", "id"), &PopupMenu::add_separator, DEFVAL(String()), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("clear"), &PopupMenu::clear);
ClassDB::bind_method(D_METHOD("_set_items"), &PopupMenu::_set_items);
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index a082fcf0e7..5aa16b0ce3 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -228,7 +228,7 @@ public:
void remove_item(int p_idx);
- void add_separator(const String &p_text = String());
+ void add_separator(const String &p_text = String(), int p_id = -1);
void clear();