diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-27 09:53:52 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-27 09:53:52 +0200 |
commit | 92371880bd10041a6924e271147258ad47e81c4e (patch) | |
tree | 0fb35341a4b186579f3c18d25d42cd84901a8f18 | |
parent | 43eac58e314badb012162f7ad535603f463c89e5 (diff) | |
parent | af438ae74277beb63d1cea6fbdc5dcb737f7f3d6 (diff) |
Merge pull request #66445 from EricEzaM/GH-66442-shortcut-change-popupmenu-update
Ensure popup menu redraws items when shortcuts update.
-rw-r--r-- | scene/gui/popup_menu.cpp | 11 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index d4a4efd578..10e13042a7 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1762,7 +1762,7 @@ void PopupMenu::clear() { void PopupMenu::_ref_shortcut(Ref<Shortcut> p_sc) { if (!shortcut_refcount.has(p_sc)) { shortcut_refcount[p_sc] = 1; - p_sc->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw)); + p_sc->connect("changed", callable_mp(this, &PopupMenu::_shortcut_changed)); } else { shortcut_refcount[p_sc] += 1; } @@ -1772,11 +1772,18 @@ void PopupMenu::_unref_shortcut(Ref<Shortcut> p_sc) { ERR_FAIL_COND(!shortcut_refcount.has(p_sc)); shortcut_refcount[p_sc]--; if (shortcut_refcount[p_sc] == 0) { - p_sc->disconnect("changed", callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw)); + p_sc->disconnect("changed", callable_mp(this, &PopupMenu::_shortcut_changed)); shortcut_refcount.erase(p_sc); } } +void PopupMenu::_shortcut_changed() { + for (int i = 0; i < items.size(); i++) { + items.write[i].dirty = true; + } + control->queue_redraw(); +} + // Hide on item selection determines whether or not the popup will close after item selection void PopupMenu::set_hide_on_item_selection(bool p_enabled) { hide_on_item_selection = p_enabled; diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index ad7909842e..89d3904456 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -121,6 +121,8 @@ class PopupMenu : public Popup { void _ref_shortcut(Ref<Shortcut> p_sc); void _unref_shortcut(Ref<Shortcut> p_sc); + void _shortcut_changed(); + bool allow_search = true; uint64_t search_time_msec = 0; String search_string = ""; |