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.c75
1 files changed, 59 insertions, 16 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index 47cd3ccd..0d34658e 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -528,7 +528,7 @@ void openMenu_Widget(iWidget *d, iInt2 coord) {
528 setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse); 528 setFlags_Widget(findChild_Widget(d, "menu.cancel"), disabled_WidgetFlag, iFalse);
529 if (isPortraitPhone) { 529 if (isPortraitPhone) {
530 setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse); 530 setFlags_Widget(d, arrangeWidth_WidgetFlag | resizeChildrenToWidestChild_WidgetFlag, iFalse);
531 setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag, iTrue); 531 setFlags_Widget(d, resizeWidthOfChildren_WidgetFlag | drawBackgroundToBottom_WidgetFlag, iTrue);
532 if (!isSlidePanel) { 532 if (!isSlidePanel) {
533 setFlags_Widget(d, borderTop_WidgetFlag, iTrue); 533 setFlags_Widget(d, borderTop_WidgetFlag, iTrue);
534 } 534 }
@@ -912,6 +912,25 @@ static iBool slidePanelHandler_(iWidget *d, const char *cmd) {
912 postCommand_App("panel.close"); 912 postCommand_App("panel.close");
913 return iTrue; 913 return iTrue;
914 } 914 }
915 if (equal_Command(cmd, "window.resized")) {
916 iWidget *sheet = parent_Widget(d);
917#if defined (iPlatformAppleMobile)
918 float left, top, right, bottom;
919 safeAreaInsets_iOS(&left, &top, &right, &bottom);
920 /* TODO: incorrect */
921 if (isLandscape_App()) {
922 setPadding_Widget(sheet, left, 0, right, 0);
923 }
924 else {
925 setPadding1_Widget(sheet, 0);
926 }
927#endif
928 }
929 if (equal_Command(cmd, "panel.showhelp")) {
930 postCommand_App("prefs.dismiss");
931 postCommand_App("open url:about:help");
932 return iTrue;
933 }
915 if (equal_Command(cmd, "panel.close")) { 934 if (equal_Command(cmd, "panel.close")) {
916 iBool wasClosed = iFalse; 935 iBool wasClosed = iFalse;
917 iForEach(ObjectList, i, children_Widget(parent_Widget(d))) { 936 iForEach(ObjectList, i, children_Widget(parent_Widget(d))) {
@@ -975,9 +994,9 @@ static iAnyObject *addPanelChild_(iWidget *panel, iAnyObject *child, int64_t fla
975 /* Erase redundant/unused headings. */ 994 /* Erase redundant/unused headings. */
976 if (precedingElementType == heading_PrefsElement && 995 if (precedingElementType == heading_PrefsElement &&
977 (!child || elementType == heading_PrefsElement)) { 996 (!child || elementType == heading_PrefsElement)) {
978 iRelease(removeChild_Widget(panel, back_ObjectList(children_Widget(panel)))); 997 iRelease(removeChild_Widget(panel, lastChild_Widget(panel)));
979 if (!cmp_String(id_Widget(constAs_Widget(back_ObjectList(children_Widget(panel)))), "padding")) { 998 if (!cmp_String(id_Widget(constAs_Widget(lastChild_Widget(panel))), "padding")) {
980 iRelease(removeChild_Widget(panel, back_ObjectList(children_Widget(panel)))); 999 iRelease(removeChild_Widget(panel, lastChild_Widget(panel)));
981 } 1000 }
982 } 1001 }
983 if (child) { 1002 if (child) {
@@ -1009,6 +1028,18 @@ static void stripTrailingColon_(iLabelWidget *label) {
1009 } 1028 }
1010} 1029}
1011 1030
1031static iLabelWidget *makePanelButton_(const char *text, const char *command) {
1032 iLabelWidget *btn = new_LabelWidget(text, command);
1033 setFlags_Widget(as_Widget(btn),
1034 borderBottom_WidgetFlag | alignLeft_WidgetFlag |
1035 frameless_WidgetFlag | extraPadding_WidgetFlag,
1036 iTrue);
1037 checkIcon_LabelWidget(btn);
1038 setFont_LabelWidget(btn, defaultBig_FontId);
1039 setBackgroundColor_Widget(as_Widget(btn), uiBackgroundSidebar_ColorId);
1040 return btn;
1041}
1042
1012void finalizeSheet_Widget(iWidget *sheet) { 1043void finalizeSheet_Widget(iWidget *sheet) {
1013 if (deviceType_App() == phone_AppDeviceType) { 1044 if (deviceType_App() == phone_AppDeviceType) {
1014 /* The sheet contents are completely rearranged on a phone. We'll set up a linear 1045 /* The sheet contents are completely rearranged on a phone. We'll set up a linear
@@ -1043,12 +1074,16 @@ void finalizeSheet_Widget(iWidget *sheet) {
1043 frameless_WidgetFlag | 1074 frameless_WidgetFlag |
1044 resizeWidthOfChildren_WidgetFlag, 1075 resizeWidthOfChildren_WidgetFlag,
1045 iTrue); 1076 iTrue);
1046 setBackgroundColor_Widget(sheet, green_ColorId); 1077 setBackgroundColor_Widget(sheet, uiBackground_ColorId);
1047 iPtrArray *contents = collect_PtrArray(new_PtrArray()); /* two-column pages */ 1078 iPtrArray *contents = collect_PtrArray(new_PtrArray()); /* two-column pages */
1048 iPtrArray *panelButtons = collect_PtrArray(new_PtrArray()); 1079 iPtrArray *panelButtons = collect_PtrArray(new_PtrArray());
1049 iWidget *tabs = findChild_Widget(sheet, "prefs.tabs"); 1080 iWidget *tabs = findChild_Widget(sheet, "prefs.tabs");
1081 const iBool isPrefs = (tabs != NULL);
1082 const int64_t panelButtonFlags = borderBottom_WidgetFlag | alignLeft_WidgetFlag |
1083 frameless_WidgetFlag | extraPadding_WidgetFlag;
1050 iWidget *topPanel = new_Widget(); 1084 iWidget *topPanel = new_Widget();
1051 setId_Widget(topPanel, "panel.top"); 1085 setId_Widget(topPanel, "panel.top");
1086 addChild_Widget(topPanel, iClob(makePadding_Widget(lineHeight_Text(defaultBig_FontId))));
1052 if (tabs) { 1087 if (tabs) {
1053 iRelease(removeChild_Widget(sheet, child_Widget(sheet, 0))); /* heading */ 1088 iRelease(removeChild_Widget(sheet, child_Widget(sheet, 0))); /* heading */
1054 iRelease(removeChild_Widget(sheet, findChild_Widget(sheet, "dialogbuttons"))); 1089 iRelease(removeChild_Widget(sheet, findChild_Widget(sheet, "dialogbuttons")));
@@ -1063,22 +1098,21 @@ void finalizeSheet_Widget(iWidget *sheet) {
1063 iLabelWidget *panelButton; 1098 iLabelWidget *panelButton;
1064 pushBack_PtrArray(panelButtons, 1099 pushBack_PtrArray(panelButtons,
1065 addChildFlags_Widget(topPanel, 1100 addChildFlags_Widget(topPanel,
1066 iClob(panelButton = new_LabelWidget 1101 iClob(panelButton = makePanelButton_(
1067 (i == 1 ? "User Interface" : cstr_String(text), 1102 i == 1 ? "User Interface" : cstr_String(text),
1068 "panel.open")), 1103 "panel.open")),
1069 alignLeft_WidgetFlag | frameless_WidgetFlag | 1104 (i == 0 ? borderTop_WidgetFlag : 0) |
1070 borderBottom_WidgetFlag | extraPadding_WidgetFlag |
1071 chevron_WidgetFlag)); 1105 chevron_WidgetFlag));
1072 const iChar icons[] = { 1106 const iChar icons[] = {
1073 0x2699, /* gear */ 1107 0x02699, /* gear */
1074 0x1f4f1, /* mobile phone */ 1108 0x1f4f1, /* mobile phone */
1075 0x1f3a8, /* palette */ 1109 0x1f3a8, /* palette */
1076 0x1f523, 1110 0x1f523,
1077 0x1f5a7, /* computer network */ 1111 0x1f5a7, /* computer network */
1078 }; 1112 };
1079 setIcon_LabelWidget(panelButton, icons[i]); 1113 setIcon_LabelWidget(panelButton, icons[i]);
1080 setFont_LabelWidget(panelButton, defaultBig_FontId); 1114// setFont_LabelWidget(panelButton, defaultBig_FontId);
1081 setBackgroundColor_Widget(as_Widget(panelButton), uiBackgroundSidebar_ColorId); 1115// setBackgroundColor_Widget(as_Widget(panelButton), uiBackgroundSidebar_ColorId);
1082 iRelease(page); 1116 iRelease(page);
1083 delete_String(text); 1117 delete_String(text);
1084 } 1118 }
@@ -1259,9 +1293,19 @@ void finalizeSheet_Widget(iWidget *sheet) {
1259 } 1293 }
1260 addPanelChild_(owner, NULL, 0, 0, prevElement); 1294 addPanelChild_(owner, NULL, 0, 0, prevElement);
1261 destroy_Widget(pageContent); 1295 destroy_Widget(pageContent);
1262 addChildFlags_Widget(owner, iClob(new_Widget()), expand_WidgetFlag); 1296 setFlags_Widget(owner, drawBackgroundToBottom_WidgetFlag, iTrue);
1263 } 1297 }
1264 destroyPending_Widget(); 1298 destroyPending_Widget();
1299 /* Additional elements for preferences. */
1300 if (isPrefs) {
1301 addChild_Widget(topPanel, iClob(makePadding_Widget(lineHeight_Text(defaultBig_FontId))));
1302 addChildFlags_Widget(topPanel,
1303 iClob(makePanelButton_(info_Icon " Help", "panel.showhelp")),
1304 borderTop_WidgetFlag);
1305 addChildFlags_Widget(topPanel,
1306 iClob(makePanelButton_(planet_Icon " About", "panel.about")),
1307 chevron_WidgetFlag);
1308 }
1265 /* Navbar. */ { 1309 /* Navbar. */ {
1266 iWidget *navi = new_Widget(); 1310 iWidget *navi = new_Widget();
1267 setSize_Widget(navi, init_I2(-1, navBarHeight)); 1311 setSize_Widget(navi, init_I2(-1, navBarHeight));
@@ -1276,8 +1320,7 @@ void finalizeSheet_Widget(iWidget *sheet) {
1276 setFont_LabelWidget(back, defaultBig_FontId); 1320 setFont_LabelWidget(back, defaultBig_FontId);
1277 addChildFlags_Widget(sheet, iClob(navi), 1321 addChildFlags_Widget(sheet, iClob(navi),
1278 arrangeHeight_WidgetFlag | resizeWidthOfChildren_WidgetFlag | 1322 arrangeHeight_WidgetFlag | resizeWidthOfChildren_WidgetFlag |
1279 resizeToParentWidth_WidgetFlag | arrangeVertical_WidgetFlag | 1323 resizeToParentWidth_WidgetFlag | arrangeVertical_WidgetFlag);
1280 borderBottom_WidgetFlag);
1281 } 1324 }
1282 arrange_Widget(sheet->parent); 1325 arrange_Widget(sheet->parent);
1283 printTree_Widget(sheet); 1326 printTree_Widget(sheet);