1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef UPDATER_UI_TRAITS_H 17 #define UPDATER_UI_TRAITS_H 18 19 #include "macros.h" 20 #include "traits_util.h" 21 22 namespace Updater { 23 template<typename T> struct Traits; 24 // define struct for load ui strategy in ui config file 25 DEFINE_STRUCT_TRAIT(ComInfo, "com", 26 (std::string, pageId), 27 (std::string, comId) 28 ); 29 DEFINE_STRUCT_TRAIT(ProgressPage, "", 30 (std::string, progressPageId), 31 (std::string, progressComId), 32 (std::string, progressType), 33 (std::string, logoComId), 34 (std::string, logoType), 35 (std::string, warningComId) 36 ); 37 DEFINE_STRUCT_TRAIT(ResPage, "", 38 (std::string, successPageId), 39 (std::string, failPageId) 40 ); 41 DEFINE_STRUCT_TRAIT(UiStrategyCfg, "strategy", 42 (std::string, confirmPageId), 43 (ComInfo, labelLogId), 44 (ComInfo, labelLogResId), 45 (ComInfo, labelUpdId), 46 (ProgressPage, progressPage), 47 (ResPage, resPage) 48 ); 49 50 // define struct for load pages' components from page json config, such as menu.json, update.json 51 DEFINE_STRUCT_TRAIT(UxViewCommonInfo, "Common", 52 (int, x), 53 (int, y), 54 (int, w), 55 (int, h), 56 (std::string, id), 57 (std::string, type), 58 (bool, visible) 59 ); 60 61 DEFINE_STRUCT_TRAIT(UxLabelInfo, "UILabel", 62 (uint8_t, fontSize), 63 (std::string, text), 64 (std::string, align), 65 (std::string, fontColor), 66 (std::string, bgColor) 67 ); 68 DEFINE_STRUCT_TRAIT(UxImageInfo, "UIImageView", 69 (std::string, resPath), 70 (std::string, filePrefix), 71 (uint32_t, imgCnt), 72 (uint32_t, updInterval) 73 ); 74 DEFINE_STRUCT_TRAIT(UxBoxProgressInfo, "UIBoxProgress", 75 (uint32_t, defaultValue), 76 (std::string, fgColor), 77 (std::string, bgColor), 78 (std::string, endPoint), 79 (bool, hasEp) 80 ); 81 DEFINE_STRUCT_TRAIT(UxLabelBtnInfo, "UILabelButton", 82 (uint8_t, fontSize), 83 (std::string, text), 84 (std::string, txtColor), 85 (std::string, bgColor), 86 (std::string, focusedTxtColor), 87 (std::string, focusedBgColor), 88 (bool, focusable) 89 ); 90 DEFINE_STRUCT_TRAIT(UxSubPageInfo, "subpages", 91 (std::string, id), 92 (std::string, bgColor), 93 (std::vector<std::string>, coms) 94 ); 95 DEFINE_STRUCT_TRAIT(PagePath, "", 96 (std::string, dir), 97 (std::string, entry), 98 (std::vector<std::string>, pages) 99 ); 100 101 using SpecificInfo = std::variant<UxLabelInfo, UxImageInfo, UxBoxProgressInfo, UxLabelBtnInfo>; 102 103 struct UxViewInfo { 104 UxViewCommonInfo commonInfo {}; 105 SpecificInfo specificInfo {}; 106 }; 107 108 struct UxPageInfo { 109 std::string id {}; 110 std::string bgColor {}; 111 std::vector<UxViewInfo> viewInfos {}; 112 std::vector<UxSubPageInfo> subpages {}; 113 }; 114 115 /** 116 * only define trait for uxpageinfo, because viewInfos_ is a variant, 117 * can't be parsed by Visit<SETVAL>(...), so it's manually parsed in 118 * LayoutParser 119 */ 120 DEFINE_TRAIT(UxPageInfo, "", 121 (std::string, id), 122 (std::string, bgColor), 123 (std::vector<UxSubPageInfo>, subpages) 124 ); 125 // define struct for load language resources in ui config file 126 DEFINE_STRUCT_TRAIT(Res, "Res", 127 (std::string, path), 128 (int, level) 129 ); 130 DEFINE_STRUCT_TRAIT(LangResource, "", 131 (std::string, localeFile), 132 (std::vector<Res>, res) 133 ); 134 135 // define struct for load callback configuration in ui config file 136 DEFINE_STRUCT_TRAIT(CallbackCfg, "", 137 (std::string, pageId), 138 (std::string, comId), 139 (std::string, type), 140 (std::string, func) 141 ); 142 } 143 #endif 144