Added optional id parameter to `PopupMenu::add_separator`

This commit is contained in:
Yuri Roubinsky 2020-12-27 15:18:47 +03:00
parent d55e335026
commit ca8c794d04
3 changed files with 7 additions and 5 deletions

View File

@ -205,8 +205,10 @@
</return> </return>
<argument index="0" name="label" type="String" default="&quot;&quot;"> <argument index="0" name="label" type="String" default="&quot;&quot;">
</argument> </argument>
<argument index="1" name="id" type="int" default="-1">
</argument>
<description> <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. A [code]label[/code] can optionally be provided, which will appear at the center of the separator.
</description> </description>
</method> </method>

View File

@ -1349,10 +1349,10 @@ void PopupMenu::remove_item(int p_idx) {
child_controls_changed(); child_controls_changed();
} }
void PopupMenu::add_separator(const String &p_text) { void PopupMenu::add_separator(const String &p_text, int p_id) {
Item sep; Item sep;
sep.separator = true; sep.separator = true;
sep.id = -1; sep.id = p_id;
if (p_text != String()) { if (p_text != String()) {
sep.text = p_text; sep.text = p_text;
sep.xl_text = tr(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("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("clear"), &PopupMenu::clear);
ClassDB::bind_method(D_METHOD("_set_items"), &PopupMenu::_set_items); ClassDB::bind_method(D_METHOD("_set_items"), &PopupMenu::_set_items);

View File

@ -228,7 +228,7 @@ public:
void remove_item(int p_idx); 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(); void clear();