Add onFinish callback to screens, hook up for UIScreen::OnBack

This commit is contained in:
Henrik Rydgård 2013-10-25 13:07:13 +02:00
parent 0c397c3e68
commit c53bf92350
3 changed files with 9 additions and 6 deletions

View File

@ -170,7 +170,7 @@ void ScreenManager::RecreateAllViews() {
}
}
void ScreenManager::finishDialog(const Screen *dialog, DialogResult result) {
void ScreenManager::finishDialog(Screen *dialog, DialogResult result) {
if (stack_.empty()) {
ELOG("Must be in a dialog to finishDialog");
return;
@ -179,6 +179,7 @@ void ScreenManager::finishDialog(const Screen *dialog, DialogResult result) {
ELOG("Wrong dialog being finished!");
return;
}
dialog->onFinish(result);
dialogFinished_ = dialog;
dialogResult_ = result;
}

View File

@ -31,6 +31,7 @@ enum DialogResult {
DR_CANCEL,
DR_YES,
DR_NO,
DR_BACK,
};
class ScreenManager;
@ -43,6 +44,7 @@ public:
screenManager_ = 0;
}
virtual void onFinish(DialogResult reason) {}
virtual void update(InputState &input) {}
virtual void render() {}
virtual void deviceLost() {}
@ -99,7 +101,7 @@ public:
void RecreateAllViews();
// Pops the dialog away.
void finishDialog(const Screen *dialog, DialogResult result = DR_OK);
void finishDialog(Screen *dialog, DialogResult result = DR_OK);
// Instant touch, separate from the update() mechanism.
void touch(const TouchInput &touch);

View File

@ -55,7 +55,7 @@ void UIScreen::key(const KeyInput &key) {
void UIDialogScreen::key(const KeyInput &key) {
if ((key.flags & KEY_DOWN) && UI::IsEscapeKeyCode(key.keyCode)) {
screenManager()->finishDialog(this, DR_CANCEL);
screenManager()->finishDialog(this, DR_BACK);
} else {
UIScreen::key(key);
}
@ -96,7 +96,7 @@ void UIScreen::axis(const AxisInput &axis) {
}
UI::EventReturn UIScreen::OnBack(UI::EventParams &e) {
screenManager()->finishDialog(this, DR_OK);
screenManager()->finishDialog(this, DR_BACK);
return UI::EVENT_DONE;
}
@ -114,7 +114,7 @@ void PopupScreen::touch(const TouchInput &touch) {
}
if (!box_->GetBounds().Contains(touch.x, touch.y))
screenManager()->finishDialog(this, DR_CANCEL);
screenManager()->finishDialog(this, DR_BACK);
UIDialogScreen::touch(touch);
}
@ -183,7 +183,7 @@ void ListPopupScreen::CreatePopupContents(UI::ViewGroup *parent) {
UI::EventReturn ListPopupScreen::OnListChoice(UI::EventParams &e) {
adaptor_.SetSelected(e.a);
if (callback_)
callback_(adaptor_.GetSelected());
callback_(adaptor_.GetSelected());
screenManager()->finishDialog(this, DR_OK);
OnCompleted(DR_OK);
OnChoice.Dispatch(e);