Style Messagebox buttons causes outline around all buttons in the button matrix

Description

I have created a massagebox with 2 buttons, when button 0 is styles it appears around both buttons

What MCU/Processor/Board and compiler are you using?

ESP32 With Arduino

What LVGL version are you using?

8.2

What do you want to achieve?

I’d like to have each button styled but not the surrounding button matrix

What have you tried so far?

Below code, review docs

Code to reproduce

  static const char * mbox_btn_map[] = {"Reboot", "Cancel", ""};
  //mbox_wifiReboot = lv_mbox_create(obj, NULL);
  mbox_wifiReboot = lv_msgbox_create(lv_scr_act(), "Reboot", "Reboot?", mbox_btn_map, true);
  lv_obj_t * mbox_btns = lv_msgbox_get_btns(mbox_wifiReboot);
  lv_obj_add_event_cb(mbox_btns, mbox_btns_event_cb, LV_EVENT_ALL, NULL);


static void mbox_btns_event_cb(lv_event_t * e)
{
  lv_event_code_t code = lv_event_get_code(e);
  lv_obj_t * obj = lv_event_get_target(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 1st and 2nd button*/
    if(dsc->id == 0 || dsc->id == 2) 
    {
      dsc->rect_dsc->radius = LV_RADIUS_CIRCLE;
      dsc->rect_dsc->bg_color = lv_color_hex(MAIN_BG_COLOUR);
      dsc->rect_dsc->border_color = lv_color_hex(0x01a2b1);
      dsc->rect_dsc->border_width = 1;
      dsc->rect_dsc->shadow_width = 0;
    }
  }
}

Screenshot and/or video

@kisvegabor is this a bug or am I not adding a condition somewhere?
Thanks!

Hi,

It’s missing condition and it was missing from the lv_example_btnmatrix_2 too. I updated the example here: example(btnmatrix): update lv_example_btnmatrix_2 to expicitly check … · lvgl/lvgl@6b2eac1 · GitHub

Perfect!!

Thanks for the solution.
Alex

1 Like