diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/popup_menu.cpp | 11 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 072e90df3a..864fb3d3d5 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -696,6 +696,17 @@ String PopupMenu::get_item_text(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, items.size(), ""); return items[p_idx].text; } + +int PopupMenu::get_item_idx_from_text(const String &text) const { + + for (int idx = 0; idx < items.size(); idx++) { + if (items[idx].text == text) + return idx; + } + + return -1; +} + Ref<Texture> PopupMenu::get_item_icon(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture>()); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index a9bd8f7e50..6f1a2db363 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -132,6 +132,7 @@ public: void toggle_item_checked(int p_idx); String get_item_text(int p_idx) const; + int get_item_idx_from_text(const String &text) const; Ref<Texture> get_item_icon(int p_idx) const; bool is_item_checked(int p_idx) const; int get_item_ID(int p_idx) const; |