From f14a38db52ee8af4729ebcc58c3dc5ddf058ff6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 28 May 2025 11:01:34 +0200 Subject: [PATCH] Remove a few uses of std::bind --- Common/UI/View.h | 10 +++++----- UI/GameScreen.cpp | 39 +++++++++++++++++++-------------------- UI/GameScreen.h | 2 -- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/Common/UI/View.h b/Common/UI/View.h index f21d3c7d0b..dcdc5dce1c 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -266,16 +266,16 @@ public: // Call this from UI thread EventReturn Dispatch(EventParams &e); - // This is suggested for use in most cases. Autobinds, allowing for neat syntax. + // This is now the suggested default way to bind a handler - just used a lambda, and if necessary call other functions. + void Add(std::function func); + + // The old way of doing things. template - T *Handle(T *thiz, EventReturn (T::* theCallback)(EventParams &e)) { + T *Handle(T *thiz, EventReturn (T::* theCallback)(EventParams &)) { Add(std::bind(theCallback, thiz, std::placeholders::_1)); return thiz; } - // Sometimes you have an already-bound function<>, just use this then. - void Add(std::function func); - private: std::vector handlers_; DISALLOW_COPY_AND_ASSIGN(Event); diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 913191371d..3d25edc1ea 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -538,24 +538,23 @@ UI::EventReturn GameScreen::OnDeleteSaveData(UI::EventParams &e) { if (info->saveDataSize) { const bool trashAvailable = System_GetPropertyBool(SYSPROP_HAS_TRASH_BIN); auto di = GetI18NCategory(I18NCat::DIALOG); + Path gamePath = gamePath_; screenManager()->push( new PromptScreen(gamePath_, di->T("DeleteConfirmAll", "Do you really want to delete all\nyour save data for this game?"), trashAvailable ? di->T("Move to trash") : di->T("Delete"), di->T("Cancel"), - std::bind(&GameScreen::CallbackDeleteSaveData, this, std::placeholders::_1))); + [gamePath](bool yes) { + if (yes) { + std::shared_ptr info = g_gameInfoCache->GetInfo(NULL, gamePath, GameInfoFlags::PARAM_SFO); + info->DeleteAllSaveData(); + info->saveDataSize = 0; + info->installDataSize = 0; + } + })); } } RecreateViews(); return UI::EVENT_DONE; } -void GameScreen::CallbackDeleteSaveData(bool yes) { - if (yes) { - std::shared_ptr info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO); - info->DeleteAllSaveData(); - info->saveDataSize = 0; - info->installDataSize = 0; - } -} - UI::EventReturn GameScreen::OnDeleteGame(UI::EventParams &e) { std::shared_ptr info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO); if (info->Ready(GameInfoFlags::PARAM_SFO)) { @@ -564,22 +563,22 @@ UI::EventReturn GameScreen::OnDeleteGame(UI::EventParams &e) { prompt = di->T("DeleteConfirmGame", "Do you really want to delete this game\nfrom your device? You can't undo this."); prompt += "\n\n" + gamePath_.ToVisualString(g_Config.memStickDirectory.c_str()); const bool trashAvailable = System_GetPropertyBool(SYSPROP_HAS_TRASH_BIN); + Path gamePath = gamePath_; + ScreenManager *sm = screenManager(); screenManager()->push( new PromptScreen(gamePath_, prompt, trashAvailable ? di->T("Move to trash") : di->T("Delete"), di->T("Cancel"), - std::bind(&GameScreen::CallbackDeleteGame, this, std::placeholders::_1))); + [sm, gamePath](bool yes) { + if (yes) { + std::shared_ptr info = g_gameInfoCache->GetInfo(NULL, gamePath, GameInfoFlags::PARAM_SFO); + info->Delete(); + g_gameInfoCache->Clear(); + sm->switchScreen(new MainScreen()); + } + })); } return UI::EVENT_DONE; } -void GameScreen::CallbackDeleteGame(bool yes) { - if (yes) { - std::shared_ptr info = g_gameInfoCache->GetInfo(NULL, gamePath_, GameInfoFlags::PARAM_SFO); - info->Delete(); - g_gameInfoCache->Clear(); - screenManager()->switchScreen(new MainScreen()); - } -} - UI::EventReturn GameScreen::OnRemoveFromRecent(UI::EventParams &e) { g_recentFiles.Remove(gamePath_.ToString()); screenManager()->switchScreen(new MainScreen()); diff --git a/UI/GameScreen.h b/UI/GameScreen.h index 34042b6e8c..30c1ac1170 100644 --- a/UI/GameScreen.h +++ b/UI/GameScreen.h @@ -44,8 +44,6 @@ public: protected: void CreateViews() override; - void CallbackDeleteSaveData(bool yes); - void CallbackDeleteGame(bool yes); private: UI::Choice *AddOtherChoice(UI::Choice *choice);