diff --git a/Common/UI/PopupScreens.cpp b/Common/UI/PopupScreens.cpp index 2535899b62..3578a3b138 100644 --- a/Common/UI/PopupScreens.cpp +++ b/Common/UI/PopupScreens.cpp @@ -332,12 +332,12 @@ void PopupCallbackScreen::CreatePopupContents(ViewGroup *parent) { AlignPopup(parent); } -std::string ChopTitle(const std::string &title) { +static std::string ChopTitle(std::string_view title) { size_t pos = title.find('\n'); if (pos != title.npos) { - return title.substr(0, pos); + return std::string(title.substr(0, pos)); } - return title; + return std::string(title); } PopupMultiChoice::PopupMultiChoice(int *value, std::string_view text, const char **choices, int minVal, int numChoices, @@ -785,6 +785,31 @@ void SliderFloatPopupScreen::OnCompleted(DialogResult result) { } } +// General utility, if you don't want to use a choice with a string. +void AskForInput(ScreenManager *screenManager, RequesterToken token, UI::View *sourceView, std::string_view title, std::function callback) { + // Choose method depending on platform capabilities. + if (System_GetPropertyBool(SYSPROP_HAS_TEXT_INPUT_DIALOG)) { + System_InputBoxGetString(token, title, "", false, [callback](const std::string &enteredValue, int) { + callback(SanitizeString(StripSpaces(enteredValue), StringRestriction::None, 0, 0), true); + }); + return; + } + + TextEditPopupScreen *popupScreen = new TextEditPopupScreen(nullptr, "", ChopTitle(title), -1); + if (System_GetPropertyBool(SYSPROP_KEYBOARD_IS_SOFT)) { + popupScreen->SetAlignTop(true); + } + popupScreen->OnChange.Add([callback, sourceView](EventParams &e) { + callback(SanitizeString(StripSpaces(*(std::string *)e.v), StringRestriction::None, 0, 0), true); + if (sourceView) { + SetFocusedView(sourceView); + } + }); + if (sourceView) + popupScreen->SetPopupOrigin(sourceView); + screenManager->push(popupScreen); +} + PopupTextInputChoice::PopupTextInputChoice(RequesterToken token, std::string *value, std::string_view title, std::string_view placeholder, int maxLen, ScreenManager *screenManager, LayoutParams *layoutParams) : AbstractChoiceWithValueDisplay(title, layoutParams), screenManager_(screenManager), value_(value), placeHolder_(placeholder), maxLen_(maxLen), token_(token), restriction_(StringRestriction::None) { OnClick.Handle(this, &PopupTextInputChoice::HandleClick); diff --git a/Common/UI/PopupScreens.h b/Common/UI/PopupScreens.h index 2491417c78..0afc183505 100644 --- a/Common/UI/PopupScreens.h +++ b/Common/UI/PopupScreens.h @@ -545,6 +545,8 @@ private: StringRestriction restriction_; }; +void AskForInput(ScreenManager *screenManager, RequesterToken token, UI::View *sourceView, std::string_view title, std::function callback); + class ChoiceWithValueDisplay : public AbstractChoiceWithValueDisplay { public: ChoiceWithValueDisplay(int *value, std::string_view text, LayoutParams *layoutParams = 0) diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index ed20114efa..a2ee50b74a 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -114,6 +114,17 @@ void CwCheatScreen::CreateSettingsViews(UI::ViewGroup *leftColumn) { leftColumn->Add(new Choice(mm->T("Browse"), ImageID("I_FOLDER_OPEN")))->OnClick.Handle(this, &CwCheatScreen::OnImportBrowse); leftColumn->Add(new ItemHeader(di->T("Options"))); + Choice *searchChoice = leftColumn->Add(new Choice(di->T("Search"), ImageID("I_SEARCH"))); + searchChoice->OnClick.Add([this, searchChoice, screenManager = screenManager(), token = GetRequesterToken()](UI::EventParams &) { + auto di = GetI18NCategory(I18NCat::DIALOG); + AskForInput(screenManager, token, searchChoice, di->T("Search"), [this](const std::string &text, bool success) { + if (!success) { + return; + } + search_.searchFilter = text; + search_.ApplySearchFilter(cheatList_, false); + }); + }); #if !defined(MOBILE_DEVICE) leftColumn->Add(new Choice(cw->T("Edit Cheat File")))->OnClick.Handle(this, &CwCheatScreen::OnEditCheatFile); #endif @@ -130,6 +141,10 @@ void CwCheatScreen::CreateContentViews(UI::ViewGroup *parent) { UI::LinearLayout *rightSide = parent->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 0.5f))); search_.searchFilter.clear(); search_.searchBar = rightSide->Add(new SearchBar(new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT))); + search_.searchBar->OnCancel.Add([this](UI::EventParams &) { + search_.searchFilter.clear(); + search_.ApplySearchFilter(cheatList_, false); + }); UI::ScrollView *rightScroll = rightSide->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT, 1.0f))); rightScroll->SetTag("CwCheats"); diff --git a/UI/GameBrowser.cpp b/UI/GameBrowser.cpp index 0026f5a1e3..d458edbe31 100644 --- a/UI/GameBrowser.cpp +++ b/UI/GameBrowser.cpp @@ -489,7 +489,7 @@ public: pinned_ = pin; } - std::string DescribeText() const { + std::string DescribeText() const override { return std::string(Button::GetText()); // From Button } diff --git a/UI/MiscViews.cpp b/UI/MiscViews.cpp index 06b388ce0f..9a35010780 100644 --- a/UI/MiscViews.cpp +++ b/UI/MiscViews.cpp @@ -427,8 +427,8 @@ void ViewSearch::ApplySearchFilter(UI::ViewGroup *viewGroup, bool setKeyboardFoc if (firstMatch) { if (setKeyboardFocus) { UI::EnableFocusMovement(true); + UI::SetFocusedView(firstMatch); } - UI::SetFocusedView(firstMatch); } }