diff --git a/Common/UI/View.h b/Common/UI/View.h index 54de1420aa..db321d1d39 100644 --- a/Common/UI/View.h +++ b/Common/UI/View.h @@ -899,7 +899,7 @@ protected: class CollapsibleHeader : public CheckBox { public: - CollapsibleHeader(bool *toggle, const std::string &text, LayoutParams *layoutParams = nullptr); + CollapsibleHeader(bool *open, const std::string &text, LayoutParams *layoutParams = nullptr); void Draw(UIContext &dc) override; void GetContentDimensionsBySpec(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert, float &w, float &h) const override; void GetContentDimensions(const UIContext &dc, float &w, float &h) const override; @@ -907,6 +907,9 @@ public: Point GetFocusPosition(FocusDirection dir) const override; void SetHasSubitems(bool hasSubItems) { hasSubItems_ = hasSubItems; } + void SetOpenPtr(bool *open) { + toggle_ = open; + } private: bool hasSubItems_ = true; }; diff --git a/Common/UI/ViewGroup.cpp b/Common/UI/ViewGroup.cpp index fbdb582a21..2b4f4ec5a1 100644 --- a/Common/UI/ViewGroup.cpp +++ b/Common/UI/ViewGroup.cpp @@ -1175,11 +1175,12 @@ StickyChoice *ChoiceStrip::Choice(int index) { } CollapsibleSection::CollapsibleSection(const std::string &title, LayoutParams *layoutParams) : LinearLayout(ORIENT_VERTICAL, layoutParams) { + open_ = &localOpen_; SetSpacing(0.0f); - heading_ = new CollapsibleHeader(&open_, title); - views_.push_back(heading_); - heading_->OnClick.Add([=](UI::EventParams &) { + header_ = new CollapsibleHeader(open_, title); + views_.push_back(header_); + header_->OnClick.Add([=](UI::EventParams &) { // Change the visibility of all children except the first one. // Later maybe try something more ambitious. UpdateVisibility(); @@ -1189,12 +1190,12 @@ CollapsibleSection::CollapsibleSection(const std::string &title, LayoutParams *l void CollapsibleSection::Update() { ViewGroup::Update(); - heading_->SetHasSubitems(views_.size() > 1); + header_->SetHasSubitems(views_.size() > 1); } void CollapsibleSection::UpdateVisibility() { for (size_t i = 1; i < views_.size(); i++) { - views_[i]->SetVisibility(open_ ? V_VISIBLE : V_GONE); + views_[i]->SetVisibility(*open_ ? V_VISIBLE : V_GONE); } } diff --git a/Common/UI/ViewGroup.h b/Common/UI/ViewGroup.h index dcca7242c6..76918c9ed7 100644 --- a/Common/UI/ViewGroup.h +++ b/Common/UI/ViewGroup.h @@ -332,14 +332,20 @@ public: void Update() override; void SetOpen(bool open) { + *open_ = open; + UpdateVisibility(); + } + void SetOpenPtr(bool *open) { + header_->SetOpenPtr(open); open_ = open; UpdateVisibility(); } private: void UpdateVisibility(); - bool open_ = true; - CollapsibleHeader *heading_; + bool localOpen_ = true; + bool *open_; + CollapsibleHeader *header_; }; } // namespace UI diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index cf4f75d8ff..e87b60e11d 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -280,22 +280,22 @@ void ControlMappingScreen::CreateViews() { struct Cat { const char *catName; int firstKey; - bool openByDefault; + bool *open; }; // Category name, first input from psp_button_names. static const Cat cats[] = { - {"Standard PSP controls", CTRL_UP, true}, - {"Control modifiers", VIRTKEY_ANALOG_ROTATE_CW, true}, - {"Emulator controls", VIRTKEY_FASTFORWARD, true}, - {"Extended PSP controls", VIRTKEY_AXIS_RIGHT_Y_MAX, false}, + {"Standard PSP controls", CTRL_UP, &categoryToggles_[0]}, + {"Control modifiers", VIRTKEY_ANALOG_ROTATE_CW, &categoryToggles_[1]}, + {"Emulator controls", VIRTKEY_FASTFORWARD, &categoryToggles_[2]}, + {"Extended PSP controls", VIRTKEY_AXIS_RIGHT_Y_MAX, &categoryToggles_[3]}, }; int curCat = -1; CollapsibleSection *curSection = nullptr; for (size_t i = 0; i < numMappableKeys; i++) { if (curCat < (int)ARRAY_SIZE(cats) && mappableKeys[i].key == cats[curCat + 1].firstKey) { - if (curCat >= 0 && !cats[curCat].openByDefault) { - curSection->SetOpen(false); + if (curCat >= 0) { + curSection->SetOpenPtr(cats[curCat].open); } curCat++; curSection = rightColumn->Add(new CollapsibleSection(km->T(cats[curCat].catName))); @@ -307,8 +307,8 @@ void ControlMappingScreen::CreateViews() { mapper->SetTag(StringFromFormat("KeyMap%s", mappableKeys[i].name)); mappers_.push_back(mapper); } - if (curCat >= 0 && curSection && !cats[curCat].openByDefault) { - curSection->SetOpen(false); + if (curCat >= 0 && curSection) { + curSection->SetOpenPtr(cats[curCat].open); } keyMapGeneration_ = KeyMap::g_controllerMapGeneration; diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index fb70f5cc6e..23607d9d36 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -39,6 +39,8 @@ public: explicit ControlMappingScreen(const Path &gamePath) : UIDialogScreenWithGameBackground(gamePath) { categoryToggles_[0] = true; categoryToggles_[1] = true; + categoryToggles_[2] = true; + categoryToggles_[3] = false; } const char *tag() const override { return "ControlMapping"; }