mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-09 03:51:08 +08:00
dialog title support typecheck
This commit is contained in:
parent
e64853afa0
commit
9978289fbd
@ -30,13 +30,14 @@ static ret_t dialog_title_on_paint_self(widget_t* widget, canvas_t* c) {
|
||||
return widget_paint_helper(widget, c, NULL, NULL);
|
||||
}
|
||||
|
||||
static const widget_vtable_t s_dialog_title_vtable = {.size = sizeof(dialog_title_t),
|
||||
TK_DECL_VTABLE(dialog_title) = {.size = sizeof(dialog_title_t),
|
||||
.type = WIDGET_TYPE_DIALOG_TITLE,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = dialog_title_create,
|
||||
.on_paint_self = dialog_title_on_paint_self};
|
||||
|
||||
widget_t* dialog_title_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* widget = widget_create(parent, &s_dialog_title_vtable, x, y, w, h);
|
||||
widget_t* widget = widget_create(parent, TK_REF_VTABLE(dialog_title), x, y, w, h);
|
||||
return_value_if_fail(widget != NULL, NULL);
|
||||
|
||||
widget_set_name(widget, "title");
|
||||
@ -45,7 +46,7 @@ widget_t* dialog_title_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h)
|
||||
}
|
||||
|
||||
widget_t* dialog_title_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt == &s_dialog_title_vtable, NULL);
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, dialog_title), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -82,7 +82,10 @@ widget_t* dialog_title_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);
|
||||
*/
|
||||
widget_t* dialog_title_cast(widget_t* widget);
|
||||
|
||||
#define DIALOG_TITLE(widget) ((dialog_title_t*)(widget))
|
||||
#define DIALOG_TITLE(widget) ((dialog_title_t*)(dialog_title_cast(widget)))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(dialog_title);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
10
tests/dialog_title_test.cc
Normal file
10
tests/dialog_title_test.cc
Normal file
@ -0,0 +1,10 @@
|
||||
#include "widgets/dialog_title.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(DialgTitle, cast) {
|
||||
widget_t* w = dialog_title_create(NULL, 10, 20, 30, 40);
|
||||
|
||||
ASSERT_EQ(w, dialog_title_cast(w));
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user