Permalink
Browse files

UI: Fix leak in control visibility screen.

  • Loading branch information...
unknownbrackets committed Jun 17, 2018
1 parent 0b0d4c1 commit c50f5cc3db2eb419ba0e2a01a2c5a2f865261952
Showing with 20 additions and 14 deletions.
  1. +20 −6 UI/TouchControlVisibilityScreen.cpp
  2. +0 −8 UI/TouchControlVisibilityScreen.h
@@ -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;
@@ -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);
@@ -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;
@@ -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.