From 5d4ac87b2b804c575140ff8b9acf888726ece44e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 9 Feb 2026 14:27:07 +0100 Subject: [PATCH] In PopupMultiChoice lists, indicate the selected item with a checkmark See #21223 --- Common/Input/GestureDetector.cpp | 1 + Common/UI/ScrollView.cpp | 54 ++++++++++++++++++-------------- Common/UI/ScrollView.h | 6 ++-- Common/UI/View.cpp | 2 +- Common/UI/View.h | 3 ++ UI/MiscViews.cpp | 1 + 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/Common/Input/GestureDetector.cpp b/Common/Input/GestureDetector.cpp index 08f4f8edcb..a8b4a0f23a 100644 --- a/Common/Input/GestureDetector.cpp +++ b/Common/Input/GestureDetector.cpp @@ -6,6 +6,7 @@ #include "Common/TimeUtil.h" #include "Common/Input/GestureDetector.h" +#include "Common/System/Display.h" const float estimatedInertiaDamping = 0.75f; diff --git a/Common/UI/ScrollView.cpp b/Common/UI/ScrollView.cpp index 16b1a08900..c567dcdcf6 100644 --- a/Common/UI/ScrollView.cpp +++ b/Common/UI/ScrollView.cpp @@ -572,17 +572,21 @@ 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++) { - if (hidden_.find(i) == hidden_.end()) { - ImageID *imageID = nullptr; - auto iter = icons_.find(i); - if (iter != icons_.end()) { - imageID = &iter->second; - } - View *v = linLayout_->Add(adaptor_->CreateItemView(i, imageID)); - adaptor_->AddEventCallback(v, [this, i](UI::EventParams &e) { - OnItemCallback(i, e); - }); + if (hidden_.count(i)) { + // Item was hidden, skip it. + continue; } + + ImageID *imageID = nullptr; + auto iter = icons_.find(i); + if (iter != icons_.end()) { + imageID = &iter->second; + } + const bool selected = adaptor_->GetSelected() == i; + View *v = linLayout_->Add(adaptor_->CreateItemView(i, selected, imageID)); + adaptor_->AddEventCallback(v, [this, i](UI::EventParams &e) { + OnItemCallback(i, e); + }); } } @@ -607,37 +611,39 @@ void ListView::OnItemCallback(int num, EventParams &e) { CreateAllItems(); } -View *ChoiceListAdaptor::CreateItemView(int index, ImageID *optionalImageID) { +View *ChoiceListAdaptor::CreateItemView(int index, bool selected, ImageID *optionalImageID) { Choice *choice; if (optionalImageID) { choice = new Choice(items_[index], *optionalImageID); } else { choice = new Choice(items_[index]); - //choice->SetIconRight(*optionalImageID); + } + if (selected) { + choice->SetSelectedIndicator(true); } return choice; } void ChoiceListAdaptor::AddEventCallback(View *view, std::function callback) { - Choice *choice = (Choice *)view; - choice->OnClick.Add(callback); + Clickable *choice = dynamic_cast(view); + if (choice) { + choice->OnClick.Add(callback); + } } -View *StringVectorListAdaptor::CreateItemView(int index, ImageID *optionalImageID) { - ImageID temp; - if (optionalImageID) { - temp = *optionalImageID; +View *StringVectorListAdaptor::CreateItemView(int index, bool selected, ImageID *optionalImageID) { + Choice *choice = new Choice(items_[index], optionalImageID ? *optionalImageID : ImageID()); + if (selected) { + choice->SetSelectedIndicator(true); } - Choice *choice = new Choice(items_[index], temp); - // if (optionalImageID) { - // choice->SetIconRight(*optionalImageID); - // } return choice; } void StringVectorListAdaptor::AddEventCallback(View *view, std::function callback) { - Choice *choice = (Choice *)view; - choice->OnClick.Add(callback); + Clickable *choice = dynamic_cast(view); + if (choice) { + choice->OnClick.Add(callback); + } } } // namespace diff --git a/Common/UI/ScrollView.h b/Common/UI/ScrollView.h index 72f4c453f7..9631dc9d4b 100644 --- a/Common/UI/ScrollView.h +++ b/Common/UI/ScrollView.h @@ -93,7 +93,7 @@ private: class ListAdaptor { public: virtual ~ListAdaptor() {} - virtual View *CreateItemView(int index, ImageID *optionalImageID) = 0; + virtual View *CreateItemView(int index, bool selected, ImageID *optionalImageID) = 0; virtual int GetNumItems() = 0; virtual void AddEventCallback(View *view, std::function callback) {} virtual std::string GetTitle(int index) const { return ""; } @@ -104,7 +104,7 @@ public: class ChoiceListAdaptor : public ListAdaptor { public: ChoiceListAdaptor(const char *items[], int numItems) : items_(items), numItems_(numItems) {} - View *CreateItemView(int index, ImageID *optionalImageID) override; + View *CreateItemView(int index, bool selected, ImageID *optionalImageID) override; int GetNumItems() override { return numItems_; } void AddEventCallback(View *view, std::function callback) override; @@ -118,7 +118,7 @@ class StringVectorListAdaptor : public ListAdaptor { public: StringVectorListAdaptor() : selected_(-1) {} StringVectorListAdaptor(const std::vector &items, int selected = -1) : items_(items), selected_(selected) {} - View *CreateItemView(int index, ImageID *optionalImageID) override; + View *CreateItemView(int index, bool selected, ImageID *optionalImageID) override; int GetNumItems() override { return (int)items_.size(); } void AddEventCallback(View *view, std::function callback) override; void SetSelected(int sel) override { selected_ = sel; } diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 889e8fa6d2..f9f6d483d6 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -568,7 +568,7 @@ void Choice::Draw(UIContext &dc) { } if (selected_) { - dc.Draw()->DrawImage(dc.GetTheme().checkOn, bounds_.x2() - 40, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); + dc.Draw()->DrawImage(ImageID("I_CHECKMARK"), bounds_.x2() - 30, bounds_.centerY(), 1.0f, style.fgColor, ALIGN_CENTER); } } diff --git a/Common/UI/View.h b/Common/UI/View.h index 706dab75f7..20b9578174 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -757,6 +757,9 @@ public: void SetIconOnly(bool iconOnly) { iconOnly_ = iconOnly; } + void SetSelectedIndicator(bool selected) { + selected_ = selected; + } protected: void ClickInternal() override; diff --git a/UI/MiscViews.cpp b/UI/MiscViews.cpp index 5703a7c083..c67fba3e70 100644 --- a/UI/MiscViews.cpp +++ b/UI/MiscViews.cpp @@ -171,6 +171,7 @@ void GameImageView::GetContentDimensions(const UIContext &dc, float &w, float &h w = 0; h = 0; if (!tex || !tex->texture) { + // Not ready yet return; } Draw::Texture *texture = tex->texture;