Fixed bug 4747 - [Patch] SDL_ShowMessageBox ignores BUTTON_RETURNKEY_DEFAULT flag
authorSam Lantinga <slouken@libsdl.org>
Mon, 05 Aug 2019 23:52:16 -0700
changeset 130024436f8e76e5c
parent 13001 1353fb9be62b
child 13003 200f23b4f8d2
Fixed bug 4747 - [Patch] SDL_ShowMessageBox ignores BUTTON_RETURNKEY_DEFAULT flag

Caleb Cornett

SDL_ShowMessageBox on UIKit doesn't do anything special with buttons that are marked with the flag SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT. According to Apple's documentation on UIAlertController, a button can respond to a return key if it's marked as the preferredAction of the controller. SDL doesn't set a preferredAction currently, so I've attached a patch to fix that.
src/video/uikit/SDL_uikitmessagebox.m
     1.1 --- a/src/video/uikit/SDL_uikitmessagebox.m	Mon Aug 05 23:46:09 2019 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitmessagebox.m	Mon Aug 05 23:52:16 2019 -0700
     1.3 @@ -91,6 +91,10 @@
     1.4  				                            clickedindex = (int)(sdlButton - messageboxdata->buttons);
     1.5                                          }];
     1.6          [alert addAction:action];
     1.7 +
     1.8 +        if (sdlButton->flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
     1.9 +            alert.preferredAction = action;
    1.10 +        }
    1.11      }
    1.12  
    1.13      if (messageboxdata->window) {