How to uncheck all buttons in button matrix or Tabview

Hi @Zebra067 ,

The states are represented by ‘bits’ so the value of ‘BOD’ can represent multiple states at any point in time, so the value 0x0022 for example means the object is both ‘focused’ and ‘pressed’ at the same time. Does that make sense?

I would change the logic of your event callback to something like this:

static void 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);

    lv_state_t BOD = lv_obj_get_state(obj);
    uint32_t id = lv_btnmatrix_get_selected_btn(obj);
    const char * txt = lv_btnmatrix_get_btn_text(obj, id);

	if(code == LV_EVENT_VALUE_CHANGED)
	{

		if( BOD & LV_STATE_CHECKED ) LV_LOG_USER(" %s LV_STATE_CHECKED" ,txt);
		if( BOD & LV_STATE_FOCUSED ) LV_LOG_USER(" %s LV_STATE_FOCUSED",txt);
		if( BOD & LV_STATE_DEFAULT ) LV_LOG_USER(" %s LV_STATE_DEFAULT",txt);
		if( BOD & LV_STATE_FOCUS_KEY ) LV_LOG_USER( " %s LV_STATE_FOCUS_KEY",txt);
		if( BOD & LV_STATE_EDITED ) LV_LOG_USER( " %s LV_STATE_EDITED",txt);
		if( BOD & LV_STATE_HOVERED ) LV_LOG_USER( " %s LV_STATE_HOVERED",txt);
		if( BOD & LV_STATE_PRESSED ) LV_LOG_USER( " %s LV_STATE_PRESSED ",txt);
		if( BOD & LV_STATE_DISABLED ) LV_LOG_USER( " %s LV_STATE_DISABLED",txt);
		if( BOD & LV_STATE_SCROLLED ) LV_LOG_USER( " %s LV_STATE_SCROLLED",txt);
	}
}

I think if you combine this logic change with the answer here from @kisvegabor on your other post, you should be able to achieve you goals.

I hope that helps.

Kind Regards,

Pete

1 Like