Skip to content

Commit

Permalink
Merge pull request #66445 from EricEzaM/GH-66442-shortcut-change-popu…
Browse files Browse the repository at this point in the history
…pmenu-update

Ensure popup menu redraws items when shortcuts update.
  • Loading branch information
akien-mga committed Sep 27, 2022
2 parents 43eac58 + af438ae commit 9237188
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scene/gui/popup_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/popup_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down

0 comments on commit 9237188

Please sign in to comment.