mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-22 21:09:52 +00:00
Fix issue with the collapsible sections in control mapping collapsing on every change.
This commit is contained in:
parent
f02142c5c0
commit
c29f81da36
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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"; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user