From 35c7197d1c059964407891aba20e7fa8662167ed Mon Sep 17 00:00:00 2001 From: tgillbe Date: Fri, 4 Sep 2020 12:30:39 +0100 Subject: [PATCH] Fix button matrix button width (#1768) --- CHANGELOG.md | 1 + src/lv_widgets/lv_btnmatrix.c | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f46572f8a..d37c77706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugfixes - Fix unexpeted DEFOCUS on lv_page when clicking to bg after the scrollable - Fix `lv_obj_del` and `lv_obj_clean` if the children list changed during deletion. +- Adjust button matrix button width to include padding when spanning multiple units. ## v7.4.0 (01.09.2020) diff --git a/src/lv_widgets/lv_btnmatrix.c b/src/lv_widgets/lv_btnmatrix.c index 9f39dd638..d4a4a5c59 100644 --- a/src/lv_widgets/lv_btnmatrix.c +++ b/src/lv_widgets/lv_btnmatrix.c @@ -208,7 +208,7 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[]) /*Only deal with the non empty lines*/ if(btn_cnt != 0) { /*Calculate the width of all units*/ - lv_coord_t all_unit_w = max_w - ((btn_cnt - 1) * inner); + lv_coord_t all_unit_w = max_w - ((unit_cnt - 1) * inner); /*Set the button size and positions and set the texts*/ uint16_t i; @@ -216,19 +216,20 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[]) unit_act_cnt = 0; for(i = 0; i < btn_cnt; i++) { + uint8_t btn_unit_w = get_button_width(ext->ctrl_bits[btn_i]); /* one_unit_w = all_unit_w / unit_cnt * act_unit_w = one_unit_w * button_width * do this two operations but the multiply first to divide a greater number */ - lv_coord_t act_unit_w = (all_unit_w * get_button_width(ext->ctrl_bits[btn_i])) / unit_cnt; + lv_coord_t act_unit_w = (all_unit_w * btn_unit_w) / unit_cnt + inner * (btn_unit_w - 1); act_unit_w--; /*-1 because e.g. width = 100 means 101 pixels (0..100)*/ /*Always recalculate act_x because of rounding errors */ if(base_dir == LV_BIDI_DIR_RTL) { - act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner; + act_x = (unit_act_cnt * all_unit_w) / unit_cnt + unit_act_cnt * inner; act_x = lv_obj_get_width(btnm) - right - act_x - act_unit_w - 1; } else { - act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner + + act_x = (unit_act_cnt * all_unit_w) / unit_cnt + unit_act_cnt * inner + left; } /* Set the button's area. @@ -243,7 +244,7 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[]) lv_area_set(&ext->button_areas[btn_i], act_x, act_y, act_x + act_unit_w, act_y + btn_h); } - unit_act_cnt += get_button_width(ext->ctrl_bits[btn_i]); + unit_act_cnt += btn_unit_w; i_tot++; btn_i++;