add widget_on_with_tag/wuidget_off_by_tag

This commit is contained in:
lixianjing 2019-10-23 14:23:47 +08:00
parent da97174117
commit aac47ce517
6 changed files with 99 additions and 5 deletions

View File

@ -2,6 +2,7 @@
* 2019/10/23
* 修改clone出来的edit的显示问题。
* 增加widget\_on\_with\_tag和widget\_off\_by\_tag方便一次注销多个同类事件。
* 2019/10/19
* 完善主题切换功能。

View File

@ -932,13 +932,18 @@ ret_t widget_dispatch(widget_t* widget, event_t* e) {
return ret;
}
int32_t widget_on(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx) {
int32_t widget_on_with_tag(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx,
uint32_t tag) {
return_value_if_fail(widget != NULL && on_event != NULL, RET_BAD_PARAMS);
if (widget->emitter == NULL) {
widget->emitter = emitter_create();
}
return emitter_on(widget->emitter, type, on_event, ctx);
return emitter_on_with_tag(widget->emitter, type, on_event, ctx, tag);
}
int32_t widget_on(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx) {
return widget_on_with_tag(widget, type, on_event, ctx, 0);
}
int32_t widget_child_on(widget_t* widget, const char* name, uint32_t type, event_func_t on_event,
@ -953,6 +958,13 @@ ret_t widget_off(widget_t* widget, int32_t id) {
return emitter_off(widget->emitter, id);
}
ret_t widget_off_by_tag(widget_t* widget, int32_t tag) {
return_value_if_fail(widget != NULL, RET_BAD_PARAMS);
return_value_if_fail(widget->emitter != NULL, RET_BAD_PARAMS);
return emitter_off_by_tag(widget->emitter, tag);
}
ret_t widget_off_by_func(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx) {
return_value_if_fail(widget != NULL && on_event != NULL, RET_BAD_PARAMS);
return_value_if_fail(widget->emitter != NULL, RET_BAD_PARAMS);

View File

@ -1143,6 +1143,24 @@ ret_t widget_set_sensitive(widget_t* widget, bool_t sensitive);
*/
int32_t widget_on(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx);
/**
* @method widget_on_with_tag
* tag的事件处理函数
*
* > tagwidget\_off\_by\_tag注销相同tag的事件处理函数
*
* @annotation ["scriptable:custom"]
* @param {widget_t*} widget
* @param {uint32_t} type
* @param {event_func_t} on_event
* @param {void*} ctx
* @param {uint32_t} tag tag
*
* @return {int32_t} idwidget_off
*/
int32_t widget_on_with_tag(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx,
uint32_t tag);
/**
* @method widget_off
*
@ -1171,8 +1189,7 @@ int32_t widget_child_on(widget_t* widget, const char* name, uint32_t type, event
/**
* @method widget_off_by_func
*
*
*
* @param {widget_t*} widget
* @param {uint32_t} type
* @param {event_func_t} on_event
@ -1182,6 +1199,16 @@ int32_t widget_child_on(widget_t* widget, const char* name, uint32_t type, event
*/
ret_t widget_off_by_func(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx);
/**
* @method widget_off_by_tag
* tag的事件处理函数
* @param {widget_t*} widget
* @param {uint32_t} tag tag
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_off_by_tag(widget_t* widget, uint32_t tag);
/**
* @method widget_invalidate
* widget->dirty已经为TRUE

View File

@ -190,7 +190,7 @@ TEST(ComboBox, clone) {
w2 = widget_clone(w1, NULL);
ASSERT_EQ(widget_equal(w1, w2), TRUE);
widget_destroy(w1);
widget_destroy(w2);
}

View File

@ -199,3 +199,30 @@ TEST(Emitter, remove_item) {
emitter_destroy(emitter);
}
TEST(Emitter, off_by_tag) {
uint32_t type = 12;
emitter_t* emitter = emitter_create();
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
emitter_on_with_tag(emitter, type, on_remove, NULL, 2);
emitter_on_with_tag(emitter, type, on_remove, NULL, 3);
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
ASSERT_EQ(emitter_size(emitter), 6);
ASSERT_EQ(emitter_off_by_tag(emitter, 1), RET_OK);
ASSERT_EQ(emitter_size(emitter), 2);
ASSERT_EQ(emitter_off_by_tag(emitter, 3), RET_OK);
ASSERT_EQ(emitter_size(emitter), 1);
ASSERT_EQ(emitter_off_by_tag(emitter, 2), RET_OK);
ASSERT_EQ(emitter_size(emitter), 0);
emitter_destroy(emitter);
}

View File

@ -1103,3 +1103,30 @@ TEST(Widget, feedback1) {
widget_destroy(w);
}
TEST(Widget, off) {
widget_t* w = button_create(NULL, 0, 0, 0, 0);
ASSERT_EQ(widget_on(w, EVT_MOVE, widget_log_events, NULL) > 0, TRUE);
ASSERT_EQ(emitter_size(w->emitter), 1);
ASSERT_EQ(widget_off_by_func(w, EVT_MOVE, widget_log_events, NULL), RET_OK);
widget_destroy(w);
}
TEST(Widget, off_by_tag) {
widget_t* w = button_create(NULL, 0, 0, 0, 0);
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 1) > 0, TRUE);
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 1) > 0, TRUE);
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 1) > 0, TRUE);
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 2) > 0, TRUE);
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 2) > 0, TRUE);
ASSERT_EQ(emitter_size(w->emitter), 5);
ASSERT_EQ(widget_off_by_tag(w, 1), RET_OK);
ASSERT_EQ(emitter_size(w->emitter), 2);
widget_destroy(w);
}