chore(observer): rename lv_button_bind_checked to lv_obj_bind_checked (#5944)
This commit is contained in:
@@ -272,14 +272,11 @@ Set an object state if an integer subject's value is not equal to a reference va
|
||||
|
||||
observer = lv_obj_bind_state_if_not_eq(obj, &subject, LV_STATE_*, ref_value);
|
||||
|
||||
Button
|
||||
------
|
||||
|
||||
Set an integer subject to 1 when a button is checked and set it 0 when unchecked.
|
||||
Set an integer subject to 1 when an object is checked and set it 0 when unchecked.
|
||||
|
||||
.. code:: c
|
||||
|
||||
observer = lv_button_bind_checked(obj, &subject);
|
||||
observer = lv_obj_bind_checked(obj, &subject);
|
||||
|
||||
Label
|
||||
-----
|
||||
|
||||
@@ -37,6 +37,8 @@ extern "C" {
|
||||
#define LV_DRAW_LAYER_SIMPLE_BUF_SIZE LV_DRAW_SW_LAYER_SIMPLE_BUF_SIZE
|
||||
#endif
|
||||
|
||||
#define lv_button_bind_checked lv_obj_bind_checked
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -34,10 +34,7 @@ static lv_observer_t * bind_to_bitfield(lv_subject_t * subject, lv_obj_t * obj,
|
||||
int32_t ref_value, bool inv);
|
||||
static void obj_flag_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
static void obj_state_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
|
||||
#if LV_USE_BUTTON
|
||||
static void btn_value_changed_event_cb(lv_event_t * e);
|
||||
#endif
|
||||
static void obj_value_changed_event_cb(lv_event_t * e);
|
||||
|
||||
#if LV_USE_LABEL
|
||||
static void label_text_observer_cb(lv_observer_t * observer, lv_subject_t * subject);
|
||||
@@ -360,10 +357,7 @@ void lv_subject_remove_all_obj(lv_subject_t * subject, lv_obj_t * obj)
|
||||
}
|
||||
|
||||
while(lv_obj_remove_event_cb(obj, unsubscribe_on_delete_cb));
|
||||
|
||||
#if LV_USE_BUTTON
|
||||
while(lv_obj_remove_event_cb(obj, btn_value_changed_event_cb));
|
||||
#endif /*LV_USE_BUTTON*/
|
||||
while(lv_obj_remove_event_cb(obj, obj_value_changed_event_cb));
|
||||
|
||||
#if LV_USE_ARC
|
||||
while(lv_obj_remove_event_cb(obj, arc_value_changed_event_cb));
|
||||
@@ -440,14 +434,12 @@ lv_observer_t * lv_obj_bind_state_if_not_eq(lv_obj_t * obj, lv_subject_t * subje
|
||||
return observable;
|
||||
}
|
||||
|
||||
#if LV_USE_BUTTON
|
||||
lv_observer_t * lv_button_bind_checked(lv_obj_t * obj, lv_subject_t * subject)
|
||||
lv_observer_t * lv_obj_bind_checked(lv_obj_t * obj, lv_subject_t * subject)
|
||||
{
|
||||
lv_observer_t * observable = bind_to_bitfield(subject, obj, obj_state_observer_cb, LV_STATE_CHECKED, 1, false);
|
||||
lv_obj_add_event_cb(obj, btn_value_changed_event_cb, LV_EVENT_VALUE_CHANGED, subject);
|
||||
lv_obj_add_event_cb(obj, obj_value_changed_event_cb, LV_EVENT_VALUE_CHANGED, subject);
|
||||
return observable;
|
||||
}
|
||||
#endif /*LV_USE_BUTTON*/
|
||||
|
||||
#if LV_USE_LABEL
|
||||
lv_observer_t * lv_label_bind_text(lv_obj_t * obj, lv_subject_t * subject, const char * fmt)
|
||||
@@ -606,9 +598,7 @@ static void obj_state_observer_cb(lv_observer_t * observer, lv_subject_t * subje
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_USE_BUTTON
|
||||
|
||||
static void btn_value_changed_event_cb(lv_event_t * e)
|
||||
static void obj_value_changed_event_cb(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * obj = lv_event_get_current_target(e);
|
||||
lv_subject_t * subject = lv_event_get_user_data(e);
|
||||
@@ -616,8 +606,6 @@ static void btn_value_changed_event_cb(lv_event_t * e)
|
||||
lv_subject_set_int(subject, lv_obj_has_state(obj, LV_STATE_CHECKED));
|
||||
}
|
||||
|
||||
#endif /*LV_USE_BUTTON*/
|
||||
|
||||
#if LV_USE_LABEL
|
||||
|
||||
static void label_text_observer_cb(lv_observer_t * observer, lv_subject_t * subject)
|
||||
|
||||
@@ -329,15 +329,14 @@ lv_observer_t * lv_obj_bind_state_if_eq(lv_obj_t * obj, lv_subject_t * subject,
|
||||
lv_observer_t * lv_obj_bind_state_if_not_eq(lv_obj_t * obj, lv_subject_t * subject, lv_state_t state,
|
||||
int32_t ref_value);
|
||||
|
||||
#if LV_USE_BUTTON
|
||||
/**
|
||||
* Set an integer subject to 1 when a button is checked and set it 0 when unchecked.
|
||||
* @param obj pointer to a button
|
||||
* Set an integer subject to 1 when an object is checked and set it 0 when unchecked.
|
||||
* @param obj pointer to an object
|
||||
* @param subject pointer to a subject
|
||||
* @return pointer to the created observer
|
||||
* @note Ensure the object's `LV_OBJ_FLAG_CHECKABLE` flag is set
|
||||
*/
|
||||
lv_observer_t * lv_button_bind_checked(lv_obj_t * obj, lv_subject_t * subject);
|
||||
#endif
|
||||
lv_observer_t * lv_obj_bind_checked(lv_obj_t * obj, lv_subject_t * subject);
|
||||
|
||||
#if LV_USE_LABEL
|
||||
/**
|
||||
|
||||
@@ -286,12 +286,12 @@ void test_observer_button_checked(void)
|
||||
/*Can bind only to int*/
|
||||
static lv_subject_t subject_wrong;
|
||||
lv_subject_init_pointer(&subject_wrong, NULL);
|
||||
lv_observer_t * observer = lv_button_bind_checked(obj, &subject_wrong);
|
||||
lv_observer_t * observer = lv_obj_bind_checked(obj, &subject_wrong);
|
||||
TEST_ASSERT_EQUAL_PTR(NULL, observer);
|
||||
|
||||
static lv_subject_t subject;
|
||||
lv_subject_init_int(&subject, 1);
|
||||
lv_button_bind_checked(obj, &subject);
|
||||
lv_obj_bind_checked(obj, &subject);
|
||||
|
||||
TEST_ASSERT_EQUAL(true, lv_obj_has_state(obj, LV_STATE_CHECKED));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user