Skip to content

Commit

Permalink
UI: Fix leak in control visibility screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Jun 23, 2018
1 parent 0b0d4c1 commit c50f5cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
26 changes: 20 additions & 6 deletions UI/TouchControlVisibilityScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@

static const int leftColumnWidth = 140;

class CheckBoxChoice : public UI::Choice {
public:
CheckBoxChoice(const std::string &text, UI::CheckBox *checkbox, UI::LayoutParams *lp)
: Choice(text, lp), checkbox_(checkbox) {
OnClick.Handle(this, &CheckBoxChoice::HandleClick);
}
CheckBoxChoice(ImageID imgID, UI::CheckBox *checkbox, UI::LayoutParams *lp)
: Choice(imgID, lp), checkbox_(checkbox) {
OnClick.Handle(this, &CheckBoxChoice::HandleClick);
}

private:
UI::EventReturn HandleClick(UI::EventParams &e);

UI::CheckBox *checkbox_;
};

void TouchControlVisibilityScreen::CreateViews() {
using namespace UI;

Expand Down Expand Up @@ -83,14 +100,11 @@ void TouchControlVisibilityScreen::CreateViews() {

Choice *choice;
if (toggle.img != -1) {
choice = new Choice(toggle.img, new LinearLayoutParams(1.0f));
choice = new CheckBoxChoice(toggle.img, checkbox, new LinearLayoutParams(1.0f));
} else {
choice = new Choice(mc->T(toggle.key), new LinearLayoutParams(1.0f));
choice = new CheckBoxChoice(mc->T(toggle.key), checkbox, new LinearLayoutParams(1.0f));
}

ChoiceEventHandler *choiceEventHandler = new ChoiceEventHandler(checkbox);
choice->OnClick.Handle(choiceEventHandler, &ChoiceEventHandler::onChoiceClick);

choice->SetCentered(true);

row->Add(choice);
Expand All @@ -111,7 +125,7 @@ UI::EventReturn TouchControlVisibilityScreen::OnToggleAll(UI::EventParams &e) {
return UI::EVENT_DONE;
}

UI::EventReturn TouchControlVisibilityScreen::ChoiceEventHandler::onChoiceClick(UI::EventParams &e){
UI::EventReturn CheckBoxChoice::HandleClick(UI::EventParams &e) {
checkbox_->Toggle();

return UI::EVENT_DONE;
Expand Down
8 changes: 0 additions & 8 deletions UI/TouchControlVisibilityScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,4 @@ class TouchControlVisibilityScreen : public UIDialogScreenWithBackground {
private:
std::vector<TouchButtonToggle> toggles_;
bool nextToggleAll_ = true;

class ChoiceEventHandler{
public:
ChoiceEventHandler(UI::CheckBox *checkbox) : checkbox_(checkbox) {}
UI::EventReturn onChoiceClick(UI::EventParams &e);
private:
UI::CheckBox *checkbox_;
};
};

0 comments on commit c50f5cc

Please sign in to comment.