summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c57
1 files changed, 38 insertions, 19 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 4f059dc7..7da68fa5 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -428,6 +428,17 @@ static iBool menuHandler_(iWidget *menu, const char *cmd) {
428 return iFalse; 428 return iFalse;
429} 429}
430 430
431static iWidget *makeMenuSeparator_(void) {
432 iWidget *sep = new_Widget();
433 setBackgroundColor_Widget(sep, uiSeparator_ColorId);
434 sep->rect.size.y = gap_UI / 3;
435 if (deviceType_App() != desktop_AppDeviceType) {
436 sep->rect.size.y = gap_UI / 2;
437 }
438 setFlags_Widget(sep, hover_WidgetFlag | fixedHeight_WidgetFlag, iTrue);
439 return sep;
440}
441
431iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { 442iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
432 iWidget *menu = new_Widget(); 443 iWidget *menu = new_Widget();
433 setFrameColor_Widget(menu, uiSeparator_ColorId); 444 setFrameColor_Widget(menu, uiSeparator_ColorId);
@@ -443,13 +454,7 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
443 for (size_t i = 0; i < n; ++i) { 454 for (size_t i = 0; i < n; ++i) {
444 const iMenuItem *item = &items[i]; 455 const iMenuItem *item = &items[i];
445 if (equal_CStr(item->label, "---")) { 456 if (equal_CStr(item->label, "---")) {
446 iWidget *sep = addChild_Widget(menu, iClob(new_Widget())); 457 addChild_Widget(menu, iClob(makeMenuSeparator_()));
447 setBackgroundColor_Widget(sep, uiSeparator_ColorId);
448 sep->rect.size.y = gap_UI / 3;
449 if (deviceType_App() != desktop_AppDeviceType) {
450 sep->rect.size.y = gap_UI / 2;
451 }
452 setFlags_Widget(sep, hover_WidgetFlag | fixedHeight_WidgetFlag, iTrue);
453 } 458 }
454 else { 459 else {
455 iLabelWidget *label = addChildFlags_Widget( 460 iLabelWidget *label = addChildFlags_Widget(
@@ -462,6 +467,12 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
462 } 467 }
463 } 468 }
464 } 469 }
470 if (deviceType_App() == phone_AppDeviceType) {
471 addChild_Widget(menu, iClob(makeMenuSeparator_()));
472 setFont_LabelWidget(addChildFlags_Widget(menu, iClob(new_LabelWidget("Cancel", "cancel")),
473 frameless_WidgetFlag | alignLeft_WidgetFlag),
474 defaultBig_FontId);
475 }
465 addChild_Widget(parent, iClob(menu)); 476 addChild_Widget(parent, iClob(menu));
466 setCommandHandler_Widget(menu, menuHandler_); 477 setCommandHandler_Widget(menu, menuHandler_);
467 iWidget *cancel = addAction_Widget(menu, SDLK_ESCAPE, 0, "cancel"); 478 iWidget *cancel = addAction_Widget(menu, SDLK_ESCAPE, 0, "cancel");
@@ -471,29 +482,33 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
471} 482}
472 483
473void openMenu_Widget(iWidget *d, iInt2 coord) { 484void openMenu_Widget(iWidget *d, iInt2 coord) {
485 const iInt2 rootSize = rootSize_Window(get_Window());
486 const iBool isPortraitPhone = (deviceType_App() == phone_AppDeviceType && isPortrait_App());
474 /* Menu closes when commands are emitted, so handle any pending ones beforehand. */ 487 /* Menu closes when commands are emitted, so handle any pending ones beforehand. */
475 postCommand_App("cancel"); /* dismiss any other menus */ 488 postCommand_App("cancel"); /* dismiss any other menus */
476 processEvents_App(postedEventsOnly_AppEventMode); 489 processEvents_App(postedEventsOnly_AppEventMode);
477 setFlags_Widget(d, hidden_WidgetFlag, iFalse); 490 setFlags_Widget(d, hidden_WidgetFlag, iFalse);
478 setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue); 491 setFlags_Widget(d, commandOnMouseMiss_WidgetFlag, iTrue);
479 setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); 492 setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse);
480 if (deviceType_App() == phone_AppDeviceType) { 493 if (isPortraitPhone) {
481 if (isPortrait_App()) { 494 setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse);
482 setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse); 495 setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag, iTrue);
483 setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag, iTrue); 496 d->rect.size.x = rootSize_Window(get_Window()).x;
484 d->rect.size.x = rootSize_Window(get_Window()).x; 497 iForEach(ObjectList, i, children_Widget(d)) {
485 iForEach(ObjectList, i, children_Widget(d)) { 498 if (isInstance_Object(i.object, &Class_LabelWidget)) {
486 if (isInstance_Object(i.object, &Class_LabelWidget)) { 499 iLabelWidget *label = i.object;
487 iLabelWidget *label = i.object; 500 setFont_LabelWidget(label, defaultBig_FontId);
488 setFont_LabelWidget(label, defaultBig_FontId);
489 }
490 } 501 }
491 } 502 }
492 } 503 }
493 arrange_Widget(d); 504 arrange_Widget(d);
494 d->rect.pos = coord; 505 if (isPortraitPhone) {
506 d->rect.pos = init_I2(0, rootSize.y);
507 }
508 else {
509 d->rect.pos = coord;
510 }
495 /* Ensure the full menu is visible. */ 511 /* Ensure the full menu is visible. */
496 const iInt2 rootSize = rootSize_Window(get_Window());
497 const iRect bounds = bounds_Widget(d); 512 const iRect bounds = bounds_Widget(d);
498 int leftExcess = -left_Rect(bounds); 513 int leftExcess = -left_Rect(bounds);
499 int rightExcess = right_Rect(bounds) - rootSize.x; 514 int rightExcess = right_Rect(bounds) - rootSize.x;
@@ -523,6 +538,10 @@ void openMenu_Widget(iWidget *d, iInt2 coord) {
523 } 538 }
524 postRefresh_App(); 539 postRefresh_App();
525 postCommand_Widget(d, "menu.opened"); 540 postCommand_Widget(d, "menu.opened");
541 if (isPortraitPhone) {
542 setVisualOffset_Widget(d, height_Widget(d), 0, 0);
543 setVisualOffset_Widget(d, 0, 330, easeOut_AnimFlag | softer_AnimFlag);
544 }
526} 545}
527 546
528void closeMenu_Widget(iWidget *d) { 547void closeMenu_Widget(iWidget *d) {