From adfc646f8cb497d520ea2238482ab674fe90d43a Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Sun, 27 Dec 2020 15:18:47 +0300 Subject: [PATCH] Added optional id parameter to `PopupMenu::add_separator` (cherry picked from commit ca8c794d0422f2e64a0afa0dab9b31a6589c7024) --- doc/classes/PopupMenu.xml | 4 +++- scene/gui/popup_menu.cpp | 6 +++--- scene/gui/popup_menu.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/classes/PopupMenu.xml b/doc/classes/PopupMenu.xml index 82b641c589d..bf9c4286d4d 100644 --- a/doc/classes/PopupMenu.xml +++ b/doc/classes/PopupMenu.xml @@ -203,8 +203,10 @@ + + - 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. diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index d368019a3f8..3fefaf8416e 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1216,11 +1216,11 @@ void PopupMenu::remove_item(int p_idx) { minimum_size_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); @@ -1484,7 +1484,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 9d0a2dd3334..2fc6a76b212 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -184,7 +184,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();