/** * Create a roller object * @param par pointer to an object, it will be the parent of the new roller * @param copy pointer to a roller object, if not NULL then the new object will be copied from it * @return pointer to the created roller */ lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor of roller*/ lv_obj_t * new_roller = lv_ddlist_create(par, copy); lv_mem_assert(new_roller); if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_roller)); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_roller); /*Allocate the roller type specific extended data*/ lv_roller_ext_t * ext = lv_obj_allocate_ext_attr(new_roller, sizeof(lv_roller_ext_t)); lv_mem_assert(ext); /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_roller, lv_roller_signal); lv_obj_set_design_func(new_roller, lv_roller_design); /*Init the new roller roller*/ if(copy == NULL) { lv_obj_t * scrl = lv_page_get_scrl(new_roller); lv_obj_set_drag(scrl, true); /*In ddlist is might be disabled*/ lv_page_set_rel_action(new_roller, NULL); /*Roller don't uses it (like ddlist)*/ lv_page_set_scrl_fit(new_roller, true, false); /*Height is specified directly*/ lv_ddlist_open(new_roller, false); lv_ddlist_set_anim_time(new_roller, LV_ROLLER_ANIM_TIME); lv_roller_set_visible_row_count(new_roller, 3); lv_label_set_align(ext->ddlist.label, LV_LABEL_ALIGN_CENTER); lv_obj_set_signal_func(scrl, lv_roller_scrl_signal); /*Set the default styles*/ lv_theme_t *th = lv_theme_get_current(); if(th) { lv_roller_set_style(new_roller, LV_ROLLER_STYLE_BG, th->roller.bg); lv_roller_set_style(new_roller, LV_ROLLER_STYLE_SEL, th->roller.sel); } else { /*Let the ddlist's style*/ lv_obj_refresh_style(new_roller); /*To set scrollable size automatically*/ } } /*Copy an existing roller*/ else { lv_obj_t * scrl = lv_page_get_scrl(new_roller); lv_ddlist_open(new_roller, false); lv_obj_set_signal_func(scrl, lv_roller_scrl_signal); lv_obj_refresh_style(new_roller); /*Refresh the style with new signal function*/ } return new_roller; }
/** * Create a label objects * @param par pointer to an object, it will be the parent of the new label * @param copy pointer to a button object, if not NULL then the new object will be copied from it * @return pointer to the created button */ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) { /*Create a basic object*/ lv_obj_t * new_label = lv_obj_create(par, copy); lv_mem_assert(new_label); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_label); /*Extend the basic object to a label object*/ lv_obj_allocate_ext_attr(new_label, sizeof(lv_label_ext_t)); lv_label_ext_t * ext = lv_obj_get_ext_attr(new_label); lv_mem_assert(ext); ext->text = NULL; ext->static_txt = 0; ext->recolor = 0; ext->no_break = 0; ext->body_draw = 0; ext->align = LV_LABEL_ALIGN_LEFT; ext->dot_end = LV_LABEL_DOT_END_INV; ext->long_mode = LV_LABEL_LONG_EXPAND; ext->anim_speed = LV_LABEL_SCROLL_SPEED; ext->offset.x = 0; ext->offset.y = 0; lv_obj_set_design_func(new_label, lv_label_design); lv_obj_set_signal_func(new_label, lv_label_signal); /*Init the new label*/ if(copy == NULL) { lv_obj_set_click(new_label, false); lv_label_set_long_mode(new_label, LV_LABEL_LONG_EXPAND); lv_label_set_text(new_label, "Text"); lv_label_set_style(new_label, NULL); /*Inherit parent's style*/ } /*Copy 'copy' if not NULL*/ else { lv_label_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_label_set_long_mode(new_label, lv_label_get_long_mode(copy)); lv_label_set_recolor(new_label, lv_label_get_recolor(copy)); lv_label_set_body_draw(new_label, lv_label_get_body_draw(copy)); lv_label_set_align(new_label, lv_label_get_align(copy)); if(copy_ext->static_txt == 0) lv_label_set_text(new_label, lv_label_get_text(copy)); else lv_label_set_static_text(new_label, lv_label_get_text(copy)); /*In DOT mode save the text byte-to-byte because a '\0' can be in the middle*/ if(copy_ext->long_mode == LV_LABEL_LONG_DOT) { ext->text = lv_mem_realloc(ext->text, lv_mem_get_size(copy_ext->text)); memcpy(ext->text, copy_ext->text, lv_mem_get_size(copy_ext->text)); } memcpy(ext->dot_tmp, copy_ext->dot_tmp, sizeof(ext->dot_tmp)); ext->dot_end = copy_ext->dot_end; /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_label); } return new_label; }
/** * Create a gauge objects * @param par pointer to an object, it will be the parent of the new gauge * @param copy pointer to a gauge object, if not NULL then the new object will be copied from it * @return pointer to the created gauge */ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor gauge*/ lv_obj_t * new_gauge = lv_lmeter_create(par, copy); lv_mem_assert(new_gauge); /*Allocate the gauge type specific extended data*/ lv_gauge_ext_t * ext = lv_obj_allocate_ext_attr(new_gauge, sizeof(lv_gauge_ext_t)); lv_mem_assert(ext); /*Initialize the allocated 'ext' */ ext->needle_count = 0; ext->values = NULL; ext->needle_colors = NULL; ext->label_count = LV_GAUGE_DEF_LABEL_COUNT; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_gauge); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_gauge); /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_gauge, lv_gauge_signal); lv_obj_set_design_func(new_gauge, lv_gauge_design); /*Init the new gauge gauge*/ if(copy == NULL) { lv_gauge_set_scale(new_gauge, LV_GAUGE_DEF_ANGLE, LV_GAUGE_DEF_LINE_COUNT, LV_GAUGE_DEF_LABEL_COUNT); lv_gauge_set_needle_count(new_gauge, 1, NULL); lv_gauge_set_critical_value(new_gauge, 80); lv_obj_set_size(new_gauge, 2 * LV_DPI, 2 * LV_DPI); /*Set the default styles*/ lv_theme_t *th = lv_theme_get_current(); if(th) { lv_gauge_set_style(new_gauge, th->gauge); } else { lv_gauge_set_style(new_gauge, &lv_style_pretty_color); } } /*Copy an existing gauge*/ else { lv_gauge_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_gauge_set_needle_count(new_gauge, copy_ext->needle_count, copy_ext->needle_colors); uint8_t i; for(i = 0; i < ext->needle_count; i++) { ext->values[i] = copy_ext->values[i]; } ext->label_count = copy_ext->label_count; /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_gauge); } return new_gauge; }
/** * Create a switch objects * @param par pointer to an object, it will be the parent of the new switch * @param copy pointer to a switch object, if not NULL then the new object will be copied from it * @return pointer to the created switch */ lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor of switch*/ lv_obj_t * new_sw = lv_slider_create(par, copy); lv_mem_assert(new_sw); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_sw); /*Allocate the switch type specific extended data*/ lv_sw_ext_t * ext = lv_obj_allocate_ext_attr(new_sw, sizeof(lv_sw_ext_t)); lv_mem_assert(ext); /*Initialize the allocated 'ext' */ ext->changed = 0; ext->style_knob_off = ext->slider.style_knob; ext->style_knob_on = ext->slider.style_knob; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_sw, lv_sw_signal); /*Init the new switch switch*/ if(copy == NULL) { lv_slider_set_range(new_sw, 0, 1); lv_obj_set_size(new_sw, 2 * LV_DPI / 3, LV_DPI / 3); lv_slider_set_knob_in(new_sw, true); /*Set the default styles*/ lv_theme_t *th = lv_theme_get_current(); if(th) { lv_sw_set_style(new_sw, LV_SW_STYLE_BG, th->sw.bg); lv_sw_set_style(new_sw, LV_SW_STYLE_INDIC, th->sw.indic); lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_OFF, th->sw.knob_off); lv_sw_set_style(new_sw, LV_SW_STYLE_KNOB_ON, th->sw.knob_on); } else { /*Let the slider' style*/ } } /*Copy an existing switch*/ else { lv_sw_ext_t *copy_ext = lv_obj_get_ext_attr(copy); ext->style_knob_off = copy_ext->style_knob_off; ext->style_knob_on = copy_ext->style_knob_on; if(lv_sw_get_state(new_sw)) lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on); else lv_slider_set_style(new_sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off); /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_sw); } return new_sw; }
/** * Create a slider objects * @param par pointer to an object, it will be the parent of the new slider * @param copy pointer to a slider object, if not NULL then the new object will be copied from it * @return pointer to the created slider */ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor slider*/ lv_obj_t * new_slider = lv_bar_create(par, copy); lv_mem_assert(new_slider); if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_slider); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_slider); /*Allocate the slider type specific extended data*/ lv_slider_ext_t * ext = lv_obj_allocate_ext_attr(new_slider, sizeof(lv_slider_ext_t)); lv_mem_assert(ext); /*Initialize the allocated 'ext' */ ext->action = NULL; ext->drag_value = LV_SLIDER_NOT_PRESSED; ext->style_knob = &lv_style_pretty; ext->knob_in = 0; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_slider, lv_slider_signal); lv_obj_set_design_func(new_slider, lv_slider_design); /*Init the new slider slider*/ if(copy == NULL) { lv_obj_set_click(new_slider, true); lv_obj_set_protect(new_slider, LV_PROTECT_PRESS_LOST); /*Set the default styles*/ lv_theme_t *th = lv_theme_get_current(); if(th) { lv_slider_set_style(new_slider, LV_SLIDER_STYLE_BG, th->slider.bg); lv_slider_set_style(new_slider, LV_SLIDER_STYLE_INDIC, th->slider.indic); lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, th->slider.knob); } else { lv_slider_set_style(new_slider, LV_SLIDER_STYLE_KNOB, ext->style_knob); } } /*Copy an existing slider*/ else { lv_slider_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->style_knob = copy_ext->style_knob; ext->action = copy_ext->action; ext->knob_in = copy_ext->knob_in; /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_slider); } return new_slider; }
/** * Create a led objects * @param par pointer to an object, it will be the parent of the new led * @param copy pointer to a led object, if not NULL then the new object will be copied from it * @return pointer to the created led */ lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy) { LV_LOG_TRACE("led create started"); /*Create the ancestor basic object*/ lv_obj_t * new_led = lv_obj_create(par, copy); lv_mem_assert(new_led); if(new_led == NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_led); if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_led); /*Allocate the object type specific extended data*/ lv_led_ext_t * ext = lv_obj_allocate_ext_attr(new_led, sizeof(lv_led_ext_t)); lv_mem_assert(ext); if(ext == NULL) return NULL; ext->bright = LV_LED_BRIGHT_ON; lv_obj_set_signal_func(new_led, lv_led_signal); lv_obj_set_design_func(new_led, lv_led_design); /*Init the new led object*/ if(copy == NULL) { lv_obj_set_size(new_led, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF); /*Set the default styles*/ lv_theme_t * th = lv_theme_get_current(); if(th) { lv_led_set_style(new_led, th->led); } else { lv_led_set_style(new_led, &lv_style_pretty_color); } } /*Copy an existing object*/ else { lv_led_ext_t * copy_ext = lv_obj_get_ext_attr(copy); ext->bright = copy_ext->bright; /*Refresh the style with new signal function*/ lv_obj_refresh_style(new_led); } LV_LOG_INFO("led created"); return new_led; }
/** * 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 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; }