mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
slide_menu support typecheck
This commit is contained in:
parent
b3688170ce
commit
e8bf8ca98f
@ -536,21 +536,21 @@ static ret_t slide_menu_on_event(widget_t* widget, event_t* e) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static const widget_vtable_t s_slide_menu_vtable = {
|
||||
.size = sizeof(slide_menu_t),
|
||||
.type = WIDGET_TYPE_SLIDE_MENU,
|
||||
.clone_properties = s_slide_menu_properties,
|
||||
.persistent_properties = s_slide_menu_properties,
|
||||
.create = slide_menu_create,
|
||||
.set_prop = slide_menu_set_prop,
|
||||
.get_prop = slide_menu_get_prop,
|
||||
.find_target = slide_menu_find_target,
|
||||
.on_paint_children = slide_menu_on_paint_children,
|
||||
.on_layout_children = slide_menu_layout_children,
|
||||
.on_event = slide_menu_on_event};
|
||||
TK_DECL_VTABLE(slide_menu) = {.size = sizeof(slide_menu_t),
|
||||
.type = WIDGET_TYPE_SLIDE_MENU,
|
||||
.clone_properties = s_slide_menu_properties,
|
||||
.persistent_properties = s_slide_menu_properties,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = slide_menu_create,
|
||||
.set_prop = slide_menu_set_prop,
|
||||
.get_prop = slide_menu_get_prop,
|
||||
.find_target = slide_menu_find_target,
|
||||
.on_paint_children = slide_menu_on_paint_children,
|
||||
.on_layout_children = slide_menu_layout_children,
|
||||
.on_event = slide_menu_on_event};
|
||||
|
||||
widget_t* slide_menu_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* widget = widget_create(parent, &s_slide_menu_vtable, x, y, w, h);
|
||||
widget_t* widget = widget_create(parent, TK_REF_VTABLE(slide_menu), x, y, w, h);
|
||||
slide_menu_t* slide_menu = SLIDE_MENU(widget);
|
||||
return_value_if_fail(slide_menu != NULL, NULL);
|
||||
|
||||
@ -590,7 +590,7 @@ ret_t slide_menu_set_align_v(widget_t* widget, align_v_t align_v) {
|
||||
}
|
||||
|
||||
widget_t* slide_menu_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt == &s_slide_menu_vtable, NULL);
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, slide_menu), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -196,7 +196,10 @@ ret_t slide_menu_set_min_scale(widget_t* widget, float_t min_scale);
|
||||
#define SLIDE_MENU_PROP_MIN_SCALE "min_scale"
|
||||
|
||||
#define WIDGET_TYPE_SLIDE_MENU "slide_menu"
|
||||
#define SLIDE_MENU(widget) ((slide_menu_t*)(widget))
|
||||
#define SLIDE_MENU(widget) ((slide_menu_t*)(slide_menu_cast(WIDGET(widget))))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(slide_menu);
|
||||
|
||||
/*public for test*/
|
||||
int32_t slide_menu_fix_index(widget_t* widget, int32_t index);
|
||||
|
@ -97,3 +97,11 @@ TEST(SlideMenu, props) {
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
||||
TEST(SlideMenu, cast) {
|
||||
widget_t* w = slide_menu_create(NULL, 0, 0, 400, 300);
|
||||
|
||||
ASSERT_EQ(w, slide_menu_cast(w));
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user