diff --git a/UI/TouchControlVisibilityScreen.cpp b/UI/TouchControlVisibilityScreen.cpp index 1d0e99e553..4e67d1cc5c 100644 --- a/UI/TouchControlVisibilityScreen.cpp +++ b/UI/TouchControlVisibilityScreen.cpp @@ -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; diff --git a/UI/TouchControlVisibilityScreen.h b/UI/TouchControlVisibilityScreen.h index e702a5f6aa..88455a343e 100644 --- a/UI/TouchControlVisibilityScreen.h +++ b/UI/TouchControlVisibilityScreen.h @@ -40,12 +40,4 @@ protected: private: std::vector toggles_; bool nextToggleAll_ = true; - - class ChoiceEventHandler{ - public: - ChoiceEventHandler(UI::CheckBox *checkbox) : checkbox_(checkbox) {} - UI::EventReturn onChoiceClick(UI::EventParams &e); - private: - UI::CheckBox *checkbox_; - }; };