From e8d07b02c2072b159c83e074b68bcfdd8a872c2f Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Thu, 15 Aug 2013 22:13:57 +0200 Subject: [PATCH] Fix a potential crash bug with axis input. Remove ok/cancel buttons from popup lists. --- ui/ui_screen.cpp | 22 ++++++++++++---------- ui/ui_screen.h | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/ui/ui_screen.cpp b/ui/ui_screen.cpp index ec6bc3f468..766bf4175b 100644 --- a/ui/ui_screen.cpp +++ b/ui/ui_screen.cpp @@ -97,7 +97,9 @@ void UIScreen::axis(const AxisInput &axis) { if (released & PAD_BUTTON_UP) key(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_DPAD_UP, KEY_UP)); if (released & PAD_BUTTON_DOWN) key(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_DPAD_DOWN, KEY_UP)); hatDown_ = flags; - UI::AxisEvent(axis, root_); + if (root_) { + UI::AxisEvent(axis, root_); + } } @@ -127,11 +129,13 @@ void PopupScreen::CreateViews() { CreatePopupContents(box); - // And the two buttons at the bottom. - ViewGroup *buttonRow = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(200, WRAP_CONTENT)); - buttonRow->Add(new Button("OK", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK); - buttonRow->Add(new Button("Cancel", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel); - box->Add(buttonRow); + if (ShowButtons()) { + // And the two buttons at the bottom. + ViewGroup *buttonRow = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(200, WRAP_CONTENT)); + buttonRow->Add(new Button("OK", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnOK); + buttonRow->Add(new Button("Cancel", new LinearLayoutParams(1.0f)))->OnClick.Handle(this, &PopupScreen::OnCancel); + box->Add(buttonRow); + } } void PopupScreen::key(const KeyInput &key) { @@ -160,14 +164,12 @@ void ListPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { UI::EventReturn ListPopupScreen::OnListChoice(UI::EventParams &e) { adaptor_.SetSelected(e.a); + callback_(adaptor_.GetSelected()); + screenManager()->finishDialog(this, DR_OK); OnChoice.Dispatch(e); return UI::EVENT_DONE; } -void ListPopupScreen::OnCompleted() { - callback_(adaptor_.GetSelected()); -} - void SliderPopupScreen::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; sliderValue_ = *value_; diff --git a/ui/ui_screen.h b/ui/ui_screen.h index 39bad3d894..eeea4126ad 100644 --- a/ui/ui_screen.h +++ b/ui/ui_screen.h @@ -49,6 +49,7 @@ public: protected: virtual bool FillVertical() { return false; } + virtual bool ShowButtons() { return true; } virtual void OnCompleted() {} private: @@ -69,7 +70,7 @@ public: protected: virtual bool FillVertical() { return true; } - virtual void OnCompleted(); + virtual bool ShowButtons() { return false; } void CreatePopupContents(UI::ViewGroup *parent); UI::StringVectorListAdaptor adaptor_; UI::ListView *listView_;