static void list_create(lv_obj_t *parent) { lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit); lv_page_set_style(parent, LV_PAGE_STYLE_SCRL, &lv_style_transp_fit); lv_page_set_scrl_fit(parent, false, false); lv_page_set_scrl_height(parent, lv_obj_get_height(parent)); lv_page_set_sb_mode(parent, LV_SB_MODE_OFF); /*Create styles for the buttons*/ static lv_style_t style_btn_rel; static lv_style_t style_btn_pr; lv_style_copy(&style_btn_rel, &lv_style_btn_rel); style_btn_rel.body.main_color = LV_COLOR_HEX3(0x333); style_btn_rel.body.grad_color = LV_COLOR_BLACK; style_btn_rel.body.border.color = LV_COLOR_SILVER; style_btn_rel.body.border.width = 1; style_btn_rel.body.border.opa = LV_OPA_50; style_btn_rel.body.radius = 0; lv_style_copy(&style_btn_pr, &style_btn_rel); style_btn_pr.body.main_color = LV_COLOR_MAKE(0x55, 0x96, 0xd8); style_btn_pr.body.grad_color = LV_COLOR_MAKE(0x37, 0x62, 0x90); style_btn_pr.text.color = LV_COLOR_MAKE(0xbb, 0xd5, 0xf1); lv_obj_t *list = lv_list_create(parent, NULL); lv_obj_set_height(list, 2 * lv_obj_get_height(parent) / 3); lv_list_set_style(list, LV_LIST_STYLE_BG, &lv_style_transp_tight); lv_list_set_style(list, LV_LIST_STYLE_SCRL, &lv_style_transp_tight); lv_list_set_style(list, LV_LIST_STYLE_BTN_REL, &style_btn_rel); lv_list_set_style(list, LV_LIST_STYLE_BTN_PR, &style_btn_pr); lv_obj_align(list, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 4); lv_list_add(list, SYMBOL_FILE, "New", list_btn_action); lv_list_add(list, SYMBOL_DIRECTORY, "Open", list_btn_action); lv_list_add(list, SYMBOL_TRASH, "Delete", list_btn_action); lv_list_add(list, SYMBOL_EDIT, "Edit", list_btn_action); lv_list_add(list, SYMBOL_SAVE, "Save", list_btn_action); lv_list_add(list, SYMBOL_WIFI, "WiFi", list_btn_action); lv_list_add(list, SYMBOL_GPS, "GPS", list_btn_action); lv_obj_t *mbox= lv_mbox_create(parent, NULL); lv_mbox_set_text(mbox, "Click a button to copy its text to the Text area "); lv_obj_set_width(mbox, LV_HOR_RES - LV_DPI); static const char * mbox_btns[] = {"Got it", ""}; lv_mbox_add_btns(mbox, mbox_btns, NULL); /*The default action is close*/ lv_obj_align(mbox, parent, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 2); }
static void write_create(lv_obj_t *parent) { lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit); lv_page_set_style(parent, LV_PAGE_STYLE_SCRL, &lv_style_transp_fit); lv_page_set_sb_mode(parent, LV_SB_MODE_OFF); static lv_style_t style_ta; lv_style_copy(&style_ta, &lv_style_pretty); style_ta.body.opa = LV_OPA_30; style_ta.body.radius = 0; style_ta.text.color = LV_COLOR_HEX3(0x222); ta = lv_ta_create(parent, NULL); lv_obj_set_size(ta, lv_page_get_scrl_width(parent), lv_obj_get_height(parent) / 2); lv_ta_set_style(ta, LV_TA_STYLE_BG, &style_ta); lv_ta_set_text(ta, ""); lv_page_set_rel_action(ta, keyboard_open_close); lv_style_copy(&style_kb, &lv_style_plain); style_kb.body.opa = LV_OPA_70; style_kb.body.main_color = LV_COLOR_HEX3(0x333); style_kb.body.grad_color = LV_COLOR_HEX3(0x333); style_kb.body.padding.hor = 0; style_kb.body.padding.ver = 0; style_kb.body.padding.inner = 0; lv_style_copy(&style_kb_rel, &lv_style_plain); style_kb_rel.body.empty = 1; style_kb_rel.body.radius = 0; style_kb_rel.body.border.width = 1; style_kb_rel.body.border.color = LV_COLOR_SILVER; style_kb_rel.body.border.opa = LV_OPA_50; style_kb_rel.body.main_color = LV_COLOR_HEX3(0x333); /*Recommended if LV_VDB_SIZE == 0 and bpp > 1 fonts are used*/ style_kb_rel.body.grad_color = LV_COLOR_HEX3(0x333); style_kb_rel.text.color = LV_COLOR_WHITE; lv_style_copy(&style_kb_pr, &lv_style_plain); style_kb_pr.body.radius = 0; style_kb_pr.body.opa = LV_OPA_50; style_kb_pr.body.main_color = LV_COLOR_WHITE; style_kb_pr.body.grad_color = LV_COLOR_WHITE; style_kb_pr.body.border.width = 1; style_kb_pr.body.border.color = LV_COLOR_SILVER; keyboard_open_close(ta); }
/** * Set a style of a drop down list * @param ddlist pointer to a drop down list object * @param type which style should be set * @param style pointer to a style */ void lv_ddlist_set_style(lv_obj_t *ddlist, lv_ddlist_style_t type, lv_style_t *style) { lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); switch (type) { case LV_DDLIST_STYLE_BG: lv_page_set_style(ddlist, LV_PAGE_STYLE_BG, style); break; case LV_DDLIST_STYLE_SB: lv_page_set_style(ddlist, LV_PAGE_STYLE_SB, style); break; case LV_DDLIST_STYLE_SEL: ext->sel_style = style; lv_obj_t *scrl = lv_page_get_scrl(ddlist); lv_obj_refresh_ext_size(scrl); /*Because of the wider selected rectangle*/ break; } }
static void chart_create(lv_obj_t *parent) { lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit); lv_page_set_style(parent, LV_PAGE_STYLE_SCRL, &lv_style_transp_fit); lv_page_set_scrl_fit(parent, false, false); lv_page_set_scrl_height(parent, lv_obj_get_height(parent)); lv_page_set_sb_mode(parent, LV_SB_MODE_OFF); static lv_style_t style_chart; lv_style_copy(&style_chart, &lv_style_pretty); style_chart.body.opa = LV_OPA_60; style_chart.body.radius = 0; style_chart.line.color = LV_COLOR_GRAY; chart = lv_chart_create(parent, NULL); lv_obj_set_size(chart, 2 * lv_obj_get_width(parent) / 3, lv_obj_get_height(parent) / 2); lv_obj_align(chart, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 4); lv_chart_set_type(chart, LV_CHART_TYPE_COLUMN); lv_chart_set_style(chart, &style_chart); lv_chart_set_series_opa(chart, LV_OPA_70); lv_chart_series_t *ser1; ser1 = lv_chart_add_series(chart, LV_COLOR_RED); lv_chart_set_next(chart, ser1, 40); lv_chart_set_next(chart, ser1, 30); lv_chart_set_next(chart, ser1, 47); lv_chart_set_next(chart, ser1, 59); lv_chart_set_next(chart, ser1, 59); lv_chart_set_next(chart, ser1, 31); lv_chart_set_next(chart, ser1, 55); lv_chart_set_next(chart, ser1, 70); lv_chart_set_next(chart, ser1, 82); /*Create a bar, an indicator and a knob style*/ static lv_style_t style_bar; static lv_style_t style_indic; static lv_style_t style_knob; lv_style_copy(&style_bar, &lv_style_pretty); style_bar.body.main_color = LV_COLOR_BLACK; style_bar.body.grad_color = LV_COLOR_GRAY; style_bar.body.radius = LV_RADIUS_CIRCLE; style_bar.body.border.color = LV_COLOR_WHITE; style_bar.body.opa = LV_OPA_60; style_bar.body.padding.hor = 0; style_bar.body.padding.ver = LV_DPI / 10; lv_style_copy(&style_indic, &lv_style_pretty); style_indic.body.grad_color = LV_COLOR_MARRON; style_indic.body.main_color = LV_COLOR_RED; style_indic.body.radius = LV_RADIUS_CIRCLE; style_indic.body.shadow.width = LV_DPI / 10; style_indic.body.shadow.color = LV_COLOR_RED; style_indic.body.padding.hor = LV_DPI / 30; style_indic.body.padding.ver = LV_DPI / 30; lv_style_copy(&style_knob, &lv_style_pretty); style_knob.body.radius = LV_RADIUS_CIRCLE; style_knob.body.opa = LV_OPA_70; /*Create a second slider*/ lv_obj_t *slider = lv_slider_create(parent, NULL); lv_slider_set_style(slider, LV_SLIDER_STYLE_BG, &style_bar); lv_slider_set_style(slider, LV_SLIDER_STYLE_INDIC, &style_indic); lv_slider_set_style(slider, LV_SLIDER_STYLE_KNOB, &style_knob); lv_obj_set_size(slider, lv_obj_get_width(chart), LV_DPI / 3); lv_obj_align(slider, chart, LV_ALIGN_OUT_BOTTOM_MID, 0, (LV_VER_RES - chart->coords.y2 - lv_obj_get_height(slider)) / 2); /*Align to below the chart*/ lv_slider_set_action(slider, slider_action); lv_slider_set_range(slider, 10, 1000); lv_slider_set_value(slider, 700); slider_action(slider); /*Simulate a user value set the refresh the chart*/ }
/** * Create a drop down list objects * @param par pointer to an object, it will be the parent of the new drop down list * @param copy pointer to a drop down list object, if not NULL then the new object will be copied from it * @return pointer to the created drop down list */ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor drop down list*/ lv_obj_t * new_ddlist = lv_page_create(par, copy); lv_mem_assert(new_ddlist); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_ddlist); if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_ddlist)); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_ddlist); /*Allocate the drop down list type specific extended data*/ lv_ddlist_ext_t * ext = lv_obj_allocate_ext_attr(new_ddlist, sizeof(lv_ddlist_ext_t)); lv_mem_assert(ext); /*Initialize the allocated 'ext' */ ext->label = NULL; ext->action = NULL; ext->opened = 0; ext->fix_height = 0; ext->sel_opt_id = 0; ext->sel_opt_id_ori = 0; ext->option_cnt = 0; ext->anim_time = LV_DDLIST_ANIM_TIME; ext->sel_style = &lv_style_plain_color; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_ddlist, lv_ddlist_signal); lv_obj_set_signal_func(lv_page_get_scrl(new_ddlist), lv_ddlist_scrl_signal); lv_obj_set_design_func(new_ddlist, lv_ddlist_design); /*Init the new drop down list drop down list*/ if(copy == NULL) { lv_obj_t * scrl = lv_page_get_scrl(new_ddlist); lv_obj_set_drag(scrl, false); lv_page_set_scrl_fit(new_ddlist, true, true); ext->label = lv_label_create(new_ddlist, NULL); lv_cont_set_fit(new_ddlist, true, false); lv_page_set_rel_action(new_ddlist, lv_ddlist_release_action); lv_page_set_sb_mode(new_ddlist, LV_SB_MODE_DRAG); lv_page_set_style(new_ddlist, LV_PAGE_STYLE_SCRL, &lv_style_transp_tight); lv_ddlist_set_options(new_ddlist, "Option 1\nOption 2\nOption 3"); /*Set the default styles*/ lv_theme_t *th = lv_theme_get_current(); if(th) { lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, th->ddlist.bg); lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL,th->ddlist.sel); lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, th->ddlist.sb); } else { lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_BG, &lv_style_pretty); lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SEL, &lv_style_plain_color); lv_ddlist_set_style(new_ddlist, LV_DDLIST_STYLE_SB, &lv_style_pretty_color); } } /*Copy an existing drop down list*/ else { lv_ddlist_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->label = lv_label_create(new_ddlist, copy_ext->label); lv_label_set_text(ext->label, lv_label_get_text(copy_ext->label)); ext->sel_opt_id = copy_ext->sel_opt_id; ext->fix_height = copy_ext->fix_height; ext->action = copy_ext->action; ext->option_cnt = copy_ext->option_cnt; ext->sel_style = copy_ext->sel_style; ext->anim_time = copy_ext->anim_time; /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_ddlist); } return new_ddlist; }
/** * Create tab views to test their functionalities */ void lv_test_tabview_1(void) { /* Default object. It will be an empty tab view*/ lv_obj_t *tv1 = lv_tabview_create(lv_scr_act(), NULL); lv_tabview_add_tab(tv1, "First"); lv_tabview_add_tab(tv1, "Second"); lv_obj_set_size(tv1, LV_HOR_RES / 2 - 10, LV_VER_RES / 2 - 10); /*Copy the first tabview and add some texts*/ lv_obj_t *tv2 = lv_tabview_create(lv_scr_act(), tv1); lv_obj_align(tv2, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0); lv_obj_t *tab = lv_tabview_get_tab(tv2, 0); lv_obj_t *label = lv_label_create(tab, NULL); lv_label_set_text(label, "This is\n\n\nA long text\n\n\ntext\n\n\non the\n\n\nsecond\n\n\ntab\n\n\nto see\n\n\nthe scrolling"); tab = lv_tabview_get_tab(tv2, 1); label = lv_label_create(tab, NULL); lv_label_set_text(label, "This is the second tab"); /*Create styles*/ static lv_style_t bg; static lv_style_t sb; static lv_style_t btns_bg; static lv_style_t tab_bg; static lv_style_t rel; static lv_style_t pr; static lv_style_t tgl_rel; static lv_style_t tgl_pr; static lv_style_t indic; lv_style_copy(&btns_bg, &lv_style_plain_color); lv_style_copy(&tab_bg, &lv_style_pretty_color); lv_style_copy(&bg, &lv_style_pretty_color); lv_style_copy(&sb, &lv_style_pretty); lv_style_copy(&btns_bg, &lv_style_transp_fit); lv_style_copy(&rel, &lv_style_plain); lv_style_copy(&pr, &lv_style_plain); lv_style_copy(&tgl_rel, &lv_style_plain); lv_style_copy(&tgl_pr, &lv_style_plain); lv_style_copy(&indic, &lv_style_plain); rel.body.main_color = LV_COLOR_SILVER; pr.body.main_color = LV_COLOR_GRAY; tgl_rel.body.main_color = LV_COLOR_RED; tgl_pr.body.main_color = LV_COLOR_MARRON; indic.body.main_color = LV_COLOR_ORANGE; indic.body.grad_color = LV_COLOR_ORANGE; indic.body.padding.inner = LV_DPI / 16; tab_bg.body.main_color = LV_COLOR_SILVER; tab_bg.body.grad_color = LV_COLOR_GREEN; tab_bg.text.color = LV_COLOR_YELLOW; /*Apply the styles*/ lv_obj_t *tv3 = lv_tabview_create(lv_scr_act(), tv2); lv_obj_align(tv3, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); lv_tabview_set_style(tv3, LV_TABVIEW_STYLE_BG, &bg); lv_tabview_set_style(tv3, LV_TABVIEW_STYLE_BTN_BG, &btns_bg); lv_tabview_set_style(tv3, LV_TABVIEW_STYLE_BTN_REL, &rel); lv_tabview_set_style(tv3, LV_TABVIEW_STYLE_BTN_PR, &pr); lv_tabview_set_style(tv3, LV_TABVIEW_STYLE_BTN_TGL_REL, &tgl_rel); lv_tabview_set_style(tv3, LV_TABVIEW_STYLE_BTN_TGL_PR, &tgl_pr); lv_tabview_set_style(tv3, LV_TABVIEW_STYLE_INDIC, &indic); tab = lv_tabview_get_tab(tv3, 0); lv_page_set_style(tab, LV_PAGE_STYLE_BG, &tab_bg); lv_page_set_style(tab, LV_PAGE_STYLE_SB, &sb); label = lv_label_create(tab, NULL); lv_label_set_text(label, "This is\n\n\nA long text\n\n\ntext\n\n\non the\n\n\nsecond\n\n\ntab\n\n\nto see\n\n\nthe scrolling"); tab = lv_tabview_get_tab(tv3, 1); label = lv_label_create(tab, NULL); lv_label_set_text(label, "This is the second tab"); /*Copy the styles tab view*/ lv_obj_t *tv4 = lv_tabview_create(lv_scr_act(), tv3); lv_obj_align(tv4, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); }
/** * Create a page objects * @param par pointer to an object, it will be the parent of the new page * @param copy pointer to a page object, if not NULL then the new object will be copied from it * @return pointer to the created page */ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor object*/ lv_obj_t * new_page = lv_cont_create(par, copy); lv_mem_assert(new_page); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_page); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_page); /*Allocate the object type specific extended data*/ lv_page_ext_t * ext = lv_obj_allocate_ext_attr(new_page, sizeof(lv_page_ext_t)); lv_mem_assert(ext); ext->scrl = NULL; ext->pr_action = NULL; ext->rel_action = NULL; ext->sb.hor_draw = 0; ext->sb.ver_draw = 0; ext->sb.style = &lv_style_pretty; ext->sb.mode = LV_SB_MODE_AUTO; /*Init the new page object*/ if(copy == NULL) { ext->scrl = lv_cont_create(new_page, NULL); lv_obj_set_signal_func(ext->scrl, lv_page_scrollable_signal); lv_obj_set_design_func(ext->scrl, lv_scrl_design); lv_obj_set_drag(ext->scrl, true); lv_obj_set_drag_throw(ext->scrl, true); lv_obj_set_protect(ext->scrl, LV_PROTECT_PARENT | LV_PROTECT_PRESS_LOST); lv_cont_set_fit(ext->scrl, false, true); /* Add the signal function only if 'scrolling' is created * because everything has to be ready before any signal is received*/ lv_obj_set_signal_func(new_page, lv_page_signal); lv_obj_set_design_func(new_page, lv_page_design); lv_page_set_sb_mode(new_page, ext->sb.mode); /*Set the default styles*/ lv_theme_t *th = lv_theme_get_current(); if(th) { if(par == NULL){ /*Different styles if it is screen*/ lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->bg); lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_transp); } else { lv_page_set_style(new_page, LV_PAGE_STYLE_BG, th->page.bg); lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, th->page.scrl); } lv_page_set_style(new_page, LV_PAGE_STYLE_SB, th->page.sb); } else { lv_page_set_style(new_page, LV_PAGE_STYLE_BG, &lv_style_pretty_color); lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, &lv_style_pretty); lv_page_set_style(new_page, LV_PAGE_STYLE_SB, &lv_style_pretty_color); } } else { lv_page_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->scrl = lv_cont_create(new_page, copy_ext->scrl); lv_obj_set_signal_func(ext->scrl, lv_page_scrollable_signal); lv_page_set_pr_action(new_page, copy_ext->pr_action); lv_page_set_rel_action(new_page, copy_ext->rel_action); lv_page_set_sb_mode(new_page, copy_ext->sb.mode); lv_page_set_style(new_page, LV_PAGE_STYLE_BG, lv_page_get_style(copy, LV_PAGE_STYLE_BG)); lv_page_set_style(new_page, LV_PAGE_STYLE_SCRL, lv_page_get_style(copy, LV_PAGE_STYLE_SCRL)); lv_page_set_style(new_page, LV_PAGE_STYLE_SB, lv_page_get_style(copy, LV_PAGE_STYLE_SB)); /* Add the signal function only if 'scrolling' is created * because everything has to be ready before any signal is received*/ lv_obj_set_signal_func(new_page, lv_page_signal); lv_obj_set_design_func(new_page, lv_page_design); /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_page); } lv_page_sb_refresh(new_page); return new_page; }