//创建一个点击的图片
lv_obj_t*customize_pic = lv_img_create(scr_Coffee_Data);
lv_img_set_src(customize_pic, &customize0);
lv_obj_set_pos(customize_pic, 739, 180);
lv_obj_set_ext_click_area(customize_pic, 20);
lv_obj_add_flag(customize_pic, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(customize_pic, customize_pic_click, LV_EVENT_CLICKED, NULL);
//创建一个滑动条
slider_grind = lv_slider_create(Custom_set_bg); lv_obj_set_size(slider_grind, 440, 4); lv_obj_set_pos(slider_grind, 207, 143); lv_obj_set_style_bg_color(slider_grind, lv_color_hex(0x929292), 0); lv_obj_set_style_bg_opa(slider_grind, 0, 0);
lv_obj_set_style_bg_color(slider_grind, lv_color_hex(0xffffff), LV_PART_INDICATOR | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(slider_grind, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT);
lv_obj_set_style_bg_color(slider_grind, lv_color_hex(0xffffff), LV_PART_KNOB | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(slider_grind, 255, LV_PART_KNOB | LV_STATE_DEFAULT);
lv_obj_set_style_radius(slider_grind, 50, LV_PART_KNOB | LV_STATE_DEFAULT);
lv_obj_set_style_pad_all(slider_grind, 8, LV_PART_KNOB | LV_STATE_DEFAULT);
lv_obj_set_ext_click_area(slider_grind, 20);
lv_obj_add_flag(slider_grind, LV_OBJ_FLAG_ADV_HITTEST);//取消点击,只可以滑动
lv_slider_set_range(slider_grind, 1, 30);//最小和最大值
lv_slider_set_value(slider_grind, set_send2[btn_mode], false);//值
lv_obj_add_event_cb(slider_grind, slider_grind_click, LV_EVENT_DRAW_PART_END, NULL);
//动画调用
static void anim_y_cb(void* var, int32_t v)
{
lv_obj_set_y(var, v);
}
static void start_tou_anim(int32_t start, int32_t end, int32_t start1, int32_t end1)
{
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, Custom_set_bg);
lv_anim_set_time(&a, 450);
lv_anim_set_exec_cb(&a, anim_y_cb);
lv_anim_set_values(&a, start, end);
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
lv_anim_start(&a);
}
//点击图片事件
static void customize_pic_click(lv_event_t* event)
{
start_tou_anim(480, 220, 0, 100);
}
//滑动条绘制事件 ,这个事件在动画运行的过程会一直进来,请在怎么避免?
static void slider_grind_click(lv_event_t* event) { lv_obj_draw_part_dsc_t* dsc = lv_event_get_param(event); if (dsc->part != LV_PART_INDICATOR) return;
lv_obj_t* obj = lv_event_get_target(event);
lv_area_t txt_area;
if (lv_slider_get_value(obj) > 99)
txt_area.x2 = dsc->draw_area->x2 - 25;
else if (lv_slider_get_value(obj) > 9)
txt_area.x2 = dsc->draw_area->x2 - 37;
else
txt_area.x2 = dsc->draw_area->x2 - 30;
lv_label_set_text_fmt(slider_grind_label, "%d%s", lv_slider_get_value(slider_grind), "oz");
lv_obj_set_pos(slider_grind_label, txt_area.x2, 164);
}