summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-10 14:58:35 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-10 14:58:35 +0200
commitbe1b78651171e9a9386c9fbbf8b8aced2e8dbcac (patch)
tree2fcf099d487f0712619bff822f01648182e96509 /src/ui/util.c
parent199e99d120086af2e782ca994a3df080401e33de (diff)
Mobile: Phone-styled input dialog
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c44
1 files changed, 36 insertions, 8 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
1064void finalizeSheet_Widget(iWidget *sheet) { 1064void 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
1433static void updateValueInputWidth_(iWidget *dlg) { 1445static 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 }