diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index db799e18e..400b57cf5 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -215,7 +215,7 @@ void lv_group_focus_obj(lv_obj_t * obj) if(g->obj_focus == i) return; /*Don't focus the already focused object again*/ if(g->obj_focus != NULL) { (*g->obj_focus)->signal_cb(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL); - lv_res_t res = lv_obj_send_event(*g->obj_focus, LV_EVENT_DEFOCUSED); + lv_res_t res = lv_event_send(*g->obj_focus, LV_EVENT_DEFOCUSED, NULL); if(res != LV_RES_OK) return; lv_obj_invalidate(*g->obj_focus); } @@ -225,7 +225,7 @@ void lv_group_focus_obj(lv_obj_t * obj) if(g->obj_focus != NULL) { (*g->obj_focus)->signal_cb(*g->obj_focus, LV_SIGNAL_FOCUS, NULL); if(g->focus_cb) g->focus_cb(g); - lv_res_t res = lv_obj_send_event(*g->obj_focus, LV_EVENT_FOCUSED); + lv_res_t res = lv_event_send(*g->obj_focus, LV_EVENT_FOCUSED, NULL); if(res != LV_RES_OK) return; lv_obj_invalidate(*g->obj_focus); @@ -328,7 +328,7 @@ void lv_group_set_editing(lv_group_t * group, bool edit) if(focused) { focused->signal_cb(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave/open edit/navigate mode*/ - lv_res_t res = lv_obj_send_event(*group->obj_focus, LV_EVENT_FOCUSED); + lv_res_t res = lv_event_send(*group->obj_focus, LV_EVENT_FOCUSED, NULL); if(res != LV_RES_OK) return; } @@ -626,7 +626,7 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *) if(group->obj_focus) { (*group->obj_focus)->signal_cb(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL); - lv_res_t res = lv_obj_send_event(*group->obj_focus, LV_EVENT_DEFOCUSED); + lv_res_t res = lv_event_send(*group->obj_focus, LV_EVENT_DEFOCUSED, NULL); if(res != LV_RES_OK) return; lv_obj_invalidate(*group->obj_focus); } @@ -634,7 +634,7 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *) group->obj_focus = obj_next; (*group->obj_focus)->signal_cb(*group->obj_focus, LV_SIGNAL_FOCUS, NULL); - lv_res_t res = lv_obj_send_event(*group->obj_focus, LV_EVENT_FOCUSED); + lv_res_t res = lv_event_send(*group->obj_focus, LV_EVENT_FOCUSED, NULL); if(res != LV_RES_OK) return; /*If the object or its parent has `top == true` bring it to the foregorund*/ diff --git a/src/lv_core/lv_indev.c b/src/lv_core/lv_indev.c index 1112ae6b5..f95f0b32a 100644 --- a/src/lv_core/lv_indev.c +++ b/src/lv_core/lv_indev.c @@ -403,7 +403,7 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) if(data->key == LV_GROUP_KEY_ENTER) { focused->signal_cb(focused, LV_SIGNAL_PRESSED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_PRESSED); + lv_event_send(focused, LV_EVENT_PRESSED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ /*Send the ENTER as a normal KEY*/ @@ -436,7 +436,7 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) i->proc.longpr_rep_timestamp = lv_tick_get(); focused->signal_cb(focused, LV_SIGNAL_LONG_PRESS, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_LONG_PRESSED); + lv_event_send(focused, LV_EVENT_LONG_PRESSED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ } } @@ -449,7 +449,7 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) if(data->key == LV_GROUP_KEY_ENTER) { focused->signal_cb(focused, LV_SIGNAL_LONG_PRESS_REP, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_LONG_PRESSED_REPEAT); + lv_event_send(focused, LV_EVENT_LONG_PRESSED_REPEAT, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ } /*Move the focus on NEXT again*/ @@ -482,13 +482,13 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data) if(i->proc.reset_query) return; /*The object might be deleted*/ if(i->proc.long_pr_sent == 0) { - lv_obj_send_event(focused, LV_EVENT_SHORT_CLICKED); + lv_event_send(focused, LV_EVENT_SHORT_CLICKED, NULL); } - lv_obj_send_event(focused, LV_EVENT_CLICKED); + lv_event_send(focused, LV_EVENT_CLICKED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_RELEASED); + lv_event_send(focused, LV_EVENT_RELEASED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ } i->proc.pr_timestamp = 0; @@ -554,7 +554,7 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) focused->signal_cb(focused, LV_SIGNAL_PRESSED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_PRESSED); + lv_event_send(focused, LV_EVENT_PRESSED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ } } @@ -577,7 +577,7 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) else { focused->signal_cb(focused, LV_SIGNAL_LONG_PRESS, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_LONG_PRESSED); + lv_event_send(focused, LV_EVENT_LONG_PRESSED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ } i->proc.long_pr_sent = 1; @@ -594,13 +594,13 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) focused->signal_cb(focused, LV_SIGNAL_RELEASED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - if(i->proc.long_pr_sent == 0) lv_obj_send_event(focused, LV_EVENT_SHORT_CLICKED); + if(i->proc.long_pr_sent == 0) lv_event_send(focused, LV_EVENT_SHORT_CLICKED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_CLICKED); + lv_event_send(focused, LV_EVENT_CLICKED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_RELEASED); + lv_event_send(focused, LV_EVENT_RELEASED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ } /*An object is being edited and the button is released. */ @@ -610,13 +610,13 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data) focused->signal_cb(focused, LV_SIGNAL_RELEASED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_SHORT_CLICKED); + lv_event_send(focused, LV_EVENT_SHORT_CLICKED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_CLICKED); + lv_event_send(focused, LV_EVENT_CLICKED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(focused, LV_EVENT_RELEASED); + lv_event_send(focused, LV_EVENT_RELEASED, NULL); if(i->proc.reset_query) return; /*The object might be deleted*/ lv_group_send_data(g, LV_GROUP_KEY_ENTER); @@ -706,7 +706,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) if(proc->types.pointer.act_obj != NULL) { proc->types.pointer.act_obj->signal_cb(proc->types.pointer.act_obj, LV_SIGNAL_PRESS_LOST, indev_act); if(proc->reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_PRESS_LOST); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_PRESS_LOST, NULL); if(proc->reset_query) return; /*The object might be deleted*/ } @@ -744,7 +744,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) /*Send a signal about the press*/ proc->types.pointer.act_obj->signal_cb(proc->types.pointer.act_obj, LV_SIGNAL_PRESSED, indev_act); if(proc->reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_PRESSED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_PRESSED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ } } @@ -769,7 +769,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) if(proc->types.pointer.act_obj != NULL) { proc->types.pointer.act_obj->signal_cb(proc->types.pointer.act_obj, LV_SIGNAL_PRESSING, indev_act); if(proc->reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_PRESSING); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_PRESSING, NULL); if(proc->reset_query) return; /*The object might be deleted*/ indev_drag(proc); @@ -781,7 +781,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) if(lv_tick_elaps(proc->pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) { pr_obj->signal_cb(pr_obj, LV_SIGNAL_LONG_PRESS, indev_act); if(proc->reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(pr_obj, LV_EVENT_LONG_PRESSED); + lv_event_send(pr_obj, LV_EVENT_LONG_PRESSED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ /*Mark the signal sending to do not send it again*/ @@ -797,7 +797,7 @@ static void indev_proc_press(lv_indev_proc_t * proc) if(lv_tick_elaps(proc->longpr_rep_timestamp) > LV_INDEV_LONG_PRESS_REP_TIME) { pr_obj->signal_cb(pr_obj, LV_SIGNAL_LONG_PRESS_REP, indev_act); if(proc->reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(pr_obj, LV_EVENT_LONG_PRESSED_REPEAT); + lv_event_send(pr_obj, LV_EVENT_LONG_PRESSED_REPEAT, NULL); if(proc->reset_query) return; /*The object might be deleted*/ proc->longpr_rep_timestamp = lv_tick_get(); @@ -830,14 +830,14 @@ static void indev_proc_release(lv_indev_proc_t * proc) if(proc->reset_query) return; /*The object might be deleted*/ if(proc->long_pr_sent == 0 && proc->types.pointer.drag_in_prog == 0) { - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_SHORT_CLICKED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_SHORT_CLICKED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ } - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_CLICKED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_CLICKED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_RELEASED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_RELEASED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ } /* The simple case: `act_obj` was not protected against press lost. @@ -847,14 +847,14 @@ static void indev_proc_release(lv_indev_proc_t * proc) if(proc->reset_query) return; /*The object might be deleted*/ if(proc->long_pr_sent == 0 && proc->types.pointer.drag_in_prog == 0) { - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_SHORT_CLICKED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_SHORT_CLICKED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ } - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_CLICKED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_CLICKED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_RELEASED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_RELEASED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ } @@ -894,10 +894,10 @@ static void indev_proc_release(lv_indev_proc_t * proc) * If the one of them is in group then it possible that `lv_group_focus_obj` alraedy sent * a focus/defucus signal because of `click focus`*/ if(proc->types.pointer.last_pressed != proc->types.pointer.act_obj) { - lv_obj_send_event(proc->types.pointer.last_pressed, LV_EVENT_DEFOCUSED); + lv_event_send(proc->types.pointer.last_pressed, LV_EVENT_DEFOCUSED, NULL); if(proc->reset_query) return; /*Not so strict as it's only the previous object and indev not uses it.*/ - lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_FOCUSED); + lv_event_send(proc->types.pointer.act_obj, LV_EVENT_FOCUSED, NULL); if(proc->reset_query) return; /*The object might be deleted*/ proc->types.pointer.last_pressed = proc->types.pointer.act_obj; diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index cd5cac383..3dc688c4e 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -49,8 +49,9 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param); * STATIC VARIABLES **********************/ static bool lv_initialized = false; -static lv_obj_t * obj_act_event; /*Stores the which event is currently being executed*/ -static bool obj_act_event_deleted; /*Shows that the object was deleted in the event function*/ +static lv_obj_t * event_act_obj; /*Stores the which event is currently being executed*/ +static bool event_act_obj_deleted; /*Shows that the object was deleted in the event function*/ +static const void * event_act_data; /*Stores the data passed to the event*/ /********************** * MACROS **********************/ @@ -342,7 +343,7 @@ lv_res_t lv_obj_del(lv_obj_t * obj) { lv_obj_invalidate(obj); - if(obj_act_event == obj && obj_act_event_deleted == false) obj_act_event_deleted = true; + if(event_act_obj == obj && event_act_obj_deleted == false) event_act_obj_deleted = true; /*Delete from the group*/ #if LV_USE_GROUP @@ -1181,40 +1182,53 @@ void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t cb) /** * Send an event to the object * @param obj pointer to an object - * @param event the type of the event from `lv_event_t`. + * @param event the type of the event from `lv_event_t` + * @param data arbitrary data depending on the object type and the event. (Usually `NULL`) * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` was deleted in the event */ -lv_res_t lv_obj_send_event(lv_obj_t * obj, lv_event_t event) +lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, const void * data) { if(obj == NULL) return LV_RES_OK; /*If the event was send from an other event save the current states to restore it at the end*/ - lv_obj_t * prev_obj_act_event = obj_act_event; - bool prev_obj_act_event_deleted = obj_act_event_deleted; + lv_obj_t * prev_obj_act = event_act_obj; + bool prev_obj_act_deleted = event_act_obj_deleted; + void * prev_data = event_act_data; - obj_act_event = obj; - obj_act_event_deleted = false; + event_act_obj = obj; + event_act_obj_deleted = false; + event_act_data = data; if(obj->event_cb) obj->event_cb(obj, event); - bool deleted = obj_act_event_deleted; + bool deleted = event_act_obj_deleted; /*Restore the previous states*/ - obj_act_event = prev_obj_act_event; - obj_act_event_deleted = prev_obj_act_event_deleted; + event_act_obj = prev_obj_act; + event_act_obj_deleted = prev_obj_act_deleted; + event_act_data = prev_data; if(deleted) { return LV_RES_INV; } if(obj->parent_event && obj->par) { - lv_res_t res = lv_obj_send_event(obj->par, event); + lv_res_t res = lv_event_send(obj->par, event, data); if(res != LV_RES_OK) return LV_RES_INV; } return LV_RES_OK; } +/** + * Get the `data` parameter of the current event + * @return the `data` parameter + */ +const void * lv_event_get_data(void) +{ + return event_act_data; +} + /** * Set the a signal function of an object. Used internally by the library. * Always call the previous signal function in the new. @@ -2006,7 +2020,7 @@ static void refresh_children_style(lv_obj_t * obj) static void delete_children(lv_obj_t * obj) { - if(obj_act_event == obj && obj_act_event_deleted == false) obj_act_event_deleted = true; + if(event_act_obj == obj && event_act_obj_deleted == false) event_act_obj_deleted = true; lv_obj_t * i; lv_obj_t * i_next; diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index 683cfba19..f6910ba8c 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -89,6 +89,7 @@ typedef enum { LV_EVENT_FOCUSED, LV_EVENT_DEFOCUSED, LV_EVENT_VALUE_CHANGED, + LV_EVENT_SELECTED, LV_EVENT_REFRESH, LV_EVENT_APPLY, /*"Ok", "Apply" or similar specific button has clicked*/ LV_EVENT_CANCEL, /*"Close", "Cancel" or similar specific button has clicked*/ @@ -500,9 +501,16 @@ void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t cb); * Send an event to the object * @param obj pointer to an object * @param event the type of the event from `lv_event_t`. + * @param data arbitrary data depending on the object type and the event. (Usually `NULL`) * @return LV_RES_OK: `obj` was not deleted in the event; LV_RES_INV: `obj` was deleted in the event */ -lv_res_t lv_obj_send_event(lv_obj_t * obj, lv_event_t event); +lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, const void * data); + +/** + * Get the `data` parameter of the current event + * @return the `data` parameter + */ +const void * lv_event_get_data(void); /** * Set the a signal function of an object. Used internally by the library. diff --git a/src/lv_objx/lv_btn.c b/src/lv_objx/lv_btn.c index cc21209b4..5f350bf21 100644 --- a/src/lv_objx/lv_btn.c +++ b/src/lv_objx/lv_btn.c @@ -573,7 +573,7 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param) } if(tgl) { - res = lv_obj_send_event(btn, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } diff --git a/src/lv_objx/lv_btnm.c b/src/lv_objx/lv_btnm.c index 3f88a7a2a..98a5932e4 100644 --- a/src/lv_objx/lv_btnm.c +++ b/src/lv_objx/lv_btnm.c @@ -32,8 +32,9 @@ static uint8_t get_button_width(lv_btnm_ctrl_t ctrl_bits); static bool button_is_hidden(lv_btnm_ctrl_t ctrl_bits); static bool button_is_repeat_disabled(lv_btnm_ctrl_t ctrl_bits); static bool button_is_inactive(lv_btnm_ctrl_t ctrl_bits); -static bool button_is_toggle(lv_btnm_ctrl_t ctrl_bits); -static bool button_get_toggle_state(lv_btnm_ctrl_t ctrl_bits); +static bool button_is_click_trig(lv_btnm_ctrl_t ctrl_bits); +static bool button_is_tgl_enabled(lv_btnm_ctrl_t ctrl_bits); +static bool button_get_tgl_state(lv_btnm_ctrl_t ctrl_bits); static uint16_t get_button_from_point(lv_obj_t * btnm, lv_point_t * p); static void allocate_btn_areas_and_controls(const lv_obj_t * btnm, const char ** map); static void invalidate_button_area(const lv_obj_t * btnm, uint16_t btn_idx); @@ -346,111 +347,40 @@ void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en) } /** - * Show/hide a single button in the matrix + * Set the attributes of a button of the button matrix * @param btnm pointer to button matrix object - * @param btn_idx 0 based index of the button to modify. - * @param hidden true: hide the button + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + * @param en true: set the attributes; false: clear the attributes */ -void lv_btnm_set_btn_hidden(const lv_obj_t * btnm, uint16_t btn_idx, bool hidden) +void lv_btnm_set_btn_ctrl(const lv_obj_t * btnm, uint16_t btn_id, lv_btnm_ctrl_t ctrl, bool en) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if (btn_idx >= ext->btn_cnt) return; - if (hidden) ext->ctrl_bits[btn_idx] |= LV_BTNM_BTN_HIDDEN; - else ext->ctrl_bits[btn_idx] &= (~LV_BTNM_BTN_HIDDEN); - invalidate_button_area(btnm, btn_idx); -} - -/** - * Enable/disable a single button in the matrix - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param ina true: make the button inactive - */ -void lv_btnm_set_btn_inactive(const lv_obj_t * btnm, uint16_t btn_id, bool ina) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if (btn_id >= ext->btn_cnt) return; - - if (ina) ext->ctrl_bits[btn_id] |= LV_BTNM_BTN_INACTIVE; - else ext->ctrl_bits[btn_id] &= (~LV_BTNM_BTN_INACTIVE); + if(btn_id >= ext->btn_cnt) return; + if(en) { + ext->ctrl_bits[btn_id] |= ctrl; + } else { + ext->ctrl_bits[btn_id] &= (~ctrl); + } invalidate_button_area(btnm, btn_id); + } /** - * Enable/disable long press for a single button in the matrix - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param no_rep true: disable repeat + * Set the attributes of all buttons of a button matrix + * @param btnm pointer to a button matrix object + * @param ctrl attribute(s) to set from `lv_btnm_ctrl_t`. Values can be ORed. + * @param en true: set the attributes; false: clear the attributes */ -void lv_btnm_set_btn_no_repeat(const lv_obj_t * btnm, uint16_t btn_id, bool no_rep) +void lv_btnm_set_btn_ctrl_all(lv_obj_t * btnm, lv_btnm_ctrl_t ctrl, bool en) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if (btn_id >= ext->btn_cnt) return; - if (no_rep) ext->ctrl_bits[btn_id] |= LV_BTNM_BTN_NO_REPEAT; - else ext->ctrl_bits[btn_id] &= (~LV_BTNM_BTN_NO_REPEAT); + uint16_t i; + for(i= 0; i < ext->btn_cnt; i++) { + lv_btnm_set_btn_ctrl(btnm, i, ctrl, en); + } } - -/** - * Enable/disable toggling a single button in the matrix - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param tgl true: toggle enable - */ -void lv_btnm_set_btn_toggle(const lv_obj_t * btnm, uint16_t btn_id, bool tgl) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if (btn_id >= ext->btn_cnt) return; - if (tgl) ext->ctrl_bits[btn_id] |= LV_BTNM_BTN_TOGGLE; - else ext->ctrl_bits[btn_id] &= (~LV_BTNM_BTN_TOGGLE); -} - -/** - * Make the a single button button toggled or not toggled. - * @param btnm pointer to button matrix object - * @param btn_id index of button (not counting "\n") - * @param state true: toggled; false: not toggled - */ -void lv_btnm_set_btn_toggle_state(lv_obj_t * btnm, uint16_t btn_id, bool state) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if (btn_id >= ext->btn_cnt) return; - - if(state) ext->ctrl_bits[btn_id] |= LV_BTNM_BTN_TOGGLE_STATE; - else ext->ctrl_bits[btn_id] &= (~LV_BTNM_BTN_TOGGLE_STATE); - - invalidate_button_area(btnm, btn_id); -} - -/** - * Set hidden/disabled/repeat flags for a single button. - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param hidden true: hide the button - * @param inactive true: disable the button - * @param no_repeat true: disable repeat - * @param toggle true: enable toggling - * @param toggled_state true: set toggled state - */ -void lv_btnm_set_btn_flags(const lv_obj_t * btnm, uint16_t btn_id, bool hidden, bool inactive, bool no_repeat, bool toggle, bool toggle_state) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - if (btn_id >= ext->btn_cnt) return; - - uint8_t flags = ext->ctrl_bits[btn_id]; - - flags = hidden ? flags | LV_BTNM_BTN_HIDDEN : flags & (~LV_BTNM_BTN_HIDDEN); - flags = inactive ? flags | LV_BTNM_BTN_INACTIVE : flags & (~LV_BTNM_BTN_INACTIVE); - flags = no_repeat ? flags | LV_BTNM_BTN_NO_REPEAT : flags & (~LV_BTNM_BTN_NO_REPEAT); - flags = toggle ? flags | LV_BTNM_BTN_TOGGLE : flags & (~LV_BTNM_BTN_TOGGLE); - flags = toggle_state ? flags | LV_BTNM_BTN_TOGGLE_STATE : flags & (~LV_BTNM_BTN_TOGGLE_STATE); - - ext->ctrl_bits[btn_id] = flags; - invalidate_button_area(btnm, btn_id); -} - - /** * Set a single buttons relative width. * This method will cause the matrix be regenerated and is a relatively @@ -471,23 +401,6 @@ void lv_btnm_set_btn_width(const lv_obj_t * btnm, uint16_t btn_id, uint8_t width lv_btnm_set_map(btnm, ext->map_p); } -/** - * Set the toggle state of all buttons - * @param btnm pointer to a button matrix object - * @param state true: toggled; false: not toggled - */ -void lv_btnm_set_btn_toggle_state_all(lv_obj_t * btnm, bool state) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - uint16_t i; - for(i = 0; i < ext->btn_cnt; i++) { - if(state) ext->ctrl_bits[i] |= LV_BTNM_BTN_TOGGLE_STATE; - else ext->ctrl_bits[i] &= (~LV_BTNM_BTN_TOGGLE_STATE); - } - - lv_obj_invalidate(btnm); -} - /*===================== * Getter functions *====================*/ @@ -559,7 +472,7 @@ uint16_t lv_btnm_get_pressed_btn(const lv_obj_t * btnm) /** * Get the button's text * @param btnm pointer to button matrix object - * @param btn_index the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) + * @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) * @return text of btn_index` button */ const char * lv_btnm_get_btn_text(const lv_obj_t * btnm, uint16_t btn_id) @@ -584,65 +497,18 @@ const char * lv_btnm_get_btn_text(const lv_obj_t * btnm, uint16_t btn_id) } /** - * Check whether "no repeat" for a button is set or not. - * The `LV_EVENT_LONG_PRESS_REPEAT` will be sent anyway but it can be ignored by the user if this function returns `true` + * Get the whether a control value is enabled or disabled for button of a button matrix * @param btnm pointer to a button matrix object - * @param btn_index the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) + * @param btn_id the index a button not counting new line characters. (E.g. the return value of lv_btnm_get_pressed/released) + * @param ctrl control values to check (ORed value can be used) * @return true: long press repeat is disabled; false: long press repeat enabled */ -bool lv_btnm_get_btn_no_repeat(lv_obj_t * btnm, uint16_t btn_id) +bool lv_btnm_get_btn_ctrl(lv_obj_t * btnm, uint16_t btn_id, lv_btnm_ctrl_t ctrl) { lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - return button_is_repeat_disabled(ext->ctrl_bits[btn_id]); -} + if(btn_id >= ext->btn_cnt) return false; -/** - * Check whether a button for a button is hidden or not. - * Events will be sent anyway but they can be ignored by the user if this function returns `true` - * @param btnm pointer to a button matrix object - * @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) - * @return true: hidden; false: not hidden - */ -bool lv_btnm_get_btn_hidden(lv_obj_t * btnm, uint16_t btn_id) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - return button_is_hidden(ext->ctrl_bits[btn_id]); -} - -/** - * Check whether a button for a button is inactive or not. - * Events will be sent anyway but they can be ignored by the user if this function returns `true` - * @param btnm pointer to a button matrix object - * @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) - * @return true: inactive; false: not inactive - */ -bool lv_btnm_get_btn_inactive(lv_obj_t * btnm, uint16_t btn_id) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - return button_is_inactive(ext->ctrl_bits[btn_id]); -} -/** - * Check if the button can be toggled or not - * @param btnm pointer to button matrix object - * @return btn_id index a of a button not counting "\n". (The return value of lv_btnm_get_pressed/released) - */ -bool lv_btnm_get_btn_toggle(const lv_obj_t * btnm, int16_t btn_id) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - - return button_is_toggle(ext->ctrl_bits[btn_id]); -} - -/** - * Check if the button is toggled or not - * @param btnm pointer to button matrix object - * @return btn_id index a of a button not counting "\n". (The return value of lv_btnm_get_pressed/released) - */ -bool lv_btnm_get_btn_toggle_state(const lv_obj_t * btnm, int16_t btn_id) -{ - lv_btnm_ext_t * ext = lv_obj_get_ext_attr(btnm); - - return button_get_toggle_state(ext->ctrl_bits[btn_id]); + return ext->ctrl_bits[btn_id] & ctrl ? true : false; } /** @@ -746,7 +612,7 @@ static bool lv_btnm_design(lv_obj_t * btnm, const lv_area_t * mask, lv_design_mo btn_h = lv_area_get_height(&area_tmp); /*Load the style*/ - bool tgl_state = button_get_toggle_state(ext->ctrl_bits[btn_i]); + bool tgl_state = button_get_tgl_state(ext->ctrl_bits[btn_i]); if(button_is_inactive(ext->ctrl_bits[btn_i])) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_INA); else if(btn_i != ext->btn_id_pr && tgl_state == false) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_REL); else if(btn_i == ext->btn_id_pr && tgl_state == false) btn_style = lv_btnm_get_style(btnm, LV_BTNM_STYLE_BTN_PR); @@ -833,6 +699,14 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ext->btn_id_act = btn_pr; invalidate_button_area(btnm, ext->btn_id_pr); /*Invalidate the new area*/ } + if(ext->btn_id_act != LV_BTNM_BTN_NONE) { + if(button_is_click_trig(ext->ctrl_bits[ext->btn_id_act]) == false && + button_is_inactive(ext->ctrl_bits[ext->btn_id_act]) == false && + button_is_hidden(ext->ctrl_bits[ext->btn_id_act]) == false) + { + lv_event_send(btnm, LV_EVENT_SELECTED, lv_btnm_get_active_btn_text(btnm)); + } + } } else if(sign == LV_SIGNAL_PRESSING) { uint16_t btn_pr; @@ -846,6 +720,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) invalidate_button_area(btnm, ext->btn_id_pr); } if(btn_pr != LV_BTNM_BTN_NONE) { + if(btn_pr != LV_BTNM_BTN_NONE) lv_event_send(btnm, LV_EVENT_SELECTED, ext->map_p[btn_pr]); invalidate_button_area(btnm, btn_pr); } } @@ -856,11 +731,11 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) else if(sign == LV_SIGNAL_RELEASED) { if(ext->btn_id_pr != LV_BTNM_BTN_NONE) { /*Toggle the button if enabled*/ - if(button_is_toggle(ext->ctrl_bits[ext->btn_id_pr])) { - if(ext->ctrl_bits[ext->btn_id_pr] & LV_BTNM_BTN_TOGGLE_STATE) { - ext->ctrl_bits[ext->btn_id_pr] &= (~LV_BTNM_BTN_TOGGLE_STATE); + if(button_is_tgl_enabled(ext->ctrl_bits[ext->btn_id_pr])) { + if(button_get_tgl_state(ext->ctrl_bits[ext->btn_id_pr])) { + ext->ctrl_bits[ext->btn_id_pr] &= (~LV_BTNM_CTRL_TGL_STATE); } else { - ext->ctrl_bits[ext->btn_id_pr] |= LV_BTNM_BTN_TOGGLE_STATE; + ext->ctrl_bits[ext->btn_id_pr] |= LV_BTNM_CTRL_TGL_STATE; } } @@ -876,10 +751,29 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) #else ext->btn_id_pr = LV_BTNM_BTN_NONE; #endif + + if(button_is_click_trig(ext->ctrl_bits[ext->btn_id_act]) == true && + button_is_inactive(ext->ctrl_bits[ext->btn_id_act]) == false && + button_is_hidden(ext->ctrl_bits[ext->btn_id_act]) == false) + { + lv_event_send(btnm, LV_EVENT_SELECTED, lv_btnm_get_active_btn_text(btnm)); + } + + } + } + else if(sign == LV_SIGNAL_LONG_PRESS_REP) { + if(ext->btn_id_act != LV_BTNM_BTN_NONE) { + if(button_is_repeat_disabled(ext->ctrl_bits[ext->btn_id_act]) == false && + button_is_inactive(ext->ctrl_bits[ext->btn_id_act]) == false && + button_is_hidden(ext->ctrl_bits[ext->btn_id_act]) == false) + { + lv_event_send(btnm, LV_EVENT_SELECTED, lv_btnm_get_active_btn_text(btnm)); + } } } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { ext->btn_id_pr = LV_BTNM_BTN_NONE; + ext->btn_id_act = LV_BTNM_BTN_NONE; lv_obj_invalidate(btnm); } else if(sign == LV_SIGNAL_FOCUS) { @@ -1036,27 +930,32 @@ static uint8_t get_button_width(lv_btnm_ctrl_t ctrl_bits) static bool button_is_hidden(lv_btnm_ctrl_t ctrl_bits) { - return ctrl_bits & LV_BTNM_BTN_HIDDEN; + return ctrl_bits & LV_BTNM_CTRL_HIDDEN ? true : false; } static bool button_is_repeat_disabled(lv_btnm_ctrl_t ctrl_bits) { - return ctrl_bits & LV_BTNM_BTN_NO_REPEAT; + return ctrl_bits & LV_BTNM_CTRL_NO_REPEAT ? true : false; } static bool button_is_inactive(lv_btnm_ctrl_t ctrl_bits) { - return ctrl_bits & LV_BTNM_BTN_INACTIVE; + return ctrl_bits & LV_BTNM_CTRL_INACTIVE ? true : false; } -static bool button_is_toggle(lv_btnm_ctrl_t ctrl_bits) +static bool button_is_click_trig(lv_btnm_ctrl_t ctrl_bits) { - return ctrl_bits & LV_BTNM_BTN_TOGGLE; + return ctrl_bits & LV_BTNM_CTRL_CLICK_TRIG ? true : false; } -static bool button_get_toggle_state(lv_btnm_ctrl_t ctrl_bits) +static bool button_is_tgl_enabled(lv_btnm_ctrl_t ctrl_bits) { - return ctrl_bits & LV_BTNM_BTN_TOGGLE_STATE; + return ctrl_bits & LV_BTNM_CTRL_TGL_ENABLE ? true : false; +} + +static bool button_get_tgl_state(lv_btnm_ctrl_t ctrl_bits) +{ + return ctrl_bits & LV_BTNM_CTRL_TGL_STATE ? true : false; } /** diff --git a/src/lv_objx/lv_btnm.h b/src/lv_objx/lv_btnm.h index 5d04cec41..6cdc8f3fd 100644 --- a/src/lv_objx/lv_btnm.h +++ b/src/lv_objx/lv_btnm.h @@ -29,22 +29,23 @@ extern "C" { /********************* * DEFINES *********************/ - -/*Control byte*/ -#define LV_BTNM_WIDTH_MASK 0x07 -#define LV_BTNM_BTN_HIDDEN 0x08 -#define LV_BTNM_BTN_NO_REPEAT 0x10 -#define LV_BTNM_BTN_INACTIVE 0x20 -#define LV_BTNM_BTN_TOGGLE 0x40 -#define LV_BTNM_BTN_TOGGLE_STATE 0x80 - +#define LV_BTNM_WIDTH_MASK 0x0007 #define LV_BTNM_BTN_NONE 0xFFFF + /********************** * TYPEDEFS **********************/ /* Type to store button control bits (disabled, hidden etc.) */ -typedef uint8_t lv_btnm_ctrl_t; +enum { + LV_BTNM_CTRL_HIDDEN = 0x0008, + LV_BTNM_CTRL_NO_REPEAT = 0x0010, + LV_BTNM_CTRL_INACTIVE = 0x0020, + LV_BTNM_CTRL_TGL_ENABLE = 0x0040, + LV_BTNM_CTRL_TGL_STATE = 0x0080, + LV_BTNM_CTRL_CLICK_TRIG = 0x0100, +}; +typedef uint16_t lv_btnm_ctrl_t; /*Data of button matrix*/ typedef struct @@ -138,56 +139,21 @@ void lv_btnm_set_style(lv_obj_t * btnm, lv_btnm_style_t type, lv_style_t * style void lv_btnm_set_recolor(const lv_obj_t * btnm, bool en); /** - * Show/hide a single button in the matrix + * Set/clear an attribute of a button of the button matrix * @param btnm pointer to button matrix object - * @param btn_idx 0 based index of the button to modify. - * @param hidden true: hide the button + * @param btn_id 0 based index of the button to modify. (Not counting new lines) + * @param ctrl attribute(s) to change from `lv_btnm_ctrl_t`. Values can be ORed. + * @param en true: set the attributes; false: clear the attributes */ -void lv_btnm_set_btn_hidden(const lv_obj_t * btnm, uint16_t btn_idx, bool hidden); +void lv_btnm_set_btn_ctrl(const lv_obj_t * btnm, uint16_t btn_id, lv_btnm_ctrl_t ctrl, bool en); /** - * Enable/disable a single button in the matrix - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param ina true: make the button inactive + * Set the attributes of all buttons of a button matrix + * @param btnm pointer to a button matrix object + * @param ctrl attribute(s) to set from `lv_btnm_ctrl_t`. Values can be ORed. + * @param en true: set the attributes; false: clear the attributes */ -void lv_btnm_set_btn_inactive(const lv_obj_t * btnm, uint16_t btn_id, bool ina); - -/** - * Enable/disable long press for a single button in the matrix - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param no_rep true: disable repeat - */ -void lv_btnm_set_btn_no_repeat(const lv_obj_t * btnm, uint16_t btn_id, bool no_rep); - -/** - * Enable/disable toggling a single button in the matrix - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param tgl true: toggle enable - */ -void lv_btnm_set_btn_toggle(const lv_obj_t * btnm, uint16_t btn_id, bool tgl); - -/** - * Make the a single button button toggled or not toggled. - * @param btnm pointer to button matrix object - * @param btn_id index of button (not counting "\n") - * @param state true: toggled; false: not toggled - */ -void lv_btnm_set_btn_toggle_state(lv_obj_t * btnm, uint16_t btn_id, bool toggle); - -/** - * Set hidden/disabled/repeat flags for a single button. - * @param btnm pointer to button matrix object - * @param btn_id 0 based index of the button to modify. - * @param hidden true: hide the button - * @param inactive true: disable the button - * @param no_repeat true: disable repeat - * @param toggle true: enable toggling - * @param toggled_state true: set toggled state - */ -void lv_btnm_set_btn_flags(const lv_obj_t * btnm, uint16_t btn_id, bool hidden, bool inactive, bool no_repeat, bool toggle, bool toggle_state); +void lv_btnm_set_btn_ctrl_all(lv_obj_t * btnm, lv_btnm_ctrl_t ctrl, bool en); /** * Set a single buttons relative width. @@ -200,12 +166,6 @@ void lv_btnm_set_btn_flags(const lv_obj_t * btnm, uint16_t btn_id, bool hidden, */ void lv_btnm_set_btn_width(const lv_obj_t * btnm, uint16_t btn_id, uint8_t width); -/** - * Set the toggle state of all buttons - * @param btnm pointer to a button matrix object - * @param state true: toggled; false: not toggled - */ -void lv_btnm_set_btn_toggle_state_all(lv_obj_t * btnm, bool state); /*===================== * Getter functions @@ -252,51 +212,19 @@ uint16_t lv_btnm_get_pressed_btn(const lv_obj_t * btnm); /** * Get the button's text * @param btnm pointer to button matrix object - * @param btn_index the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) + * @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) * @return text of btn_index` button */ const char * lv_btnm_get_btn_text(const lv_obj_t * btnm, uint16_t btn_id); /** - * Check whether "no repeat" for a button is set or not. - * The `LV_EVENT_LONG_PRESS_REPEAT` will be sent anyway but it can be ignored by the user if this function returns `true` + * Get the whether a control value is enabled or disabled for button of a button matrix * @param btnm pointer to a button matrix object - * @param btn_index the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) + * @param btn_id the index a button not counting new line characters. (E.g. the return value of lv_btnm_get_pressed/released) + * @param ctrl control values to check (ORed value can be used) * @return true: long press repeat is disabled; false: long press repeat enabled */ -bool lv_btnm_get_btn_no_repeat(lv_obj_t * btnm, uint16_t btn_id); - -/** - * Check whether a button for a button is hidden or not. - * Events will be sent anyway but they can be ignored by the user if this function returns `true` - * @param btnm pointer to a button matrix object - * @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) - * @return true: hidden; false: not hidden - */ -bool lv_btnm_get_btn_hidden(lv_obj_t * btnm, uint16_t btn_id); - -/** - * Check whether a button for a button is inactive or not. - * Events will be sent anyway but they can be ignored by the user if this function returns `true` - * @param btnm pointer to a button matrix object - * @param btn_id the index a button not counting new line characters. (The return value of lv_btnm_get_pressed/released) - * @return true: inactive; false: not inactive - */ -bool lv_btnm_get_btn_inactive(lv_obj_t * btnm, uint16_t btn_id); - -/** - * Check if the button can be toggled or not - * @param btnm pointer to button matrix object - * @return btn_id index a of a button not counting "\n". (The return value of lv_btnm_get_pressed/released) - */ -bool lv_btnm_get_btn_toggle(const lv_obj_t * btnm, int16_t btn_id); - -/** - * Check if the button is toggled or not - * @param btnm pointer to button matrix object - * @return btn_id index a of a button not counting "\n". (The return value of lv_btnm_get_pressed/released) - */ -bool lv_btnm_get_btn_toggle_state(const lv_obj_t * btnm, int16_t btn_id); +bool lv_btnm_get_btn_ctrl(lv_obj_t * btnm, uint16_t btn_id, lv_btnm_ctrl_t ctrl); /** * Get a style of a button matrix diff --git a/src/lv_objx/lv_calendar.c b/src/lv_objx/lv_calendar.c index 6398a16c1..7ca7e1ae4 100644 --- a/src/lv_objx/lv_calendar.c +++ b/src/lv_objx/lv_calendar.c @@ -544,7 +544,7 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * } else if(ext->pressed_date.year != 0) { - res = lv_obj_send_event(calendar, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(calendar, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } diff --git a/src/lv_objx/lv_ddlist.c b/src/lv_objx/lv_ddlist.c index 8ef5280ac..2adc3a05d 100644 --- a/src/lv_objx/lv_ddlist.c +++ b/src/lv_objx/lv_ddlist.c @@ -805,7 +805,7 @@ static lv_res_t release_handler(lv_obj_t * ddlist) ext->sel_opt_id_ori = ext->sel_opt_id; - lv_res_t res = lv_obj_send_event(ddlist, LV_EVENT_VALUE_CHANGED); + lv_res_t res = lv_event_send(ddlist, LV_EVENT_VALUE_CHANGED, &ext->sel_opt_id); if(res != LV_RES_OK) return res; if(ext->stay_open == 0) { diff --git a/src/lv_objx/lv_kb.c b/src/lv_objx/lv_kb.c index f90e9d07a..073b53060 100644 --- a/src/lv_objx/lv_kb.c +++ b/src/lv_objx/lv_kb.c @@ -41,7 +41,7 @@ static const char * kb_map_lc[] = { static const lv_btnm_ctrl_t kb_ctrl_lc_map[] = { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, - (6 | LV_BTNM_BTN_NO_REPEAT), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, + (6 | LV_BTNM_CTRL_NO_REPEAT), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 6, 2, 2 }; @@ -55,7 +55,7 @@ static const char * kb_map_uc[] = { static const lv_btnm_ctrl_t kb_ctrl_uc_map[] = { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, - (6 | LV_BTNM_BTN_NO_REPEAT), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, + (6 | LV_BTNM_CTRL_NO_REPEAT), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 6, 2, 2 }; @@ -69,7 +69,7 @@ static const char * kb_map_spec[] = { static const lv_btnm_ctrl_t kb_ctrl_spec_map[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - (2 | LV_BTNM_BTN_NO_REPEAT), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + (2 | LV_BTNM_CTRL_NO_REPEAT), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 6, 2, 2 }; @@ -371,7 +371,7 @@ static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param) lv_kb_def_btn_action_cb(kb); } else if(sign == LV_SIGNAL_LONG_PRESS_REP) { - bool no_rep = lv_btnm_get_btn_no_repeat(kb, lv_btnm_get_active_btn(kb)); + bool no_rep = lv_btnm_get_btn_ctrl(kb, lv_btnm_get_active_btn(kb), LV_BTNM_CTRL_NO_REPEAT); if(no_rep == false) lv_kb_def_btn_action_cb(kb); } else if(sign == LV_SIGNAL_FOCUS) { @@ -413,8 +413,7 @@ static void lv_kb_def_btn_action_cb(lv_obj_t * kb) uint16_t btn_id = lv_btnm_get_active_btn(kb); if(btn_id == LV_BTNM_BTN_NONE) return; - if(lv_btnm_get_btn_hidden(kb, btn_id)) return; - if(lv_btnm_get_btn_inactive(kb, btn_id)) return; + if(lv_btnm_get_btn_ctrl(kb, btn_id, LV_BTNM_CTRL_HIDDEN | LV_BTNM_CTRL_INACTIVE)) return; const char * txt = lv_btnm_get_active_btn_text(kb); if(txt == NULL) return; @@ -434,7 +433,7 @@ static void lv_kb_def_btn_action_cb(lv_obj_t * kb) return; } else if(strcmp(txt, LV_SYMBOL_CLOSE) == 0) { if(kb->event_cb) { - lv_obj_send_event(kb, LV_EVENT_CANCEL); + lv_event_send(kb, LV_EVENT_CANCEL, NULL); } else { lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ @@ -442,7 +441,7 @@ static void lv_kb_def_btn_action_cb(lv_obj_t * kb) } return; } else if(strcmp(txt, LV_SYMBOL_OK) == 0) { - if(kb->event_cb) lv_obj_send_event(kb, LV_EVENT_APPLY); + if(kb->event_cb) lv_event_send(kb, LV_EVENT_APPLY, NULL); else lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ return; } diff --git a/src/lv_objx/lv_list.c b/src/lv_objx/lv_list.c index cbdbde6b5..71d5cc593 100644 --- a/src/lv_objx/lv_list.c +++ b/src/lv_objx/lv_list.c @@ -760,22 +760,22 @@ static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param) if(btn) { if(sign == LV_SIGNAL_PRESSED) { - lv_obj_send_event(btn, LV_EVENT_PRESSED); + lv_event_send(btn, LV_EVENT_PRESSED, NULL); } else if(sign == LV_SIGNAL_PRESSING) { - lv_obj_send_event(btn, LV_EVENT_PRESSING); + lv_event_send(btn, LV_EVENT_PRESSING, NULL); } else if(sign == LV_SIGNAL_LONG_PRESS) { - lv_obj_send_event(btn, LV_EVENT_LONG_PRESSED); + lv_event_send(btn, LV_EVENT_LONG_PRESSED, NULL); } else if(sign == LV_SIGNAL_LONG_PRESS_REP) { - lv_obj_send_event(btn, LV_EVENT_LONG_PRESSED_REPEAT); + lv_event_send(btn, LV_EVENT_LONG_PRESSED_REPEAT, NULL); } else if(sign == LV_SIGNAL_RELEASED) { ext->last_sel = btn; - if(indev->proc.long_pr_sent == 0) lv_obj_send_event(btn, LV_EVENT_SHORT_CLICKED); - lv_obj_send_event(btn, LV_EVENT_CLICKED); - lv_obj_send_event(btn, LV_EVENT_RELEASED); + if(indev->proc.long_pr_sent == 0) lv_event_send(btn, LV_EVENT_SHORT_CLICKED, NULL); + if(lv_indev_is_dragging(indev) == false) lv_event_send(btn, LV_EVENT_CLICKED, NULL); + lv_event_send(btn, LV_EVENT_RELEASED, NULL); } } } diff --git a/src/lv_objx/lv_mbox.c b/src/lv_objx/lv_mbox.c index f17c3e0c5..d351ed666 100644 --- a/src/lv_objx/lv_mbox.c +++ b/src/lv_objx/lv_mbox.c @@ -153,6 +153,7 @@ void lv_mbox_add_btns(lv_obj_t * mbox, const char ** btn_map) } lv_btnm_set_map(ext->btnm, btn_map); + lv_btnm_set_btn_ctrl_all(ext->btnm, LV_BTNM_CTRL_CLICK_TRIG | LV_BTNM_CTRL_NO_REPEAT, true); lv_obj_set_parent_event(ext->btnm, true); mbox_realign(mbox); @@ -440,12 +441,9 @@ static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param) mbox_realign(mbox); } - else if(sign == LV_SIGNAL_PRESSED) { - /*If the message box was pressed clear the last active button*/ - if(ext->btnm) { - lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btnm); - btnm_ext->btn_id_act = LV_BTNM_BTN_NONE; - } + else if(sign == LV_SIGNAL_RELEASED) { + uint16_t btn_id = lv_btnm_get_active_btn(ext->btnm); + if(btn_id != LV_BTNM_BTN_NONE) lv_event_send(mbox, LV_EVENT_SELECTED, lv_btnm_get_btn_text(ext->btnm, btn_id)); } else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROLL || sign == LV_SIGNAL_GET_EDITABLE) { @@ -467,8 +465,6 @@ static lv_res_t lv_mbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param) } #endif } - - } else if(sign == LV_SIGNAL_GET_TYPE) { lv_obj_type_t * buf = param; uint8_t i; diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index 5ec765c5f..0150e6205 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -1015,6 +1015,7 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi * It is used by default if the scrollable's event is not specified * @param scrl pointer to the page's scrollable object * @param event type of the event + * @param data data of the event */ static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event) { @@ -1032,7 +1033,7 @@ static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event) event == LV_EVENT_FOCUSED || event == LV_EVENT_DEFOCUSED) { - lv_obj_send_event(page, event); + lv_event_send(page, event, lv_event_get_data()); } } diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index 84d4a49bf..cc088344f 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -518,7 +518,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, ext->ddlist.sel_opt_id = id; ext->ddlist.sel_opt_id_ori = id; - res = lv_obj_send_event(roller, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(roller, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } else if(sign == LV_SIGNAL_RELEASED) { /*If picked an option by clicking then set it*/ @@ -536,7 +536,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, bool editing = lv_group_get_editing(g); if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/ #endif - res = lv_obj_send_event(roller, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(roller, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } diff --git a/src/lv_objx/lv_slider.c b/src/lv_objx/lv_slider.c index fe16c8344..508610d20 100644 --- a/src/lv_objx/lv_slider.c +++ b/src/lv_objx/lv_slider.c @@ -479,7 +479,7 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par if(tmp != ext->drag_value) { ext->drag_value = tmp; lv_obj_invalidate(slider); - res = lv_obj_send_event(slider, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { @@ -529,11 +529,11 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { lv_slider_set_value(slider, lv_slider_get_value(slider) + 1, true); - res = lv_obj_send_event(slider, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { lv_slider_set_value(slider, lv_slider_get_value(slider) - 1, true); - res = lv_obj_send_event(slider, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } else if(sign == LV_SIGNAL_GET_EDITABLE) { diff --git a/src/lv_objx/lv_sw.c b/src/lv_objx/lv_sw.c index a1477f523..cc6ef7cbc 100644 --- a/src/lv_objx/lv_sw.c +++ b/src/lv_objx/lv_sw.c @@ -328,13 +328,13 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) if(lv_sw_get_state(sw)) { lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on); lv_slider_set_value(sw, LV_SW_MAX_VALUE, true); - res = lv_obj_send_event(sw, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } else { lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off); lv_slider_set_value(sw, 0, true); - res = lv_obj_send_event(sw, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } @@ -344,7 +344,7 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) if(lv_sw_get_state(sw)) lv_sw_off(sw, true); else lv_sw_on(sw, true); - res = lv_obj_send_event(sw, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } /*If the switch was dragged then calculate the new state based on the current position*/ @@ -353,18 +353,18 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param) if(v > LV_SW_MAX_VALUE / 2) lv_sw_on(sw, true); else lv_sw_off(sw, true); - res = lv_obj_send_event(sw, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } else if(sign == LV_SIGNAL_CONTROLL) { char c = *((char *)param); if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { lv_slider_set_value(sw, LV_SW_MAX_VALUE, true); - res = lv_obj_send_event(sw, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { lv_slider_set_value(sw, 0, true); - res = lv_obj_send_event(sw, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(sw, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } else if(sign == LV_SIGNAL_GET_EDITABLE) { diff --git a/src/lv_objx/lv_ta.c b/src/lv_objx/lv_ta.c index 206e2aa76..35ed32d7f 100644 --- a/src/lv_objx/lv_ta.c +++ b/src/lv_objx/lv_ta.c @@ -255,7 +255,7 @@ void lv_ta_add_char(lv_obj_t * ta, uint32_t c) placeholder_update(ta); - lv_obj_send_event(ta, LV_EVENT_VALUE_CHANGED); + lv_event_send(ta, LV_EVENT_VALUE_CHANGED, letter_buf); } /** @@ -322,7 +322,7 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) placeholder_update(ta); - lv_obj_send_event(ta, LV_EVENT_VALUE_CHANGED); + lv_event_send(ta, LV_EVENT_VALUE_CHANGED, txt); } /** @@ -365,7 +365,7 @@ void lv_ta_del_char(lv_obj_t * ta) placeholder_update(ta); - lv_obj_send_event(ta, LV_EVENT_VALUE_CHANGED); + lv_event_send(ta, LV_EVENT_VALUE_CHANGED, NULL); } /** @@ -442,7 +442,7 @@ void lv_ta_set_text(lv_obj_t * ta, const char * txt) placeholder_update(ta); - lv_obj_send_event(ta, LV_EVENT_VALUE_CHANGED); + lv_event_send(ta, LV_EVENT_VALUE_CHANGED, txt); } /** diff --git a/src/lv_objx/lv_tabview.c b/src/lv_objx/lv_tabview.c index f3f906bf4..e019b9009 100644 --- a/src/lv_objx/lv_tabview.c +++ b/src/lv_objx/lv_tabview.c @@ -234,7 +234,7 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) btnm_ext->map_p = NULL; lv_btnm_set_map(ext->btns, ext->tab_name_ptr); - lv_btnm_set_btn_no_repeat(ext->btns, ext->tab_cnt - 1, true); + lv_btnm_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_NO_REPEAT, true); /*Modify the indicator size*/ lv_style_t * style_tabs = lv_obj_get_style(ext->btns); @@ -276,8 +276,11 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en) lv_res_t res = LV_RES_OK; if(id >= ext->tab_cnt) id = ext->tab_cnt - 1; - if(id != ext->tab_cur) res = lv_obj_send_event(tabview, LV_EVENT_VALUE_CHANGED); - if(res != LV_RES_OK) return; /*Prevent the tab loading*/ + if(id != ext->tab_cur) res = lv_event_send(tabview, LV_EVENT_SELECTED, lv_btnm_get_btn_text(ext->btns, id)); + if(res != LV_RES_OK) return; + + + lv_btnm_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_TGL_STATE, false); ext->tab_cur = id; @@ -329,7 +332,7 @@ void lv_tabview_set_tab_act(lv_obj_t * tabview, uint16_t id, bool anim_en) #endif } - lv_btnm_set_btn_toggle_state(ext->btns, ext->tab_cur, true); + lv_btnm_set_btn_ctrl(ext->btns, ext->tab_cur, LV_BTNM_CTRL_TGL_STATE, true); } /** @@ -596,7 +599,7 @@ static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * p if(indev_type == LV_INDEV_TYPE_KEYPAD || (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(tabview)))) { - lv_obj_send_event(ext->btns, LV_EVENT_CLICKED); + lv_event_send(ext->btns, LV_EVENT_CLICKED, lv_event_get_data()); } } else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROLL) { @@ -806,9 +809,8 @@ static void tab_btnm_event_cb(lv_obj_t * tab_btnm, lv_event_t event) uint16_t btn_id = lv_btnm_get_active_btn(tab_btnm); if(btn_id == LV_BTNM_BTN_NONE) return; - - lv_btnm_set_btn_toggle_state_all(tab_btnm, false); - lv_btnm_set_btn_toggle_state(tab_btnm, btn_id, true); + lv_btnm_set_btn_ctrl_all(tab_btnm, LV_BTNM_CTRL_TGL_STATE, false); + lv_btnm_set_btn_ctrl(tab_btnm, btn_id, LV_BTNM_CTRL_TGL_STATE, true); lv_obj_t * tab = lv_obj_get_parent(tab_btnm); lv_tabview_set_tab_act(tab, btn_id, true); diff --git a/src/lv_objx/lv_tileview.c b/src/lv_objx/lv_tileview.c index e5dd99445..ee44c9bb7 100644 --- a/src/lv_objx/lv_tileview.c +++ b/src/lv_objx/lv_tileview.c @@ -243,7 +243,7 @@ void lv_tileview_set_tile_act(lv_obj_t * tileview, lv_coord_t x, lv_coord_t y, b lv_res_t res = LV_RES_OK; - res = lv_obj_send_event(tileview, LV_EVENT_VALUE_CHANGED); + res = lv_event_send(tileview, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return; /*Prevent the tile loading*/ } @@ -463,7 +463,6 @@ static void tileview_scrl_event_cb(lv_obj_t * scrl, lv_event_t event) lv_tileview_ext_t * ext = lv_obj_get_ext_attr(tileview); if(lv_indev_is_dragging(indev) && (ext->drag_hor || ext->drag_ver)) { indev->proc.types.pointer.drag_in_prog = 0; -// if(drag_obj) drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, NULL); } drag_end_handler(tileview);