diff options
author | crupest <crupest@outlook.com> | 2022-03-13 17:11:08 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-13 17:11:08 +0800 |
commit | 1d14ce416bb4e5651b956790b621308acf73b64c (patch) | |
tree | c7ef7d9af3afcb93d6c9168bef698b6794884877 /src/ui | |
parent | 8d24d87036e0208af24cf66bd31333445a4f813e (diff) | |
download | cru-1d14ce416bb4e5651b956790b621308acf73b64c.tar.gz cru-1d14ce416bb4e5651b956790b621308acf73b64c.tar.bz2 cru-1d14ce416bb4e5651b956790b621308acf73b64c.zip |
...
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/components/Menu.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/ui/components/Menu.cpp b/src/ui/components/Menu.cpp index 078c9f3f..471654ec 100644 --- a/src/ui/components/Menu.cpp +++ b/src/ui/components/Menu.cpp @@ -69,8 +69,9 @@ void Menu::AddTextItemAt(String text, gsl::index index, std::function<void()> on_click) { MenuItem* item = new MenuItem(std::move(text)); item->SetOnClick([this, index, on_click = std::move(on_click)] { + auto on_item_click = on_item_click_; on_click(); - if (on_item_click_) on_item_click_(index); + if (on_item_click) on_item_click(index); }); item->SetDeleteByParent(true); AddItemAt(item, index); @@ -78,7 +79,10 @@ void Menu::AddTextItemAt(String text, gsl::index index, PopupMenu::PopupMenu(controls::Control* attached_control) : attached_control_(attached_control), popup_(attached_control) { - menu_.SetOnItemClick([this](Index) { this->Close(); }); + menu_.SetOnItemClick([resolver = CreateResolver()](Index) { + auto t = static_cast<PopupMenu*>(resolver.Resolve()); + if (t) t->popup_.GetNativeWindow()->Close(); + }); popup_.AddChildAt(menu_.GetRootControl(), 0); } |