mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-08 19:44:45 +08:00
canvas_widget/color_component/color_picker support typecheck
This commit is contained in:
parent
2bf98455a7
commit
84718e1e38
@ -22,16 +22,17 @@
|
||||
#include "tkc/mem.h"
|
||||
#include "canvas_widget/canvas_widget.h"
|
||||
|
||||
static const widget_vtable_t s_canvas_widget_vtable = {.size = sizeof(canvas_widget_t),
|
||||
.type = WIDGET_TYPE_CANVAS_WIDGET,
|
||||
.create = canvas_widget_create};
|
||||
TK_DECL_VTABLE(canvas_widget) = {.size = sizeof(canvas_widget_t),
|
||||
.type = WIDGET_TYPE_CANVAS_WIDGET,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = canvas_widget_create};
|
||||
|
||||
widget_t* canvas_widget_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
return widget_create(parent, &s_canvas_widget_vtable, x, y, w, h);
|
||||
return widget_create(parent, TK_REF_VTABLE(canvas_widget), x, y, w, h);
|
||||
}
|
||||
|
||||
widget_t* canvas_widget_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt == &s_canvas_widget_vtable, NULL);
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, canvas_widget), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -121,7 +121,10 @@ widget_t* canvas_widget_cast(widget_t* widget);
|
||||
|
||||
#define WIDGET_TYPE_CANVAS_WIDGET "canvas"
|
||||
|
||||
#define CANVAS_WIDGET(widget) ((canvas_widget_t*)(widget))
|
||||
#define CANVAS_WIDGET(widget) ((canvas_widget_t*)(canvas_widget_cast(WIDGET(widget))))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(canvas_widget);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
@ -135,13 +135,13 @@ static ret_t color_component_on_destroy(widget_t* widget) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static const widget_vtable_t s_color_component_vtable = {
|
||||
.size = sizeof(color_component_t),
|
||||
.type = WIDGET_TYPE_COLOR_COMPONENT,
|
||||
.create = color_component_create,
|
||||
.on_destroy = color_component_on_destroy,
|
||||
.on_event = color_component_on_event,
|
||||
.on_paint_self = color_component_on_paint_self};
|
||||
TK_DECL_VTABLE(color_component) = {.size = sizeof(color_component_t),
|
||||
.type = WIDGET_TYPE_COLOR_COMPONENT,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = color_component_create,
|
||||
.on_destroy = color_component_on_destroy,
|
||||
.on_event = color_component_on_event,
|
||||
.on_paint_self = color_component_on_paint_self};
|
||||
|
||||
static ret_t bitmap_destroy_data(bitmap_t* bitmap) {
|
||||
void* data = (void*)bitmap->data;
|
||||
@ -236,7 +236,7 @@ static ret_t color_component_update_h(widget_t* widget) {
|
||||
}
|
||||
|
||||
widget_t* color_component_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* widget = widget_create(parent, &s_color_component_vtable, x, y, w, h);
|
||||
widget_t* widget = widget_create(parent, TK_REF_VTABLE(color_component), x, y, w, h);
|
||||
color_component_t* color_component = COLOR_COMPONENT(widget);
|
||||
return_value_if_fail(color_component != NULL, NULL);
|
||||
|
||||
@ -309,3 +309,9 @@ float color_component_get_v(widget_t* widget) {
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
widget_t* color_component_cast(widget_t* widget) {
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, color_component), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -102,7 +102,21 @@ float color_component_get_s(widget_t* widget);
|
||||
*/
|
||||
float color_component_get_v(widget_t* widget);
|
||||
|
||||
#define COLOR_COMPONENT(widget) ((color_component_t*)(widget))
|
||||
/**
|
||||
* @method color_component_cast
|
||||
* 转换为color_component对象(供脚本语言使用)。
|
||||
*
|
||||
* @annotation ["cast", "scriptable"]
|
||||
* @param {widget_t*} widget color_component对象。
|
||||
*
|
||||
* @return {widget_t*} color_component对象。
|
||||
*/
|
||||
widget_t* color_component_cast(widget_t* widget);
|
||||
|
||||
#define COLOR_COMPONENT(widget) ((color_component_t*)(color_component_cast(WIDGET(widget))))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(color_component);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
15
src/ext_widgets/color_picker/color_picker.c
Executable file → Normal file
15
src/ext_widgets/color_picker/color_picker.c
Executable file → Normal file
@ -50,11 +50,12 @@ static ret_t color_picker_set_prop(widget_t* widget, const char* name, const val
|
||||
return RET_NOT_FOUND;
|
||||
}
|
||||
|
||||
static const widget_vtable_t s_color_picker_vtable = {.size = sizeof(color_picker_t),
|
||||
.type = WIDGET_TYPE_COLOR_PICKER,
|
||||
.set_prop = color_picker_set_prop,
|
||||
.get_prop = color_picker_get_prop,
|
||||
.create = color_picker_create};
|
||||
TK_DECL_VTABLE(color_picker) = {.size = sizeof(color_picker_t),
|
||||
.type = WIDGET_TYPE_COLOR_PICKER,
|
||||
.set_prop = color_picker_set_prop,
|
||||
.get_prop = color_picker_get_prop,
|
||||
.parent = TK_PARENT_VTABLE(widget),
|
||||
.create = color_picker_create};
|
||||
|
||||
static ret_t color_picker_update_child(void* ctx, const void* iter) {
|
||||
float h = 0;
|
||||
@ -317,7 +318,7 @@ static ret_t color_picker_on_window_will_open(void* ctx, event_t* e) {
|
||||
}
|
||||
|
||||
widget_t* color_picker_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* widget = widget_create(parent, &s_color_picker_vtable, x, y, w, h);
|
||||
widget_t* widget = widget_create(parent, TK_REF_VTABLE(color_picker), x, y, w, h);
|
||||
color_picker_t* color_picker = COLOR_PICKER(widget);
|
||||
widget_t* win = widget_get_window(parent);
|
||||
return_value_if_fail(color_picker != NULL, NULL);
|
||||
@ -356,7 +357,7 @@ ret_t color_picker_set_color(widget_t* widget, const char* color) {
|
||||
}
|
||||
|
||||
widget_t* color_picker_cast(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt == &s_color_picker_vtable, NULL);
|
||||
return_value_if_fail(WIDGET_IS_INSTANCE_OF(widget, color_picker), NULL);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
@ -124,7 +124,10 @@ ret_t color_picker_set_color(widget_t* widget, const char* color);
|
||||
*/
|
||||
widget_t* color_picker_cast(widget_t* widget);
|
||||
|
||||
#define COLOR_PICKER(widget) ((color_picker_t*)(widget))
|
||||
#define COLOR_PICKER(widget) ((color_picker_t*)(color_picker_cast(WIDGET(widget))))
|
||||
|
||||
/*public for subclass and runtime type check*/
|
||||
TK_EXTERN_VTABLE(color_picker);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
10
tests/canvas_widget_test.cc
Normal file
10
tests/canvas_widget_test.cc
Normal file
@ -0,0 +1,10 @@
|
||||
#include "canvas_widget/canvas_widget.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(CanvasWidget, cast) {
|
||||
widget_t* w = canvas_widget_create(NULL, 10, 20, 30, 40);
|
||||
|
||||
ASSERT_EQ(w, canvas_widget_cast(w));
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
10
tests/color_component_test.cc
Normal file
10
tests/color_component_test.cc
Normal file
@ -0,0 +1,10 @@
|
||||
#include "color_picker/color_component.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(ColorComponent, cast) {
|
||||
widget_t* w = color_component_create(NULL, 10, 20, 30, 40);
|
||||
|
||||
ASSERT_EQ(w, color_component_cast(w));
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
10
tests/color_picker_test.cc
Normal file
10
tests/color_picker_test.cc
Normal file
@ -0,0 +1,10 @@
|
||||
#include "color_picker/color_picker.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(ColorPicker, cast) {
|
||||
widget_t* w = color_picker_create(NULL, 10, 20, 30, 40);
|
||||
|
||||
ASSERT_EQ(w, color_picker_cast(w));
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user