Skip to content

Commit

Permalink
fix(btnmatrix) always udpate row_cnt
Browse files Browse the repository at this point in the history
allocate_btn_areas_and_controls() returned very early if the same number buttuns were set
the the number fo rows can be different and is wasn't updated

fixes #2619
  • Loading branch information
kisvegabor committed Sep 29, 2021
1 parent 2a9b9e6 commit 86012ae
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/widgets/lv_btnmatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,21 +821,20 @@ static void draw_main(lv_event_t * e)
*/
static void allocate_btn_areas_and_controls(const lv_obj_t * obj, const char ** map)
{
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
btnm->row_cnt = 1;
/*Count the buttons in the map*/
uint16_t btn_cnt = 0;
uint16_t row_cnt = 1;
uint16_t i = 0;
while(map[i] && map[i][0] != '\0') {
if(strcmp(map[i], "\n") != 0) { /*Do not count line breaks*/
btn_cnt++;
} else {
row_cnt++;
btnm->row_cnt++;
}
i++;
}

lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;;

/*Do not allocate memory for the same amount of buttons*/
if(btn_cnt == btnm->btn_cnt) return;

Expand All @@ -857,7 +856,6 @@ static void allocate_btn_areas_and_controls(const lv_obj_t * obj, const char **
lv_memset_00(btnm->ctrl_bits, sizeof(lv_btnmatrix_ctrl_t) * btn_cnt);

btnm->btn_cnt = btn_cnt;
btnm->row_cnt = row_cnt;
}

/**
Expand Down

0 comments on commit 86012ae

Please sign in to comment.