mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-09 03:51:08 +08:00
row support typecheck
This commit is contained in:
parent
4ee8a6ab57
commit
a2a8ce1f11
10
src/widgets/row.c
Executable file → Normal file
10
src/widgets/row.c
Executable file → Normal file
@ -22,15 +22,17 @@
|
||||
#include "tkc/mem.h"
|
||||
#include "widgets/row.h"
|
||||
|
||||
static const widget_vtable_t s_row_vtable = {
|
||||
.size = sizeof(row_t), .type = WIDGET_TYPE_ROW, .create = row_create};
|
||||
TK_DECL_VTABLE(row) = {.size = sizeof(row_t),
|
||||
.type = WIDGET_TYPE_ROW,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = row_create};
|
||||
|
||||
widget_t* row_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
return widget_create(parent, &s_row_vtable, x, y, w, h);
|
||||
return widget_create(parent, TK_REF_VTABLE(row), x, y, w, h);
|
||||
}
|
||||
|
||||
widget_t* row_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt == &s_row_vtable, NULL);
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, row), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -85,6 +85,11 @@ widget_t* row_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
|
||||
*/
|
||||
widget_t* row_cast(widget_t* widget);
|
||||
|
||||
#define ROW(widget) ((row_t*)(row_cast(WIDGET(widget))))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(row);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_ROW_H*/
|
||||
|
10
tests/row_test.cc
Normal file
10
tests/row_test.cc
Normal file
@ -0,0 +1,10 @@
|
||||
#include "widgets/row.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(Row, cast) {
|
||||
widget_t* w = row_create(NULL, 10, 20, 30, 40);
|
||||
|
||||
ASSERT_EQ(w, row_cast(w));
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user