/** * 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; }
/********************** * STATIC FUNCTIONS **********************/ static void create_tab1(lv_theme_t * th, lv_obj_t *parent) { lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); static lv_style_t h_style; lv_style_copy(&h_style, &lv_style_transp); h_style.body.padding.inner = LV_DPI / 4; h_style.body.padding.hor = LV_DPI / 4; h_style.body.padding.ver = LV_DPI / 6; lv_obj_t *h = lv_cont_create(parent, NULL); lv_obj_set_style(h, &h_style); lv_obj_set_click(h, false); lv_cont_set_fit(h, true, true); lv_cont_set_layout(h, LV_LAYOUT_COL_M); lv_obj_t *btn = lv_btn_create(h, NULL); lv_btn_set_style(btn, LV_BTN_STYLE_REL, th->btn.rel); lv_btn_set_style(btn, LV_BTN_STYLE_PR, th->btn.pr); lv_btn_set_style(btn, LV_BTN_STYLE_TGL_REL, th->btn.tgl_rel); lv_btn_set_style(btn, LV_BTN_STYLE_TGL_PR, th->btn.tgl_pr); lv_btn_set_style(btn, LV_BTN_STYLE_INA, th->btn.ina); lv_btn_set_fit(btn, true, true); lv_btn_set_toggle(btn, true); lv_obj_t *btn_label = lv_label_create(btn, NULL); lv_label_set_text(btn_label, "Button"); btn = lv_btn_create(h, btn); lv_btn_toggle(btn); btn_label = lv_label_create(btn, NULL); lv_label_set_text(btn_label, "Toggled"); btn = lv_btn_create(h, btn); lv_btn_set_state(btn, LV_BTN_STATE_INA); btn_label = lv_label_create(btn, NULL); lv_label_set_text(btn_label, "Inactive"); lv_obj_t *label = lv_label_create(h, NULL); lv_label_set_text(label, "Primary"); lv_obj_set_style(label, th->label.prim); label = lv_label_create(h, NULL); lv_label_set_text(label, "Secondary"); lv_obj_set_style(label, th->label.sec); label = lv_label_create(h, NULL); lv_label_set_text(label, "Hint"); lv_obj_set_style(label, th->label.hint); static const char *btnm_str[] = {"1", "2", "3", SYMBOL_OK, SYMBOL_CLOSE, ""}; lv_obj_t *btnm = lv_btnm_create(h, NULL); lv_obj_set_size(btnm,LV_HOR_RES / 4, 2 * LV_DPI / 3); lv_btnm_set_map(btnm, btnm_str); lv_btnm_set_toggle(btnm, true, 3); h = lv_cont_create(parent, h); lv_obj_t *sw_h = lv_cont_create(h, NULL); lv_cont_set_style(sw_h, &lv_style_transp); lv_cont_set_fit(sw_h, false, true); lv_obj_set_width(sw_h, LV_HOR_RES / 4); lv_cont_set_layout(sw_h, LV_LAYOUT_PRETTY); lv_obj_t *sw = lv_sw_create(sw_h, NULL); sw = lv_sw_create(sw_h, sw); lv_sw_on(sw); lv_obj_t *bar = lv_bar_create(h, NULL); lv_bar_set_value(bar, 70); lv_obj_t *slider = lv_slider_create(h, NULL); lv_bar_set_value(slider, 70); lv_obj_t *line = lv_line_create(h, NULL); static const lv_point_t line_p[] = {{0,0},{LV_HOR_RES / 5, 0}}; lv_line_set_points(line, line_p, 2); lv_line_set_style(line, th->line.decor); lv_obj_t *ta = lv_ta_create(h, NULL); lv_obj_set_style(ta, th->ta.oneline); lv_ta_set_text(ta, "Some text"); lv_ta_set_one_line(ta, true); lv_obj_t *cb = lv_cb_create(h, NULL); cb = lv_cb_create(h, cb); lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL); lv_obj_t *ddlist = lv_ddlist_create(h, NULL); lv_ddlist_open(ddlist, false); lv_ddlist_set_selected(ddlist, 1); h = lv_cont_create(parent, h); lv_obj_t * list = lv_list_create(h, NULL); lv_obj_t *list_btn; list_btn = lv_list_add(list, SYMBOL_GPS, "GPS", NULL); lv_obj_set_size(list, LV_HOR_RES / 4, LV_VER_RES / 2); lv_btn_set_toggle(list_btn, true); lv_list_add(list, SYMBOL_WIFI, "WiFi", NULL); lv_list_add(list, SYMBOL_GPS, "GPS", NULL); lv_list_add(list, SYMBOL_AUDIO, "Audio", NULL); lv_list_add(list, SYMBOL_VIDEO, "Video", NULL); lv_list_add(list, SYMBOL_CALL, "Call", NULL); lv_list_add(list, SYMBOL_BELL, "Bell", NULL); lv_list_add(list, SYMBOL_FILE, "File", NULL); lv_list_add(list, SYMBOL_EDIT, "Edit", NULL); lv_list_add(list, SYMBOL_CUT, "Cut", NULL); lv_list_add(list, SYMBOL_COPY, "Copy", NULL); lv_obj_t *roller = lv_roller_create(h, NULL); lv_roller_set_options(roller, "Monday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\nSunday"); lv_roller_set_selected(roller, 1, false); lv_roller_set_visible_row_count(roller, 3); }