diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index ef0e0bbce8..172b357273 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -288,7 +288,7 @@ UI::EventReturn PopupScreen::OnCancel(UI::EventParams &e) { void ListPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; - listView_ = parent->Add(new ListView(&adaptor_)); //, new LinearLayoutParams(1.0))); + listView_ = parent->Add(new ListView(&adaptor_, hidden_)); //, new LinearLayoutParams(1.0))); listView_->SetMaxHeight(screenManager()->getUIContext()->GetBounds().h - 140); listView_->OnChoice.Handle(this, &ListPopupScreen::OnListChoice); } @@ -315,8 +315,9 @@ UI::EventReturn PopupMultiChoice::HandleClick(UI::EventParams &e) { choices.push_back(category ? category->T(choices_[i]) : choices_[i]); } - Screen *popupScreen = new ListPopupScreen(text_, choices, *value_ - minVal_, + ListPopupScreen *popupScreen = new ListPopupScreen(text_, choices, *value_ - minVal_, std::bind(&PopupMultiChoice::ChoiceCallback, this, placeholder::_1)); + popupScreen->SetHiddenChoices(hidden_); screenManager_->push(popupScreen); return UI::EVENT_DONE; } diff --git a/ext/native/ui/ui_screen.h b/ext/native/ui/ui_screen.h index 6ac9730176..63397e854e 100644 --- a/ext/native/ui/ui_screen.h +++ b/ext/native/ui/ui_screen.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "ui/screen.h" #include "ui/viewgroup.h" @@ -93,9 +95,13 @@ public: std::string GetChoiceString() const { return adaptor_.GetTitle(listView_->GetSelected()); } - UI::Event OnChoice; + void SetHiddenChoices(std::set hidden) { + hidden_ = hidden; + } virtual std::string tag() const override { return std::string("listpopup"); } + UI::Event OnChoice; + protected: virtual bool FillVertical() const override { return false; } virtual bool ShowButtons() const override { return showButtons_; } @@ -108,6 +114,7 @@ private: std::function callback_; bool showButtons_; + std::set hidden_; }; class MessagePopupScreen : public PopupScreen { @@ -215,6 +222,10 @@ public: virtual void Draw(UIContext &dc) override; virtual void Update(const InputState &input_state) override; + void HideChoice(int c) { + hidden_.insert(c); + } + UI::Event OnChoice; private: @@ -231,6 +242,7 @@ private: ScreenManager *screenManager_; std::string valueText_; bool restoreFocus_; + std::set hidden_; }; diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index 2254757653..9a5fbc2af8 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -1258,9 +1258,8 @@ StickyChoice *ChoiceStrip::Choice(int index) { return static_cast(views_[index]); return nullptr; } - -ListView::ListView(ListAdaptor *a, LayoutParams *layoutParams) - : ScrollView(ORIENT_VERTICAL, layoutParams), adaptor_(a), maxHeight_(0) { +ListView::ListView(ListAdaptor *a, std::set hidden, LayoutParams *layoutParams) + : ScrollView(ORIENT_VERTICAL, layoutParams), adaptor_(a), maxHeight_(0), hidden_(hidden) { linLayout_ = new LinearLayout(ORIENT_VERTICAL); linLayout_->SetSpacing(0.0f); @@ -1272,8 +1271,10 @@ void ListView::CreateAllItems() { linLayout_->Clear(); // Let's not be clever yet, we'll just create them all up front and add them all in. for (int i = 0; i < adaptor_->GetNumItems(); i++) { - View * v = linLayout_->Add(adaptor_->CreateItemView(i)); - adaptor_->AddEventCallback(v, std::bind(&ListView::OnItemCallback, this, i, placeholder::_1)); + if (hidden_.find(i) == hidden_.end()) { + View * v = linLayout_->Add(adaptor_->CreateItemView(i)); + adaptor_->AddEventCallback(v, std::bind(&ListView::OnItemCallback, this, i, placeholder::_1)); + } } } diff --git a/ext/native/ui/viewgroup.h b/ext/native/ui/viewgroup.h index c1d150cda5..98f7868730 100644 --- a/ext/native/ui/viewgroup.h +++ b/ext/native/ui/viewgroup.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "base/logging.h" #include "base/mutex.h" @@ -389,7 +390,7 @@ private: // In the future, it might be smart and load/unload items as they go, but currently not. class ListView : public ScrollView { public: - ListView(ListAdaptor *a, LayoutParams *layoutParams = 0); + ListView(ListAdaptor *a, std::set hidden = std::set(), LayoutParams *layoutParams = 0); int GetSelected() { return adaptor_->GetSelected(); } virtual void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override; @@ -403,6 +404,7 @@ private: ListAdaptor *adaptor_; LinearLayout *linLayout_; float maxHeight_; + std::set hidden_; }; void LayoutViewHierarchy(const UIContext &dc, ViewGroup *root);