1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-02-04 07:13:00 +08:00

fix(btnmatrix): Hide button matrix when all buttons hidden

Makes sure the focus behaves correctly when all button matrix buttons
have been hidden.
This commit is contained in:
PeterB 2023-07-12 13:02:15 +01:00
parent b1bbb95ceb
commit 65f1c9305e

View File

@ -208,7 +208,7 @@ void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctr
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;;
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return;
@ -216,6 +216,17 @@ void lv_btnmatrix_set_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_ctr
lv_btnmatrix_clear_btn_ctrl_all(obj, LV_BTNMATRIX_CTRL_CHECKED);
}
/* If we hide a button if all buttons are now hidden hide the whole button matrix to make focus behave correctly */
if(ctrl & LV_BTNMATRIX_CTRL_HIDDEN) {
bool all_buttons_hidden = true;
if(btnm->btn_cnt > 1);
for(uint16_t btn_idx = 0; btn_idx < btnm->btn_cnt; btn_idx++) {
if(btn_idx == btn_id) continue;
if(!(btnm->ctrl_bits[btn_idx] & LV_BTNMATRIX_CTRL_HIDDEN)) all_buttons_hidden = false;
}
if(all_buttons_hidden) lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);
}
btnm->ctrl_bits[btn_id] |= ctrl;
invalidate_button_area(obj, btn_id);
@ -228,10 +239,15 @@ void lv_btnmatrix_clear_btn_ctrl(lv_obj_t * obj, uint16_t btn_id, lv_btnmatrix_c
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;;
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
if(btn_id >= btnm->btn_cnt) return;
/* If all buttons were hidden the whole button matrix is hidden so we need to check and remove hidden flag if present */
if(ctrl & LV_BTNMATRIX_CTRL_HIDDEN) {
if(lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN)) lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN);
}
btnm->ctrl_bits[btn_id] &= (~ctrl);
invalidate_button_area(obj, btn_id);