1 #ifndef _WIDGET_H 2 #define _WIDGET_H 3 4 //#include <unistd.h> 5 //#include "amp_system.h" 6 #include "lvgl.h" 7 #include "render_public.h" 8 #include "render_style.h" 9 #ifdef CONFIG_ENGINE_DUKTAPE 10 #include "be_inl.h" 11 #endif 12 #include "amp_defines.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #define UI_MOD_STR "AMP_UI" 19 20 #define UI_MEM_FREE_CLEAR(addr) \ 21 if ((addr) != NULL) { \ 22 render_free((addr)); \ 23 addr = NULL; \ 24 } 25 26 27 typedef enum { 28 render_state_task_crt = 0, 29 render_state_task_entry, 30 render_state_invalid, 31 }render_state_e; 32 33 typedef enum { 34 msg_unused = 0, 35 36 msg_vm_to_view, 37 msg_view_to_vm, 38 msg_vm_to_model, 39 msg_model_to_vm, 40 msg_list_to_vm, 41 msg_list_to_view, 42 43 msg_on_load_trig, 44 msg_on_load_ret, 45 46 msg_invalid, 47 }vm_msg_type_e; 48 49 typedef enum { 50 vm_unused = 0, 51 vm_created, 52 vm_to_model, 53 vm_to_view, 54 vm_invalid, 55 }vm_data_state_e; 56 57 58 typedef enum { 59 vm_data_none = 0, 60 vm_data_uint, 61 vm_data_int, 62 vm_data_double, 63 vm_data_bool, 64 vm_data_str, 65 vm_data_pointer, 66 vm_data_type_max, 67 }vm_data_type_e; 68 69 typedef struct _vm_data_type_t { 70 vm_data_type_e type; 71 union { 72 int val_none; 73 void* val_pointer; 74 uint32_t val_uint; 75 int32_t val_int; 76 double val_double; 77 bool val_bool; 78 char *val_str; 79 }; 80 } vm_data_type_t; 81 82 typedef struct _model_array_element_t { 83 bool flag; 84 char *name; 85 char *full_name; 86 char *props; 87 vm_data_type_t *data; 88 }model_array_element_t; 89 90 typedef struct _model_array_t { 91 char *name; 92 int ele_num; 93 int array_len; 94 model_array_element_t *element; 95 }model_array_t; 96 97 typedef enum { 98 widget_type_page = 1, 99 widget_type_button, 100 widget_type_text, 101 widget_type_icon, 102 widget_type_slider, 103 widget_type_bar, 104 widget_type_preload, 105 widget_type_switch, 106 widget_type_roller, 107 widget_type_line, 108 widget_type_image, 109 widget_type_container, 110 widget_type_checkbox, 111 widget_type_text_area, 112 widget_type_qrcode, 113 widget_type_list, 114 widget_type_list_item, 115 widget_type_max 116 }widget_type_e; 117 118 typedef struct _widget_type_map_t { 119 widget_type_e type; 120 char *name; 121 } widget_type_map_t; 122 123 124 typedef enum { 125 widget_clock_hour_angle = 1, 126 widget_clock_second_angle, 127 widget_clock_minute_angle, 128 widget_data_invalid, 129 }widget_data_e; 130 131 typedef struct _slist_class_t { 132 char *class_name; 133 struct _slist_class_t *next; 134 }slist_class_t; 135 136 typedef enum { 137 list_parent = 1, 138 list_child, 139 list_child_rdy, 140 list_invalid, 141 }widget_list_flag_e; 142 143 typedef struct _widget_desc_t { 144 char *id; 145 slist_class_t *class; 146 int class_num; 147 widget_type_e type; 148 int state; 149 bool disabled; 150 bool timer_flag; 151 bool sub_flag; 152 char *data; 153 void *attribute; 154 void *custom_style; 155 widget_common_style_t *common_style; 156 157 #if 0 158 widget_style_t *style; 159 uint32_t style_len; 160 int cur_style; 161 int cur_val; 162 #else 163 amp_widget_style_t widget_style; 164 #endif 165 166 void *object; 167 void *widget; 168 uint32_t child_num; 169 uint32_t disp_num; 170 struct _widget_desc_t *parent; 171 list child; 172 list child_display; 173 174 list_node_t node; 175 list_node_t node_display; 176 177 widget_list_flag_e array_parent; 178 widget_list_flag_e array_child; 179 model_array_t *array; 180 int index; 181 }widget_desc_t; 182 183 typedef int (*WIDGST_CREATE_F)(widget_desc_t*); 184 typedef int (*WIDGST_DELETE_F)(widget_desc_t*); 185 186 typedef int (*WIDGST_ATTR_PARSE_F)(widget_desc_t*, char*, char*); 187 188 typedef int (*WIDGST_STYLE_INIT_F)(widget_desc_t*); 189 190 typedef int (*WIDGST_STYLE_PARSE_F)(widget_style_handle_t *, uint32_t, char*, uint32_t); 191 192 typedef int (*WIDGST_CUSTOM_STYLE_PARSE_F)(widget_desc_t *, uint32_t, char*, uint32_t); 193 194 typedef int (*WIDGST_UPDATE_F)(widget_desc_t*); 195 typedef int (*WIDGST_REFRESH_F)(widget_desc_t*); 196 typedef int (*WIDGST_PAINT_F)(widget_desc_t*); 197 typedef int (*WIDGST_ERASE_F)(widget_desc_t*); 198 199 200 typedef int (*WIDGST_SET_ATTR_F)(widget_desc_t*,char *, vm_data_type_t *); 201 typedef int (*WIDGST_SET_TEXT_F)(widget_desc_t*); 202 typedef int (*WIDGST_SET_TEXT_AREA_F)(widget_desc_t*); 203 204 typedef int (*WIDGST_SET_QRCODE_F)(widget_desc_t*); 205 206 typedef int (*WIDGST_PARA_COPY_F)(widget_desc_t *dest, widget_desc_t *src); 207 208 typedef struct _widget_style_type_map_t { 209 int type; 210 char *name; 211 WIDGST_STYLE_PARSE_F parse; 212 } widget_style_type_map_t; 213 214 215 typedef struct _widget_proc_t { 216 bool flag; 217 widget_type_e type; 218 219 WIDGST_CREATE_F create; 220 WIDGST_DELETE_F delete; 221 WIDGST_ATTR_PARSE_F attr_parse; 222 223 WIDGST_STYLE_INIT_F style_init; 224 WIDGST_CUSTOM_STYLE_PARSE_F style_parse; 225 WIDGST_PAINT_F paint; 226 WIDGST_ERASE_F erase; 227 228 WIDGST_UPDATE_F update; 229 WIDGST_REFRESH_F refresh; 230 231 WIDGST_SET_ATTR_F set_attr; 232 WIDGST_SET_TEXT_F set_text; 233 WIDGST_SET_TEXT_AREA_F set_text_area; 234 235 WIDGST_SET_QRCODE_F set_qrcode; 236 237 WIDGST_PARA_COPY_F copy; 238 }widget_proc_t; 239 240 241 typedef enum { 242 page_state_free = 0, 243 page_state_init, 244 page_state_loading, 245 page_state_loaded, 246 page_state_erase, 247 page_state_delete, 248 }page_stete_e; 249 250 251 typedef struct { 252 /* options object */ 253 int object; 254 /* ref of globalData */ 255 int data; 256 /* ref of onShow() */ 257 int on_show; 258 /* ref of onUpdate() */ 259 int on_update; 260 /* ref of onExit() */ 261 int on_exit; 262 }page_options_t; 263 264 265 typedef struct _page_desc_t { 266 page_stete_e state; 267 int index; 268 char name[32]; 269 char path[64]; 270 char css_file[64]; 271 char xml_file[64]; 272 char js_file[64]; 273 uint32_t total_num; 274 uint32_t used_num; 275 widget_desc_t *root_widget; 276 widget_desc_t **widgets; 277 struct _page_desc_t *next_page; 278 css_parse_state_e parse_state; 279 list style_class; 280 widget_style_handle_t widget_handle; 281 page_options_t options; 282 }page_desc_t; 283 284 typedef struct _amp_app_desc_t { 285 uint32_t state; 286 int cur_page; 287 int next_page; 288 int num; 289 char *name; 290 page_desc_t *page; 291 }amp_app_desc_t; 292 293 294 extern bool g_page_active; 295 extern widget_desc_t **g_widget; 296 extern uint32_t g_widget_num; 297 extern uint32_t g_widget_total; 298 extern widget_desc_t *g_page_root; 299 300 widget_desc_t *amp_ui_widget_get(page_desc_t* page, char *id); 301 int amp_ui_widget_type_get(char *str); 302 303 widget_desc_t *amp_ui_widget_creat(page_desc_t* page, widget_type_e type); 304 305 widget_proc_t *amp_ui_widget_proc_get(widget_type_e type); 306 307 int amp_ui_widget_proc_reg(widget_type_e type, widget_proc_t *proc); 308 309 void clock_demo_entry(); 310 311 int clock_get_seconds_angle(); 312 313 int clock_get_minutes_angle(); 314 315 int clock_get_hours_angle(); 316 317 318 void amp_bar_proc_init(void); 319 320 void amp_button_proc_init(void); 321 322 void amp_image_proc_init(void); 323 324 void amp_line_proc_init(void); 325 326 void amp_preload_proc_init(void); 327 328 void amp_roller_proc_init(void); 329 330 void amp_slider_proc_init(void); 331 332 void amp_switch_proc_init(void); 333 334 void amp_text_proc_init(void); 335 336 void amp_text_area_proc_init(void); 337 338 void amp_qrcode_proc_init(void); 339 340 void amp_cont_proc_init(void); 341 342 int amp_ui_xml_file_load(page_desc_t* page); 343 344 int amp_ui_css_file_load(page_desc_t* page); 345 346 int amp_ui_style_refresh(widget_desc_t *widget); 347 348 int amp_ui_style_update(page_desc_t* page, widget_desc_t *widget); 349 350 int amp_ui_layout(widget_desc_t *root); 351 352 int amp_ui_paint(widget_desc_t *root); 353 354 int amp_ui_widget_erase(widget_desc_t *widget); 355 356 int amp_ui_widget_delete(widget_desc_t *widget); 357 358 int render_init(void); 359 360 char *amp_bind_para_parse(char *data); 361 362 int amp_data_bind(widget_desc_t *widget, char *props, char* value); 363 int amp_ui_widget_style_init(widget_desc_t* widget); 364 int amp_ui_widget_style_copy(widget_desc_t* widget,widget_desc_t* src); 365 366 367 extern void page_entry(void *para); 368 extern void page_exit(void *para); 369 extern void page_update(void *para); 370 371 372 extern uint64_t g_time_render[10]; 373 extern amp_app_desc_t g_app; 374 375 376 #ifdef __cplusplus 377 } /* extern "C" */ 378 #endif 379 380 #endif /*_WIDGET_H*/ 381 382