diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c index bcc4a6ecd..985a3d1e1 100644 --- a/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c @@ -9,52 +9,58 @@ static void event_cb(lv_event_t * e) if(code == LV_EVENT_DRAW_PART_BEGIN) { lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e); - /*Change the draw descriptor the 2nd button*/ - if(dsc->id == 1) { - dsc->rect_dsc->radius = 0; - if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_BLUE, 3); - else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_BLUE); + /*When the button matrix draws the buttons...*/ + if(dsc->class_p == &lv_btnmatrix_class && dsc->type == LV_BTNMATRIX_DRAW_PART_BTN) { + /*Change the draw descriptor of the 2nd button*/ + if(dsc->id == 1) { + dsc->rect_dsc->radius = 0; + if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_BLUE, 3); + else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_BLUE); - dsc->rect_dsc->shadow_width = 6; - dsc->rect_dsc->shadow_ofs_x = 3; - dsc->rect_dsc->shadow_ofs_y = 3; - dsc->label_dsc->color = lv_color_white(); - } - /*Change the draw descriptor the 3rd button*/ - else if(dsc->id == 2) { - dsc->rect_dsc->radius = LV_RADIUS_CIRCLE; - if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_RED, 3); - else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_RED); + dsc->rect_dsc->shadow_width = 6; + dsc->rect_dsc->shadow_ofs_x = 3; + dsc->rect_dsc->shadow_ofs_y = 3; + dsc->label_dsc->color = lv_color_white(); + } + /*Change the draw descriptor of the 3rd button*/ + else if(dsc->id == 2) { + dsc->rect_dsc->radius = LV_RADIUS_CIRCLE; + if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = lv_palette_darken(LV_PALETTE_RED, 3); + else dsc->rect_dsc->bg_color = lv_palette_main(LV_PALETTE_RED); - dsc->label_dsc->color = lv_color_white(); - } - else if(dsc->id == 3) { - dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/ + dsc->label_dsc->color = lv_color_white(); + } + else if(dsc->id == 3) { + dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/ + } } } if(code == LV_EVENT_DRAW_PART_END) { lv_obj_draw_part_dsc_t * dsc = lv_event_get_draw_part_dsc(e); - /*Add custom content to the 4th button when the button itself was drawn*/ - if(dsc->id == 3) { - LV_IMG_DECLARE(img_star); - lv_img_header_t header; - lv_res_t res = lv_img_decoder_get_info(&img_star, &header); - if(res != LV_RES_OK) return; + /*When the button matrix draws the buttons...*/ + if(dsc->class_p == &lv_btnmatrix_class && dsc->type == LV_BTNMATRIX_DRAW_PART_BTN) { + /*Add custom content to the 4th button when the button itself was drawn*/ + if(dsc->id == 3) { + LV_IMG_DECLARE(img_star); + lv_img_header_t header; + lv_res_t res = lv_img_decoder_get_info(&img_star, &header); + if(res != LV_RES_OK) return; - lv_area_t a; - a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2; - a.x2 = a.x1 + header.w - 1; - a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2; - a.y2 = a.y1 + header.h - 1; + lv_area_t a; + a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2; + a.x2 = a.x1 + header.w - 1; + a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2; + a.y2 = a.y1 + header.h - 1; - lv_draw_img_dsc_t img_draw_dsc; - lv_draw_img_dsc_init(&img_draw_dsc); - img_draw_dsc.recolor = lv_color_black(); - if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30; + lv_draw_img_dsc_t img_draw_dsc; + lv_draw_img_dsc_init(&img_draw_dsc); + img_draw_dsc.recolor = lv_color_black(); + if(lv_btnmatrix_get_selected_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30; - lv_draw_img(dsc->draw_ctx, &img_draw_dsc, &a, &img_star); + lv_draw_img(dsc->draw_ctx, &img_draw_dsc, &a, &img_star); + } } } }