add_child/remove_child to virtual function

This commit is contained in:
xianjimli 2018-06-29 15:45:18 +08:00
parent 0efe0534e9
commit c5ca6184ee
2 changed files with 16 additions and 0 deletions

View File

@ -267,6 +267,12 @@ ret_t widget_add_child(widget_t* widget, widget_t* child) {
widget->children = array_create(4);
}
if(widget->vt->add_child) {
if(widget->vt->add_child(widget, child) == RET_OK) {
return RET_OK;
}
}
return array_push(widget->children, child);
}
@ -281,6 +287,12 @@ ret_t widget_remove_child(widget_t* widget, widget_t* child) {
widget->key_target = NULL;
}
if(widget->vt->remove_child) {
if(widget->vt->remove_child(widget, child) == RET_OK) {
return RET_OK;
}
}
return array_remove(widget->children, NULL, child, NULL);
}

View File

@ -109,6 +109,8 @@ typedef ret_t (*widget_on_click_t)(widget_t* widget, pointer_event_t* e);
typedef ret_t (*widget_on_pointer_down_t)(widget_t* widget, pointer_event_t* e);
typedef ret_t (*widget_on_pointer_move_t)(widget_t* widget, pointer_event_t* e);
typedef ret_t (*widget_on_pointer_up_t)(widget_t* widget, pointer_event_t* e);
typedef ret_t (*widget_on_add_child)(widget_t* widget, widget_t* child);
typedef ret_t (*widget_on_remove_child)(widget_t* widget, widget_t* child);
typedef ret_t (*widget_on_layout_children_t)(widget_t* widget);
typedef ret_t (*widget_get_prop_t)(widget_t* widget, const char* name, value_t* v);
typedef ret_t (*widget_set_prop_t)(widget_t* widget, const char* name, const value_t* v);
@ -134,6 +136,8 @@ typedef struct _widget_vtable_t {
widget_on_pointer_up_t on_pointer_up;
widget_on_layout_children_t on_layout_children;
widget_invalidate_t invalidate;
widget_on_add_child add_child;
widget_on_remove_child remove_child;
widget_on_event_t on_event;
widget_grab_t grab;
widget_ungrab_t ungrab;