diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-10 14:58:35 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-10 14:58:35 +0200 |
commit | be1b78651171e9a9386c9fbbf8b8aced2e8dbcac (patch) | |
tree | 2fcf099d487f0712619bff822f01648182e96509 | |
parent | 199e99d120086af2e782ca994a3df080401e33de (diff) |
Mobile: Phone-styled input dialog
-rw-r--r-- | src/ui/util.c | 44 | ||||
-rw-r--r-- | src/ui/widget.c | 4 | ||||
-rw-r--r-- | src/ui/window.c | 2 |
3 files changed, 41 insertions, 9 deletions
diff --git a/src/ui/util.c b/src/ui/util.c index 7feaa703..05858b52 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -1062,7 +1062,7 @@ static iWidget *makeValuePadding_(iWidget *value) { | |||
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | void finalizeSheet_Widget(iWidget *sheet) { | 1064 | void finalizeSheet_Widget(iWidget *sheet) { |
1065 | if (deviceType_App() == phone_AppDeviceType) { | 1065 | if (deviceType_App() == phone_AppDeviceType && parent_Widget(sheet) == get_Window()->root) { |
1066 | if (~flags_Widget(sheet) & keepOnTop_WidgetFlag) { | 1066 | if (~flags_Widget(sheet) & keepOnTop_WidgetFlag) { |
1067 | /* Already finalized. */ | 1067 | /* Already finalized. */ |
1068 | arrange_Widget(sheet); | 1068 | arrange_Widget(sheet); |
@@ -1176,7 +1176,7 @@ void finalizeSheet_Widget(iWidget *sheet) { | |||
1176 | setBackgroundColor_Widget(owner, uiBackground_ColorId); | 1176 | setBackgroundColor_Widget(owner, uiBackground_ColorId); |
1177 | addChild_Widget(owner, iClob(makePadding_Widget(navBarHeight - topSafe))); | 1177 | addChild_Widget(owner, iClob(makePadding_Widget(navBarHeight - topSafe))); |
1178 | iLabelWidget *title = addChildFlags_Widget(owner, | 1178 | iLabelWidget *title = addChildFlags_Widget(owner, |
1179 | iClob(new_LabelWidget(cstr_String(text_LabelWidget(button)), NULL)), alignLeft_WidgetFlag | frameless_WidgetFlag); | 1179 | iClob(new_LabelWidget(cstrCollect_String(upper_String(text_LabelWidget(button))), NULL)), alignLeft_WidgetFlag | frameless_WidgetFlag); |
1180 | setFont_LabelWidget(title, uiLabelLargeBold_FontId); | 1180 | setFont_LabelWidget(title, uiLabelLargeBold_FontId); |
1181 | setTextColor_LabelWidget(title, uiHeading_ColorId); | 1181 | setTextColor_LabelWidget(title, uiHeading_ColorId); |
1182 | addChildFlags_Widget(sheet, | 1182 | addChildFlags_Widget(sheet, |
@@ -1377,7 +1377,19 @@ void finalizeSheet_Widget(iWidget *sheet) { | |||
1377 | addChildFlags_Widget(as_Widget(back), iClob(def), moveToParentRightEdge_WidgetFlag); | 1377 | addChildFlags_Widget(as_Widget(back), iClob(def), moveToParentRightEdge_WidgetFlag); |
1378 | updateSize_LabelWidget(def); | 1378 | updateSize_LabelWidget(def); |
1379 | } | 1379 | } |
1380 | /* TODO: Action buttons should be added in the bottom as extra buttons. */ | ||
1380 | iRelease(removeChild_Widget(parent_Widget(buttons), buttons)); | 1381 | iRelease(removeChild_Widget(parent_Widget(buttons), buttons)); |
1382 | /* Styling for remaining elements. */ | ||
1383 | iForEach(ObjectList, i, children_Widget(topPanel)) { | ||
1384 | if (isInstance_Object(i.object, &Class_LabelWidget) && | ||
1385 | isEmpty_String(command_LabelWidget(i.object)) && | ||
1386 | isEmpty_String(id_Widget(i.object))) { | ||
1387 | setFlags_Widget(i.object, alignLeft_WidgetFlag, iTrue); | ||
1388 | if (font_LabelWidget(i.object) == uiLabel_FontId) { | ||
1389 | setFont_LabelWidget(i.object, uiContent_FontId); | ||
1390 | } | ||
1391 | } | ||
1392 | } | ||
1381 | } | 1393 | } |
1382 | addChildFlags_Widget(sheet, iClob(navi), | 1394 | addChildFlags_Widget(sheet, iClob(navi), |
1383 | arrangeHeight_WidgetFlag | resizeWidthOfChildren_WidgetFlag | | 1395 | arrangeHeight_WidgetFlag | resizeWidthOfChildren_WidgetFlag | |
@@ -1431,10 +1443,16 @@ static void acceptValueInput_(iWidget *dlg) { | |||
1431 | } | 1443 | } |
1432 | 1444 | ||
1433 | static void updateValueInputWidth_(iWidget *dlg) { | 1445 | static void updateValueInputWidth_(iWidget *dlg) { |
1434 | const iInt2 rootSize = rootSize_Window(get_Window()); | 1446 | const iRect safeRoot = safeRootRect_Window(get_Window()); |
1447 | const iInt2 rootSize = safeRoot.size; | ||
1435 | iWidget * title = findChild_Widget(dlg, "valueinput.title"); | 1448 | iWidget * title = findChild_Widget(dlg, "valueinput.title"); |
1436 | iWidget * prompt = findChild_Widget(dlg, "valueinput.prompt"); | 1449 | iWidget * prompt = findChild_Widget(dlg, "valueinput.prompt"); |
1437 | dlg->rect.size.x = iMaxi(iMaxi(rootSize.x / 2, title->rect.size.x), prompt->rect.size.x); | 1450 | if (deviceType_App() == phone_AppDeviceType) { |
1451 | dlg->rect.size.x = rootSize.x; | ||
1452 | } | ||
1453 | else { | ||
1454 | dlg->rect.size.x = iMaxi(iMaxi(rootSize.x / 2, title->rect.size.x), prompt->rect.size.x); | ||
1455 | } | ||
1438 | as_Widget(findChild_Widget(dlg, "input"))->rect.size.x = dlg->rect.size.x; | 1456 | as_Widget(findChild_Widget(dlg, "input"))->rect.size.x = dlg->rect.size.x; |
1439 | } | 1457 | } |
1440 | 1458 | ||
@@ -1493,6 +1511,11 @@ iWidget *makeDialogButtons_Widget(const iMenuItem *actions, size_t numActions) { | |||
1493 | if (!haveSep) { | 1511 | if (!haveSep) { |
1494 | addChildFlags_Widget(div, iClob(new_Widget()), expand_WidgetFlag); | 1512 | addChildFlags_Widget(div, iClob(new_Widget()), expand_WidgetFlag); |
1495 | } | 1513 | } |
1514 | int fonts[2] = { uiLabel_FontId, uiLabelBold_FontId }; | ||
1515 | if (deviceType_App() == phone_AppDeviceType) { | ||
1516 | fonts[0] = defaultMedium_FontId; | ||
1517 | fonts[1] = defaultMediumBold_FontId; | ||
1518 | } | ||
1496 | for (size_t i = 0; i < numActions; i++) { | 1519 | for (size_t i = 0; i < numActions; i++) { |
1497 | const char *label = actions[i].label; | 1520 | const char *label = actions[i].label; |
1498 | const char *cmd = actions[i].command; | 1521 | const char *cmd = actions[i].command; |
@@ -1520,9 +1543,7 @@ iWidget *makeDialogButtons_Widget(const iMenuItem *actions, size_t numActions) { | |||
1520 | } | 1543 | } |
1521 | iLabelWidget *button = | 1544 | iLabelWidget *button = |
1522 | addChild_Widget(div, iClob(newKeyMods_LabelWidget(actions[i].label, key, kmods, cmd))); | 1545 | addChild_Widget(div, iClob(newKeyMods_LabelWidget(actions[i].label, key, kmods, cmd))); |
1523 | if (isDefault) { | 1546 | setFont_LabelWidget(button, isDefault ? fonts[1] : fonts[0]); |
1524 | setFont_LabelWidget(button, uiLabelBold_FontId); | ||
1525 | } | ||
1526 | } | 1547 | } |
1527 | return div; | 1548 | return div; |
1528 | } | 1549 | } |
@@ -1533,6 +1554,7 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con | |||
1533 | setFocus_Widget(NULL); | 1554 | setFocus_Widget(NULL); |
1534 | } | 1555 | } |
1535 | iWidget *dlg = makeSheet_Widget(command); | 1556 | iWidget *dlg = makeSheet_Widget(command); |
1557 | // setFlags_Widget(dlg, horizontalSafeAreaPadding_Widget, iTrue); | ||
1536 | setCommandHandler_Widget(dlg, valueInputHandler_); | 1558 | setCommandHandler_Widget(dlg, valueInputHandler_); |
1537 | if (parent) { | 1559 | if (parent) { |
1538 | addChild_Widget(parent, iClob(dlg)); | 1560 | addChild_Widget(parent, iClob(dlg)); |
@@ -1543,7 +1565,13 @@ iWidget *makeValueInput_Widget(iWidget *parent, const iString *initialValue, con | |||
1543 | setId_Widget( | 1565 | setId_Widget( |
1544 | addChildFlags_Widget(dlg, iClob(new_LabelWidget(prompt, NULL)), frameless_WidgetFlag), | 1566 | addChildFlags_Widget(dlg, iClob(new_LabelWidget(prompt, NULL)), frameless_WidgetFlag), |
1545 | "valueinput.prompt"); | 1567 | "valueinput.prompt"); |
1546 | iInputWidget *input = addChild_Widget(dlg, iClob(new_InputWidget(0))); | 1568 | iInputWidget *input = addChildFlags_Widget(dlg, iClob(new_InputWidget(0)), 0); |
1569 | setContentPadding_InputWidget(input, 0.5f * gap_UI, 0.5f * gap_UI); | ||
1570 | if (deviceType_App() == phone_AppDeviceType) { | ||
1571 | setFont_InputWidget(input, defaultBig_FontId); | ||
1572 | setBackgroundColor_Widget(dlg, uiBackgroundSidebar_ColorId); | ||
1573 | setContentPadding_InputWidget(input, gap_UI, gap_UI); | ||
1574 | } | ||
1547 | if (initialValue) { | 1575 | if (initialValue) { |
1548 | setText_InputWidget(input, initialValue); | 1576 | setText_InputWidget(input, initialValue); |
1549 | } | 1577 | } |
diff --git a/src/ui/widget.c b/src/ui/widget.c index c7a23c54..e9a162e3 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -34,6 +34,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
34 | #include <SDL_mouse.h> | 34 | #include <SDL_mouse.h> |
35 | #include <stdarg.h> | 35 | #include <stdarg.h> |
36 | 36 | ||
37 | #if defined (iPlatformAppleMobile) | ||
38 | # include "../ios.h" | ||
39 | #endif | ||
40 | |||
37 | iDeclareType(RootData) | 41 | iDeclareType(RootData) |
38 | 42 | ||
39 | struct Impl_RootData { | 43 | struct Impl_RootData { |
diff --git a/src/ui/window.c b/src/ui/window.c index 637174b4..afc05da9 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -1811,7 +1811,7 @@ iRect safeRootRect_Window(const iWindow *d) { | |||
1811 | #if defined (iPlatformAppleMobile) | 1811 | #if defined (iPlatformAppleMobile) |
1812 | float left, top, right, bottom; | 1812 | float left, top, right, bottom; |
1813 | safeAreaInsets_iOS(&left, &top, &right, &bottom); | 1813 | safeAreaInsets_iOS(&left, &top, &right, &bottom); |
1814 | adjustEdges_Rect(&rect, top, right, bottom, left); | 1814 | adjustEdges_Rect(&rect, top, -right, -bottom, left); |
1815 | #endif | 1815 | #endif |
1816 | return rect; | 1816 | return rect; |
1817 | } | 1817 | } |