/** * Create a demo application */ void demo_create(void) { #if LV_DEMO_WALLPAPER lv_obj_t *wp = lv_img_create(lv_scr_act(), NULL); lv_img_set_src(wp, &img_bubble_pattern); lv_obj_set_width(wp, LV_HOR_RES * 4); lv_obj_set_protect(wp, LV_PROTECT_POS); #endif static lv_style_t style_tv_btn_bg; lv_style_copy(&style_tv_btn_bg, &lv_style_plain); style_tv_btn_bg.body.main_color = LV_COLOR_HEX(0x487fb7); style_tv_btn_bg.body.grad_color = LV_COLOR_HEX(0x487fb7); style_tv_btn_bg.body.padding.ver = 0; static lv_style_t style_tv_btn_rel; lv_style_copy(&style_tv_btn_rel, &lv_style_btn_rel); style_tv_btn_rel.body.empty = 1; style_tv_btn_rel.body.border.width = 0; static lv_style_t style_tv_btn_pr; lv_style_copy(&style_tv_btn_pr, &lv_style_btn_pr); style_tv_btn_pr.body.radius = 0; style_tv_btn_pr.body.opa = LV_OPA_50; style_tv_btn_pr.body.main_color = LV_COLOR_WHITE; style_tv_btn_pr.body.grad_color = LV_COLOR_WHITE; style_tv_btn_pr.body.border.width = 0; style_tv_btn_pr.text.color = LV_COLOR_GRAY; lv_obj_t *tv = lv_tabview_create(lv_scr_act(), NULL); #if LV_DEMO_WALLPAPER lv_obj_set_parent(wp, ((lv_tabview_ext_t *) tv->ext_attr)->content); lv_obj_set_pos(wp, 0, -5); #endif lv_obj_t *tab1 = lv_tabview_add_tab(tv, "Write"); lv_obj_t *tab2 = lv_tabview_add_tab(tv, "List"); lv_obj_t *tab3 = lv_tabview_add_tab(tv, "Chart"); #if LV_DEMO_WALLPAPER == 0 /*Blue bg instead of wallpaper*/ lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BG, &style_tv_btn_bg); #endif lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_BG, &style_tv_btn_bg); lv_tabview_set_style(tv, LV_TABVIEW_STYLE_INDIC, &lv_style_plain); lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_REL, &style_tv_btn_rel); lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_PR, &style_tv_btn_pr); lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_TGL_REL, &style_tv_btn_rel); lv_tabview_set_style(tv, LV_TABVIEW_STYLE_BTN_TGL_PR, &style_tv_btn_pr); write_create(tab1); list_create(tab2); chart_create(tab3); #if LV_DEMO_SLIDE_SHOW lv_task_create(tab_switcher, 3000, LV_TASK_PRIO_MID, tv); #endif }
/** * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON) * @param indev pointer to an input device * @param cur_obj pointer to an object to be used as cursor */ void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj) { if(indev->driver.type != LV_INDEV_TYPE_POINTER) return; indev->cursor = cur_obj; lv_obj_set_parent(indev->cursor, lv_layer_sys()); lv_obj_set_pos(indev->cursor, indev->proc.act_point.x, indev->proc.act_point.y); }
/** * Signal function of the page * @param page pointer to a page object * @param sign a signal type from lv_signal_t enum * @param param pointer to a signal specific variable * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted */ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) { lv_res_t res; /* Include the ancient signal function */ res = ancestor_signal(page, sign, param); if(res != LV_RES_OK) return res; lv_page_ext_t * ext = lv_obj_get_ext_attr(page); lv_style_t * style = lv_obj_get_style(page); lv_obj_t * child; if(sign == LV_SIGNAL_CHILD_CHG) { /*Automatically move children to the scrollable object*/ child = lv_obj_get_child(page, NULL); while(child != NULL) { if(lv_obj_is_protected(child, LV_PROTECT_PARENT) == false) { lv_obj_t * tmp = child; child = lv_obj_get_child(page, child); /*Get the next child before move this*/ lv_obj_set_parent(tmp, ext->scrl); } else { child = lv_obj_get_child(page, child); } } } else if(sign == LV_SIGNAL_STYLE_CHG) { /*If no hor_fit enabled set the scrollable's width to the page's width*/ if(lv_cont_get_hor_fit(ext->scrl) == false) { lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor); } else { ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); } /*The scrollbars are important only if they are visible now*/ if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page); /*Refresh the ext. size because the scrollbars might be positioned out of the page*/ lv_obj_refresh_ext_size(page); } else if(sign == LV_SIGNAL_CORD_CHG) { /*Refresh the scrollbar and notify the scrl if the size is changed*/ if(ext->scrl != NULL && (lv_obj_get_width(page) != lv_area_get_width(param) || lv_obj_get_height(page) != lv_area_get_height(param))) { /*If no hor_fit enabled set the scrollable's width to the page's width*/ if(lv_cont_get_hor_fit(ext->scrl) == false) { lv_obj_set_width(ext->scrl, lv_obj_get_width(page) - 2 * style->body.padding.hor); } ext->scrl->signal_func(ext->scrl, LV_SIGNAL_CORD_CHG, &ext->scrl->coords); /*The scrollbars are important only if they are visible now*/ if(ext->sb.hor_draw || ext->sb.ver_draw) lv_page_sb_refresh(page); } } else if(sign == LV_SIGNAL_PRESSED) { if(ext->pr_action != NULL) { ext->pr_action(page); } } else if(sign == LV_SIGNAL_RELEASED) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(ext->rel_action != NULL) { ext->rel_action(page); } } } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { /*Ensure ext. size for the scrollbars if they are out of the page*/ if(page->ext_size < (-ext->sb.style->body.padding.hor)) page->ext_size = -ext->sb.style->body.padding.hor; if(page->ext_size < (-ext->sb.style->body.padding.ver)) page->ext_size = -ext->sb.style->body.padding.ver; } else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ if(buf->type[i] == NULL) break; } buf->type[i] = "lv_page"; } return res; }