summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-10 10:01:15 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-10 10:01:15 +0200
commit7e42ad9d209de785b40c0e31ddb4c7aeab3f6385 (patch)
tree5cef1f96729a9b508c2c6ab1c0e8efc85a5e7a1b /src/ui
parente60ddfc9afc26b75cf9aa31c1a8c3b7e390a4ac7 (diff)
Mobile: Working on dialog styling
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/util.c155
1 files changed, 122 insertions, 33 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index c6e2fd1a..47cd3ccd 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -354,13 +354,14 @@ iInt2 delta_Click(const iClick *d) {
354 354
355iWidget *makePadding_Widget(int size) { 355iWidget *makePadding_Widget(int size) {
356 iWidget *pad = new_Widget(); 356 iWidget *pad = new_Widget();
357 setId_Widget(pad, "padding");
357 setSize_Widget(pad, init1_I2(size)); 358 setSize_Widget(pad, init1_I2(size));
358 return pad; 359 return pad;
359} 360}
360 361
361iLabelWidget *makeHeading_Widget(const char *text) { 362iLabelWidget *makeHeading_Widget(const char *text) {
362 iLabelWidget *heading = new_LabelWidget(text, NULL); 363 iLabelWidget *heading = new_LabelWidget(text, NULL);
363 setFlags_Widget(as_Widget(heading), frameless_WidgetFlag | alignLeft_WidgetFlag /*| fixedSize_WidgetFlag*/, iTrue); 364 setFlags_Widget(as_Widget(heading), frameless_WidgetFlag | alignLeft_WidgetFlag, iTrue);
364 setBackgroundColor_Widget(as_Widget(heading), none_ColorId); 365 setBackgroundColor_Widget(as_Widget(heading), none_ColorId);
365 return heading; 366 return heading;
366} 367}
@@ -942,6 +943,72 @@ static iBool isTwoColumnPage_(iWidget *d) {
942 return iFalse; 943 return iFalse;
943} 944}
944 945
946static iBool isOmittedPref_(const iString *id) {
947 static const char *omittedPrefs[] = {
948 "prefs.downloads",
949 "prefs.smoothscroll",
950 "prefs.imageloadscroll",
951 "prefs.retainwindow",
952 "prefs.ca.file",
953 "prefs.ca.path",
954 };
955 iForIndices(i, omittedPrefs) {
956 if (cmp_String(id, omittedPrefs[i]) == 0) {
957 return iTrue;
958 }
959 }
960 return iFalse;
961}
962
963enum iPrefsElement {
964 panelTitle_PrefsElement,
965 heading_PrefsElement,
966 toggle_PrefsElement,
967 dropdown_PrefsElement,
968 radioButton_PrefsElement,
969 textInput_PrefsElement,
970};
971
972static iAnyObject *addPanelChild_(iWidget *panel, iAnyObject *child, int64_t flags,
973 enum iPrefsElement elementType,
974 enum iPrefsElement precedingElementType) {
975 /* Erase redundant/unused headings. */
976 if (precedingElementType == heading_PrefsElement &&
977 (!child || elementType == heading_PrefsElement)) {
978 iRelease(removeChild_Widget(panel, back_ObjectList(children_Widget(panel))));
979 if (!cmp_String(id_Widget(constAs_Widget(back_ObjectList(children_Widget(panel)))), "padding")) {
980 iRelease(removeChild_Widget(panel, back_ObjectList(children_Widget(panel))));
981 }
982 }
983 if (child) {
984 /* Insert padding between different element types. */
985 if (precedingElementType != panelTitle_PrefsElement) {
986 if (elementType == heading_PrefsElement ||
987 (elementType == toggle_PrefsElement &&
988 precedingElementType != toggle_PrefsElement &&
989 precedingElementType != heading_PrefsElement)) {
990 addChild_Widget(panel, iClob(makePadding_Widget(lineHeight_Text(defaultBig_FontId))));
991 }
992 }
993 if (elementType == toggle_PrefsElement &&
994 precedingElementType != toggle_PrefsElement) {
995 flags |= borderTop_WidgetFlag;
996 }
997 return addChildFlags_Widget(panel, child, flags);
998 }
999 return NULL;
1000}
1001
1002static void stripTrailingColon_(iLabelWidget *label) {
1003 const iString *text = text_LabelWidget(label);
1004 if (endsWith_String(text, ":")) {
1005 iString *mod = copy_String(text);
1006 removeEnd_String(mod, 1);
1007 updateText_LabelWidget(label, mod);
1008 delete_String(mod);
1009 }
1010}
1011
945void finalizeSheet_Widget(iWidget *sheet) { 1012void finalizeSheet_Widget(iWidget *sheet) {
946 if (deviceType_App() == phone_AppDeviceType) { 1013 if (deviceType_App() == phone_AppDeviceType) {
947 /* The sheet contents are completely rearranged on a phone. We'll set up a linear 1014 /* The sheet contents are completely rearranged on a phone. We'll set up a linear
@@ -982,7 +1049,6 @@ void finalizeSheet_Widget(iWidget *sheet) {
982 iWidget *tabs = findChild_Widget(sheet, "prefs.tabs"); 1049 iWidget *tabs = findChild_Widget(sheet, "prefs.tabs");
983 iWidget *topPanel = new_Widget(); 1050 iWidget *topPanel = new_Widget();
984 setId_Widget(topPanel, "panel.top"); 1051 setId_Widget(topPanel, "panel.top");
985 //setBackgroundColor_Widget(topPanel, red_ColorId);
986 if (tabs) { 1052 if (tabs) {
987 iRelease(removeChild_Widget(sheet, child_Widget(sheet, 0))); /* heading */ 1053 iRelease(removeChild_Widget(sheet, child_Widget(sheet, 0))); /* heading */
988 iRelease(removeChild_Widget(sheet, findChild_Widget(sheet, "dialogbuttons"))); 1054 iRelease(removeChild_Widget(sheet, findChild_Widget(sheet, "dialogbuttons")));
@@ -1042,6 +1108,7 @@ void finalizeSheet_Widget(iWidget *sheet) {
1042 iForEach(PtrArray, j, contents) { 1108 iForEach(PtrArray, j, contents) {
1043 iWidget *owner = topPanel; 1109 iWidget *owner = topPanel;
1044 if (!isEmpty_PtrArray(panelButtons)) { 1110 if (!isEmpty_PtrArray(panelButtons)) {
1111 /* Create a new child panel. */
1045 iLabelWidget *button = at_PtrArray(panelButtons, index_PtrArrayIterator(&j)); 1112 iLabelWidget *button = at_PtrArray(panelButtons, index_PtrArrayIterator(&j));
1046 owner = new_Widget(); 1113 owner = new_Widget();
1047 setId_Widget(owner, "panel"); 1114 setId_Widget(owner, "panel");
@@ -1053,9 +1120,8 @@ void finalizeSheet_Widget(iWidget *sheet) {
1053 setFont_LabelWidget(title, uiLabelLargeBold_FontId); 1120 setFont_LabelWidget(title, uiLabelLargeBold_FontId);
1054 setTextColor_LabelWidget(title, uiHeading_ColorId); 1121 setTextColor_LabelWidget(title, uiHeading_ColorId);
1055 addChildFlags_Widget(sheet, 1122 addChildFlags_Widget(sheet,
1056 iClob(owner), 1123 iClob(owner),
1057 focusRoot_WidgetFlag | 1124 focusRoot_WidgetFlag |
1058 //mouseModal_WidgetFlag |
1059 hidden_WidgetFlag | 1125 hidden_WidgetFlag |
1060 disabled_WidgetFlag | 1126 disabled_WidgetFlag |
1061 arrangeVertical_WidgetFlag | 1127 arrangeVertical_WidgetFlag |
@@ -1068,57 +1134,57 @@ void finalizeSheet_Widget(iWidget *sheet) {
1068 iWidget *pageContent = j.ptr; 1134 iWidget *pageContent = j.ptr;
1069 iWidget *headings = child_Widget(pageContent, 0); 1135 iWidget *headings = child_Widget(pageContent, 0);
1070 iWidget *values = child_Widget(pageContent, 1); 1136 iWidget *values = child_Widget(pageContent, 1);
1071 iBool isFirst = iTrue; 1137 enum iPrefsElement prevElement = panelTitle_PrefsElement;
1072 while (!isEmpty_ObjectList(children_Widget(headings))) { 1138 while (!isEmpty_ObjectList(children_Widget(headings))) {
1073 iWidget *heading = child_Widget(headings, 0); 1139 iWidget *heading = child_Widget(headings, 0);
1074 iWidget *value = child_Widget(values, 0); 1140 iWidget *value = child_Widget(values, 0);
1075 removeChild_Widget(headings, heading); 1141 removeChild_Widget(headings, heading);
1076 removeChild_Widget(values, value); 1142 removeChild_Widget(values, value);
1143 if (isOmittedPref_(id_Widget(value))) {
1144 iRelease(heading);
1145 iRelease(value);
1146 continue;
1147 }
1148 enum iPrefsElement element = toggle_PrefsElement;
1077 iLabelWidget *headingLabel = NULL; 1149 iLabelWidget *headingLabel = NULL;
1078 iLabelWidget *valueLabel = NULL; 1150 iLabelWidget *valueLabel = NULL;
1079 iInputWidget *valueInput = NULL; 1151 iInputWidget *valueInput = NULL;
1080 if (isInstance_Object(heading, &Class_LabelWidget)) { 1152 if (isInstance_Object(heading, &Class_LabelWidget)) {
1081 headingLabel = (iLabelWidget *) heading; 1153 headingLabel = (iLabelWidget *) heading;
1154 stripTrailingColon_(headingLabel);
1082 } 1155 }
1083 if (isInstance_Object(value, &Class_LabelWidget)) { 1156 if (isInstance_Object(value, &Class_LabelWidget)) {
1084 valueLabel = (iLabelWidget *) value; 1157 valueLabel = (iLabelWidget *) value;
1085 } 1158 }
1086 if (isInstance_Object(value, &Class_InputWidget)) { 1159 if (isInstance_Object(value, &Class_InputWidget)) {
1087 valueInput = (iInputWidget *) value; 1160 valueInput = (iInputWidget *) value;
1161 element = textInput_PrefsElement;
1088 } 1162 }
1089 if (valueLabel) { 1163 if (valueLabel) {
1090 setFont_LabelWidget(valueLabel, defaultBig_FontId); 1164 setFont_LabelWidget(valueLabel, defaultBig_FontId);
1091 } 1165 }
1092 if (valueInput) {
1093 setFont_InputWidget(valueInput, defaultBig_FontId);
1094 setContentPadding_InputWidget(valueInput, 3 * gap_UI, 3 * gap_UI);
1095 }
1096 /* Toggles have the button on the right. */ 1166 /* Toggles have the button on the right. */
1097 if (valueLabel && cmp_String(command_LabelWidget(valueLabel), "toggle") == 0) { 1167 if (valueLabel && cmp_String(command_LabelWidget(valueLabel), "toggle") == 0) {
1168 element = toggle_PrefsElement;
1098 iWidget *div = new_Widget(); 1169 iWidget *div = new_Widget();
1099 setBackgroundColor_Widget(div, uiBackgroundSidebar_ColorId); 1170 setBackgroundColor_Widget(div, uiBackgroundSidebar_ColorId);
1100// setFrameColor_Widget(div, uiSeparator_ColorId);
1101 setPadding_Widget(div, gap_UI, gap_UI, 4 * gap_UI, gap_UI); 1171 setPadding_Widget(div, gap_UI, gap_UI, 4 * gap_UI, gap_UI);
1102 addChildFlags_Widget(div, iClob(heading), 0); 1172 addChildFlags_Widget(div, iClob(heading), 0);
1103 setFont_LabelWidget((iLabelWidget *) heading, defaultBig_FontId); 1173 setFont_LabelWidget((iLabelWidget *) heading, defaultBig_FontId);
1104 addChildFlags_Widget(div, iClob(new_Widget()), expand_WidgetFlag); 1174 addChildFlags_Widget(div, iClob(new_Widget()), expand_WidgetFlag);
1105 addChild_Widget(div, iClob(value)); 1175 addChild_Widget(div, iClob(value));
1106 addChildFlags_Widget(owner, 1176 addPanelChild_(owner,
1107 iClob(div), 1177 iClob(div),
1108 borderBottom_WidgetFlag | arrangeHeight_WidgetFlag | 1178 borderBottom_WidgetFlag | arrangeHeight_WidgetFlag |
1109 resizeWidthOfChildren_WidgetFlag | 1179 resizeWidthOfChildren_WidgetFlag |
1110 arrangeHorizontal_WidgetFlag); 1180 arrangeHorizontal_WidgetFlag,
1181 element, prevElement);
1111 } 1182 }
1112 else { 1183 else {
1113 if (valueLabel && isEmpty_String(text_LabelWidget(valueLabel))) { 1184 if (valueLabel && isEmpty_String(text_LabelWidget(valueLabel))) {
1114 /* Subheading padding goes above. */ 1185 element = heading_PrefsElement;
1115// if (!isFirst) {
1116// addChild_Widget(owner, iClob(value));
1117// }
1118// else {
1119 iRelease(value); 1186 iRelease(value);
1120// } 1187 addPanelChild_(owner, iClob(heading), 0, element, prevElement);
1121 addChildFlags_Widget(owner, iClob(heading), 0);
1122 setFont_LabelWidget(headingLabel, uiLabelBold_FontId); 1188 setFont_LabelWidget(headingLabel, uiLabelBold_FontId);
1123 } 1189 }
1124 else { 1190 else {
@@ -1130,26 +1196,48 @@ void finalizeSheet_Widget(iWidget *sheet) {
1130 } 1196 }
1131 const iBool isMenuButton = findChild_Widget(value, "menu") != NULL; 1197 const iBool isMenuButton = findChild_Widget(value, "menu") != NULL;
1132 if (isMenuButton) { 1198 if (isMenuButton) {
1199 element = dropdown_PrefsElement;
1133 setFlags_Widget(value, noBackground_WidgetFlag | frameless_WidgetFlag, iTrue); 1200 setFlags_Widget(value, noBackground_WidgetFlag | frameless_WidgetFlag, iTrue);
1134 setFlags_Widget(value, alignLeft_WidgetFlag, iFalse); 1201 setFlags_Widget(value, alignLeft_WidgetFlag, iFalse);
1135 } 1202 }
1136 if (valueInput || isMenuButton) { 1203 if (childCount_Widget(value) >= 2) {
1204 if (isInstance_Object(child_Widget(value, 0), &Class_InputWidget)) {
1205 element = textInput_PrefsElement;
1206 setPadding_Widget(value, 0, 0, gap_UI, 0);
1207 valueInput = child_Widget(value, 0);
1208 setFlags_Widget(as_Widget(valueInput), fixedWidth_WidgetFlag, iFalse);
1209 setFlags_Widget(as_Widget(valueInput), expand_WidgetFlag, iTrue);
1210 setFlags_Widget(value, resizeWidthOfChildren_WidgetFlag |
1211 resizeToParentWidth_WidgetFlag, iTrue);
1212 setFont_LabelWidget(child_Widget(value, 1), defaultBig_FontId);
1213 setTextColor_LabelWidget(child_Widget(value, 1), uiAnnotation_ColorId);
1214 }
1215 else {
1216 element = radioButton_PrefsElement;
1217 }
1218 }
1219 if (valueInput) {
1220 setFont_InputWidget(valueInput, defaultBig_FontId);
1221 setContentPadding_InputWidget(valueInput, 3 * gap_UI, 3 * gap_UI);
1222 }
1223 if (element == textInput_PrefsElement || isMenuButton) {
1137 setFlags_Widget(value, borderBottom_WidgetFlag, iFalse); 1224 setFlags_Widget(value, borderBottom_WidgetFlag, iFalse);
1138 iWidget *pad = new_Widget(); 1225 iWidget *pad = new_Widget();
1139 setBackgroundColor_Widget(pad, uiBackgroundSidebar_ColorId); 1226 setBackgroundColor_Widget(pad, uiBackgroundSidebar_ColorId);
1140 setPadding_Widget(pad, 0, 1 * gap_UI, 0, 1 * gap_UI); 1227 setPadding_Widget(pad, 0, 1 * gap_UI, 0, 1 * gap_UI);
1141 addChild_Widget(pad, iClob(value)); 1228 addChild_Widget(pad, iClob(value));
1142 addChildFlags_Widget(owner, iClob(pad), borderBottom_WidgetFlag | 1229 addPanelChild_(owner, iClob(pad), borderBottom_WidgetFlag |
1143 arrangeVertical_WidgetFlag | 1230 arrangeVertical_WidgetFlag |
1144 resizeToParentWidth_WidgetFlag | 1231 resizeToParentWidth_WidgetFlag |
1145 resizeWidthOfChildren_WidgetFlag | 1232 resizeWidthOfChildren_WidgetFlag |
1146 arrangeHeight_WidgetFlag); 1233 arrangeHeight_WidgetFlag,
1234 element, prevElement);
1147 } 1235 }
1148 else { 1236 else {
1149 addChild_Widget(owner, iClob(value)); 1237 addPanelChild_(owner, iClob(value), 0, element, prevElement);
1150 } 1238 }
1151 /* Align radio buttons to the right. */ 1239 /* Radio buttons expand to fill the space. */
1152 if (childCount_Widget(value) >= 2) { 1240 if (element == radioButton_PrefsElement) {
1153 setBackgroundColor_Widget(value, uiBackgroundSidebar_ColorId); 1241 setBackgroundColor_Widget(value, uiBackgroundSidebar_ColorId);
1154 setPadding_Widget(value, 4 * gap_UI, 2 * gap_UI, 4 * gap_UI, 2 * gap_UI); 1242 setPadding_Widget(value, 4 * gap_UI, 2 * gap_UI, 4 * gap_UI, 2 * gap_UI);
1155 setFlags_Widget(value, 1243 setFlags_Widget(value,
@@ -1167,8 +1255,9 @@ void finalizeSheet_Widget(iWidget *sheet) {
1167 } 1255 }
1168 } 1256 }
1169 } 1257 }
1170 isFirst = iFalse; 1258 prevElement = element;
1171 } 1259 }
1260 addPanelChild_(owner, NULL, 0, 0, prevElement);
1172 destroy_Widget(pageContent); 1261 destroy_Widget(pageContent);
1173 addChildFlags_Widget(owner, iClob(new_Widget()), expand_WidgetFlag); 1262 addChildFlags_Widget(owner, iClob(new_Widget()), expand_WidgetFlag);
1174 } 1263 }
@@ -1539,7 +1628,7 @@ iWidget *makePreferences_Widget(void) {
1539 addChild_Widget(values, iClob(makeToggle_Widget("prefs.imageloadscroll"))); 1628 addChild_Widget(values, iClob(makeToggle_Widget("prefs.imageloadscroll")));
1540 } 1629 }
1541 /* Window. */ { 1630 /* Window. */ {
1542 appendTwoColumnPage_(tabs, "Window", '2', &headings, &values); 1631 appendTwoColumnPage_(tabs, "Interface", '2', &headings, &values);
1543#if defined (iPlatformApple) || defined (iPlatformMSys) 1632#if defined (iPlatformApple) || defined (iPlatformMSys)
1544 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:"))); 1633 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:")));
1545 addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme"))); 1634 addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme")));